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.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Profil Anne98
Femeie
25 ani
Buzau
cauta Barbat
25 - 50 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [VBS, HTA] Extract Month End Date Given Month Number & Year Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
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)

Modificat de TRaP (acum 4 ani)


pus acum 4 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
Moved post #2 to this new dedicated topic:

_______________________________________


pus acum 2 ani
   
Pagini: 1  

Mergi la