Programmering - Basic - Visual Basic - VBA - Functions
Conversion
Cbool
Ccur
Cdate
Cdbl
Cint
Clng
Csng
Cvar
 
  
Date, time
DateAdd
DateDiff
DateSerial
Now
Weekday
  
Dialog
InputBox
MsgBox
  
String
Format
DateAdd
Læg 15 dage til dags dato:
datJusteret = DateAdd("d", 15, Now)
 
DateDiff
DateDiff("d"|"w"|"m"|"y", date1, date2)
Dim antaldage As Integer
antaldage = DateDiff("d", Now, #12/24/99#) ' = 225
 
DateSerial
Dim juledato As Date
Dim juledagn As Double
juledato = DateSerial(Year(Now), 12, 24)  ' = 24-12-99
juledagn = DateSerial(Year(Now), 12, 24)  ' = 36518
 
Format
Format(Now, "d-mm-yyyy")
Format(123, "00000")
Format(1234.567, "#,##0.00")
' "7-11-2001"
' "00123"
' "1.234,57"
Bemærk ved formatering af tal, at VBA i koden benytter amerikanske indstillinger
Men output bliver formateret i overensstemmelse med maskinens internationale indstillinger (Kontrolpanel, International):
   US    DK
Tusindtals-separator "," "."
Decimal-separator "." ","
 
InputBox [>Excel: Application.InputBox()]
InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])
prompt   
title
default
xpos, ypos måles i twips (twentieths of a point)
1 tomme = 2,54 cm = 72 punkter = 1440 twips
1 cm = 567 twips
Hvis xpos og ypos udelades, centreres boxen.
helpfile, context
x = InputBox(Prompt:="Hvad er dit navn?", Title:="VBA kode")
Vis meddelelsen, titlen og standardværdien:
x = InputBox(Message, Title, Default)
Brug Hjælp-fil og kontekst. Knappen Hjælp tilføjes automatisk:
x = InputBox(Message, Title, , , , "Demo.hlp", 10)
Vis dialogboksen på position 100, 100:
x = InputBox(Message, Title, Default, 100, 100)
 
MsgBox
MsgBox(prompt[, buttons] [, title] [, helpfile, context])
prompt   
buttons
0    vbOKOnly, vbApplicationModal, vbDefaultButton1
1 vbOKCancel
2 vbAbortRetryIgnore
3 vbYesNoCancel
4 vbYesNo
5 vbRetryCancel
16 Critical.gif (1157 bytes) vbCritical
32 Question.gif (1149 bytes) vbQuestion
48 Exclamation.gif (1150 bytes) vbExclamation
64 Information.gif (1129 bytes) vbInformation
256 vbDefaultButton2
512 vbDefaultButton3
768 vbDefaultButton4
4096 vbSystemModal (Alle programmer venter på brugerrespons)
16384 vbMsgBoxHelpButton
65536 vbMsgBoxSetForeground (boxen placeres i forgrunden)
524288 vbMsgBoxRight (boxen højrejusteres)
title
helpfile, context
  
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ...' Brugeren har valgt Ja.
 
Returværdier:
1    vbOK
2 vbCancel
3 vbAbort
4 vbRetry
5 vbIgnore
6 vbYes
7 vbNo
 
Now
MsgBox "Klokken er nu " & Format(Now, "hh:mm:ss")
 
Weekday
1    vbSunday
2 vbMonday
3 vbTuesday
4 vbWednesday
5 vbThursday
6 vbFriday
7 vbSaturday
 
If Weekday(Now) = vbSunday Then DoWhatEver