Filehost.ro - gazduire fisiere
Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Nou pe simpatie:
inna_90
Femeie
23 ani
Vrancea
cauta Barbat
30 - 48 ani
Mrrrr's Forum (VIEW ONLY)ReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides /

[VBS, HTA] Extract Month End Date Given Month Number & Year

Pagini: 1 Moderat de TRaP, TonyTzu
#1
TRaP
Moderator
Postari: 960
Example below. Note that when declaring variables in VBS you don't need to Dim them as "something" like String, Long etc. because VBS has only one database.

In the example below, I will be inserting month and year in order to access some SAP transactions via scripting. The code is very similar to a VBA code since it's still Visual Basic.

The code below takes into account leap years like 2020 is.



Dim strMonth
Dim strYear
Dim LeapYear

Dim strDateStart
Dim strDateEnd

strMonth = InputBox("Please insert desired month number (eg. 09):")

If strMonth < 1 or strMonth > 12 Then
  MsgBox "You didn't enter a month"
  Set session = Nothing
  WScript.Quit
End If

strYear = InputBox("Please insert desired year (eg. 2019):")

If strYear = 0 Then
  MsgBox "You didn't enter a year"
  Set session = Nothing
  WScript.Quit
End If

strDateStart = "01." & strMonth & "." & strYear

Select Case strMonth

  Case 01
    strDateEnd = "31." & strMonth & "." & strYear

  Case 03
    strDateEnd = "31." & strMonth & "." & strYear

  Case 04
    strDateEnd = "30." & strMonth & "." & strYear

  Case 05
    strDateEnd = "31." & strMonth & "." & strYear

  Case 06
    strDateEnd = "30." & strMonth & "." & strYear

  Case 07
    strDateEnd = "31." & strMonth & "." & strYear

  Case 08
    strDateEnd = "31." & strMonth & "." & strYear

  Case 09
    strDateEnd = "30." & strMonth & "." & strYear

  Case 10
    strDateEnd = "31." & strMonth & "." & strYear

  Case 11
    strDateEnd = "30." & strMonth & "." & strYear

  Case 12
    strDateEnd = "31." & strMonth & "." & strYear

  Case 02
    LeapYear = 0
    If strYear Mod 4 = 0 then LeapYear = 1
    If strYear Mod 100 = 0 then LeapYear = 0
    If strYear Mod 400 = 0 then LeapYear = 1

    If LeapYear = 0 Then
    strDateEnd = "28." & strMonth & "." & strYear

    ElseIf LeapYear = 1 Then
    strDateEnd = "29." & strMonth & "." & strYear
   
    End if
   
  Case Else
    Set session = Nothing
    WScript.Quit
   
End Select

' some SAP session fields lines are here and when the desired date field comes into play, instead of the raw start date like "01.01.2020" you enter strDateStart and instead of the end date you enter strDateEnd:
session.findById("wnd[0]/usr/ctxtSO_BUDAT-LOW").text = strDateStart
session.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").text = strDateEnd


Sources:
https://docs.microsoft.com/en-us/previo ... echnet.10)
https://docs.microsoft.com/en-us/previo ... echnet.10)


 
   
#2
Mrrrr
AdMiN
Postari: 2388
Moved post #2 to this new dedicated topic:
http://mrrrr.3xforum.ro/post/2270/HTA_A ... VBS_HTML_/


_______________________________________


 
   
Pagini: 1  
Mergi la