Programmering - Script - VBScript - Funktioner
downh.gif (840 bytes) cInt
cSng
cStr
cDbl
downh.gif (840 bytes) InStr
InStrRev
Left
Lcase
Mid
Right
Ucase
downh.gif (840 bytes) Cdate
FormatDateTime
eksempel:
Now 2000-12-30 09:52:12
Date 2000-12-30
Year 2000
Month (1..12) 12
Day (1..31) 30
Weekday (1..7)  3
Time 09:52:12
downh.gif (840 bytes) InputBox
MsgBox
downh.gif (840 bytes) CreateObject
CreateTextFile
OpenTextFile
Cdate()
jul = cdate("24-12-" & year(date))
 
CreateObject()gox.gif (837 bytes)WSH: Wscript.CreateObject, ASP: Server.CreateObject
Set ExcelSheet = CreateObject("Excel.Sheet")
set fso = CreateObject("scripting.filesystemobject")
 
Date()
s = Date 's = "2000-12-30"
msgbox date :
>Now, Year, Month, Day, Weekday, Time
NB: i JavaScript er alle tid- og dato-funktioner metoder i objektet Date
 
Day()
returnerer måneds-dagen (1..31)
s = Day(Date) 's = "27"
msgbox day(date) :
>Date
 
FileExists()
if fso.FileExists("c:\test.txt") then
  ---
 
FormatDateTime()
s = FormatDateTime(Now, vbGeneralDate) 's = "2000-12-30 09:58:12"
s = FormatDateTime(Now, vbLongDate)    's = "30. december 2000"
s = FormatDateTime(Now, vbShortDate)   's = "2000-12-30"
s = FormatDateTime(Now, vbLongTime)    's = "09:58:12"
s = FormatDateTime(Now, vbShortTime)   's = "09:58"
  
vbGeneralDate   0
vbLongDate 1
vbShortdate 2
vbLongTime 3
vbShortTime 4
 
InputBox()
Input = InputBox("Hvem er du?")
MsgBox "Hej " & Input
 
InStr()
txt = "c:\script\test.vbs"
s = InStr(txt, "\") 's = 3
 
InStrRev()
txt = "c:\script\test.vbs"
s = InStrRev(txt, "\") 's = 10
Denne funktion er velegnet til at finde stien ud fra en fils fulde navn:
function Path(FullName)
  Path = Left(FullName, InstrRev(FullName, "\") - 1)
end function
  
s = Path("c:\script\test.vbs") 's = "c:\script"
 
Lcase()
s = Lcase("C:\Script\TEST.VBS") 's = "c:\script\test.vbs"
 
Left()
txt = "Visual Basic Script"
s = Left(txt, 12) 's = "Visual Basic"
 
Mid()
txt = "Visual Basic Script"
s = Mid(txt, 8, 5) 's = "Basic"
t = Mid(txt, 8)    't = "Basic Script"
 
Month()
returnerer måneden (1..12)
s = Month(Date) 's = "7"
msgbox month(now) :
 
MsgBox() (>webdesign: window.alert)
MsgBox(prompt[, buttons][, title][, helpfile, context])
prompt   String expression displayed as the message in the dialog box.
Maximum length: approximately 1024 characters.
Line breaks: Chr(13), Chr(10) or Chr(13) & Chr(10).
buttons
Constant Value Description
vbOKOnly    0 Display OK button only.
vbOKCancel    1 Display OK and Cancel buttons.
vbAbortRetryIgnore    2 Display Abort, Retry, and Ignore buttons.
vbYesNoCancel    3 Display Yes, No, and Cancel buttons.
vbYesNo    4 Display Yes and No buttons.
vbRetryCancel    5 Display Retry and Cancel buttons.
vbCritical 16 Display Critical Message icon.
vbQuestion 32 Display Warning Query icon.
vbExclamation 48 Display Warning Message icon.
vbInformation 64 Display Information Message icon.
vbDefaultButton1    0 First button is default.
vbDefaultButton2  256 Second button is default.
vbDefaultButton3  512 Third button is default.
vbDefaultButton4  768 Fourth button is default.
vbApplicationModal    0 Application modal; the user must respond to the message box before continuing work in the current application.
vbSystemModal 4096 System modal; all applications are suspended until the user responds to the message box.

The first group of values (0–5) describes the number and type of buttons displayed in the dialog box.
The second group (16, 32, 48, 64) describes the icon style.
The third group (0, 256, 512, 768) determines which button is the default.
The fourth group (0, 4096) determines the modality of the message box.
When adding numbers to create a final value for the argument buttons, use only one number from each group.

title String expression displayed in the title bar of the dialog box.
If you omit title, the application name is used.
helpfile String expression that identifies the Help file to use to provide context-sensitive Help for the dialog box. If helpfile is provided, context must also be provided.
context Numeric expression that identifies the Help context number assigned by the Help author to the appropriate Help topic. If context is provided, helpfile must also be provided.
 
The MsgBox function has the following return values:
Constant Value Button
vbOK 1 OK
vbCancel 2 Cancel / Annuller
vbAbort 3 Abort / Afbryd
vbRetry 4 Retry / Forsøg igen
vbIgnore 5 Ignore / Ignorer
vbYes 6 Yes / Ja
vbNo 7 No / Nej
 
MsgBox kan bruges både som funktion og som subrutine:
x = msgbox("klik Ja, Nej eller Annuller",vbYesNoCancel)
msgbox "returneret værdi: " & x
 
Now()
s = Now 's = "2000-12-30 09:52:12"
msgbox now :
 
Right()
txt = "Visual Basic Script"
s = Right(txt, 6) 's = "Script"
 
Time()
s = Time 's = "09:52:12"
msgbox time :
 
Weekday()
returnerer ugedagen (1..7) - NB: søndag = 1 .. lørdag = 7
s = Weekday(Date) 's = "3"
msgbox weekday(now) :
 
Year()
s = Year(Date) 's = "2000"
msgbox year(date) :