Un livre de Wikibooks.
VBScript ou VBS (Visual Basic Script) est un langage parsé par les interpréteurs supportant le WSH de microsoft.
- Sur client : < script langage="VBScript" />
- Sur serveur : <% script langage="VBScript" %>
| + |
addition |
| - |
soustraction |
| * |
multiplication |
| ^ |
puissance |
| / |
division à float |
| \ |
division entière |
| mod |
modulo - reste de la division entière |
| < |
plus petit |
| <= |
plus petit ou égal |
| > |
plus grand |
| >= |
plus grand ou égal |
| <> |
différent |
| not |
non logique |
| and |
et logique |
| or |
ou logique |
| xor |
xor logique |
| eqv |
equivalence |
| imp |
implication |
| & |
concaténation |
Le vbs n'est pas, contrairement à beaucoup d'autres langages, sensible à la casse.
- src - source
- nm - nom
- var - variable
- expr - expression
- ins - instruction
- arg - argument
- cond - condition
- option explicit - force déclaration de toutes variables dans scr
- dim nm(src) - variable
- redim [preserve] var(src)
- const nm=expr - constante
- Procédure - execute instructions
- sub nm(arg1,arg2,...)
- [ins]
- [exit sub]
- [ins]
- end sub
- Fonction - retourne une valeur en sortie à nm
- function nm(arg1,arg2,...)
- [ins]
- [nm=expr]
- [exit function]
- [ins]
- [nm=expr]
- end function
- Get - comme fonction simple
- property get nm(arg1,arg2,...) as [type]
- ...
- [ins]
- [nm=expr]
- end property
- Let - comme fonction simple
- property let nm(arg1,arg2,...)
- ...
- [ins]
- end property
- Set - comme fonction simple
- property set nm(arg1,arg2,...)
- ...
- [ins]
- end property
- Classe - retourne initialize || terminate
- class ClassName
-
- [var]
- Private Sub Class_Initialize()
- [ins]
- End Sub
- Private Sub Class_Terminate()
- [ins]
- End Sub
- Public Function NomMethode([arg])
- [ins]
- End Function
- end Class
nota : const/sub/function/property sont déclarables en [public [default] | private]
ex 1
public function nm(args) - pour toute la src
ex 2
sub nm(args)
private const=expr - n'est déclarée et n'est valable que dans la procédure
end sub
[modifier] Instructions de contrôle
If cond Then [ins] Else [ins]
If cond1 Then
[ins]
Elseif cond2 Then
[ins]
Else
[ins]
Endif
Select Case expression
Case expr1
[ins]
Case expr2
[ins]
Case Else
[ins]
End Select
For cpt = début To fin [Step pas]
[ins]
[Exit For]
[ins]
Next [cpt]
For Each élément In groupe
[ins]
[Exit For]
[ins]
Next élément
Do [{While | Until} condition]
[ins]
[Exit Do]
[ins]
Loop
Do
[ins]
[Exit Do]
[ins]
Loop [{While | Until} condition]
While condition
[ins]
Wend
With obj
[ins]
End Width
Call nom [args]
On Error Resume Next
On Error Goto 0
Rem
- AFFECTATION DE REFERENCES
Set objvar=[obj expr | New classname | Nothing ]
Set object.eventname=GetRef(procname)
[modifier] conversion et mise en forme
- CBool(expr) - conversion en variant booleen
- CByte(expr) - conversion en variant byte
- CCur(expr) - conversion en variant currency
- CDate(expr) - conversion en variant date
- CDbl(expr) - conversion en variant double
- CInt(expr) - conversion en variant integer
- CLng(expr) - conversion en variant long
- CSng(expr) - conversion en variant single
- CStr(expr) - conversion en variant string
- FormatCurrency(expr,[NumDigitsAfterDecimal],[IncludeLeadingDigit],[UseParensForNegativeNumber],[GroupDigits]) - conversion formatée en variant currency
- FormatDateTime(date,[NamedFormat]) - conversion formatée en variant date
- FormatNumber(expr,[NumDigitsAfterDecimal],[IncludeLeadingDigit],[UseParensForNegativeNumber],[GroupDigits]) - conversion formatée en variant nombre
- FormatPercent(expr,[NumDigitsAfterDecimal],[IncludeLeadingDigit],[UseParensForNegativeNumber],[GroupDigits]) - conversion formatée en variant percent
- Hex(nbr) - conversion en variant hexadecimal
- IsArray(expr) - renvoit booleen si tableau
- IsDate(expr) - renvoit booleen si date
- IsEmpty(expr) - renvoit booleen si vide
- IsNull(expr) - renvoit booleen si null
- IsNumeric(expr) - renvoit booleen si nbr
- IsObject(identifier) - renvoit booleen si obj automation
- Oct(nbr) - conversion en string octal
- Abs(nbr) - renvoie valeur absolue
- Atn(nbr) - renvoie arc tangent
- Cos(nbr) - renvoie cosinus
- Exp(nbr) - renvoie la puissance
- Int(nbr) - renvoie partie entière
- Fix(nbr) - renvoie partie entière
- Log(nbr) - renvoie log népérien
- Sqr(nbr) - renvoie racine carrée
- Tan(nbr) - renvoie tangente
- Sgn(nbr) - renvoie signe
- Randomize(nbr) - init nbr aleatoire !!les nombres ne sont pas aleatoire en vbs!!
- Rnd(nbr) - renvoie nbr aleatoire
- Round(expr,[numdecimalplaces]) - renvoie l'arrondi
- Sin(nbr) - renvoie sinus
[modifier] de traitement de chaînes
- Asc(string) - renvoie code ansi du 1er char
- Chr(charcode) - renvoie le char du code ansi
- inStr(start,string,string2,[compare]) - renvoie 1ère position d'un string dans un autre
- InStrRev(delimiter) - renvoie position d'un string dans un autre en partant de fin
- Join(string) - renvoie string joins partant d'un tableau
- LCase(string) - conversion en minuscule
- Left(string,length) - renvoie sous string partant de gauche
- Len(string) - renvoie nbr de char dans string
- LTrim(string) - renvoie string sans espace à gauche
- Mid(string,start,[length]) - renvoie sous string partant de milieu
- Replace(expr,find,replacement,[start],[count],[compare]) - remplace string dans string
- Right(string,length) - renvoie sous string partant de droite
- RTrim(string) - renvoie string sans espace à droite
- StrComp(string1,string2,[compare]) - renvoie valeur de comparaison de string
- String([nbr],[char]) - renvoie string de char repete
- StrReverse(string) - renvoie string inverse
- Space(nbr) - renvoie string de space
- Trim(string) - renvoie string sans espace ni gauche ni droite
- UCase(string) - renvoie string en majuscule
[modifier] de date et d'heure
- Date() - renvoie date sys
- DateAdd(interval,nbr,Date) - renvoie date + interval
- DateDiff(interval,date1,date2,[firstdayofweek],[firstdayofyear]) - renvoie interval
- DatePart(interval,Date,[firstdayofweek],[firstdayofyear]) - renvoie partie spécifiée
- DateSerial(Year,Month,Date) - renvoie variant de type date
- DateValue(Date) - renvoie variant de type date
- Day(Date) - renvoie jour du mois
- Hour(Time) - renvoie heure
- Minute(Time) - renvoie minute'
- Month(Date) - renvoie mois en chiffre
- MonthName(Month,[abbreviate]) - renvoie mois en lettre
- Now() - renvoie date et heure sys
- Second(Time) - renvoie seconde
- Time() - renvoie heure sys
- Timer() - renvoie nbre de sec depuis 00:00
- TimeSerial(Hour,Minute,Second) - renvoit variant de type date
- TimeValue(Time) - renvoit variant de type date
- Weekday(Date,[fistdayofweek]) - renvoie jour semaine en chiffre
- WeekdayName(Weekday,abbreviate,firstdayofweek) - renvoie jour semaine en lettre
- Year(Date) - renvoie annee de date
[modifier] liées aux tableaux
- Array(arg) - renvoie variant contenant tableau
- Erase tableau - libère tableau
- Filter(InputStrings,Value,[Include],[compare]) - renvoie tableau commençant par 0 contenant sous ensemble de string
- LBound(arrayname,[dimension]) - renvoie plus petit indice tableau
- Split(expr,[delimiter],[count],[compare]) - renvoie tableau commençant par 0 comprenant # de string
- UBound(arrayname,[dimension]) - renvoie plus grand indice tableau
[modifier] autres fonctions
- CreateObject(class) - renvoie ref à objet automation
- Eval(string) - renvoie resultat
- Execute ins - execute ins
- ExecuteGlobal ins - execute ins globale
- GetLocale() - renvoie valeur ID parametre regionnaux sys
- GetObject([pathname],[class]) - renvoie ref à objet automation de fichier
- GetRef(string) - renvoie ref à procedure
- InputBox(prompt,[title],[default,[xpos],[ypos],[helpfile],[context]) - prompt
- LoadPicture([stringexpr) - renvoie img
- MsgBox(prompt,[buttons],[title],[helpfile],[context]) - msgbox
- RGB(red,green,blue) - renvoie int rgb
- ScriptEngine() - renvoie string de script utilisé
- ScriptEngineBuildVersion() - renvoie N° version
- ScriptEngineMajorVersion() - renvoie N° version principale
- ScriptEngineMinorVersion() - renvoie N° version secondaire
- SetLocate(Icid) - def param regionnaux globaux
- TypeName(varname) - renvoit string d'info sur variant
- VarType(varname) - renvoit valeur sous type de var
- Err - infos relatives aux erreurs d'exec
-
- Description
- Helpcontext
- Helpfile
- Number
- Source
-
- Clear()
- Raise(nbr,src,desc,hlpf,hlpcontext)
- RegExp - gestion des regular expr
-
- Global
- IgnoreCase
- Pattern
-
- Execute(string)
- Replace(string1,string2)
- Test(string)
- Match - accès aux proprietes correspondant de regular expr
-
- FirstIndex
- Length
- Value
- Matches - collection de match
-
- Count
- Item(key)
- SubMatches - collection de sous-match
-
- Count
- Item(key)
[modifier] Chaînes de caractères
| CONSTANTE |
VALEUR |
DESCRIPTION |
| vbCr |
chr(13) |
Retour chariot |
| vbCrlf |
chr(13)+chr(10) |
Retour chariot et saut de ligne |
| vbFormFeed |
chr(12) |
Saut de page |
| vblf |
chr(10) |
Saut de ligne |
| vbNewline |
chr(13)+chr(10) |
Nouvelle ligne |
| vbNullChar |
chr(0) |
0 |
| vbNullString |
chaîne ayant val. 0 |
chaine nulle |
| vbTab |
chr(9) |
tab horizontale |
| vbVerticalTab |
chr(11) |
tab verticale |
| vbBlack |
&h00 |
Noir |
| vbRed |
&hFF |
Rouge |
| vbGreen |
&hFF00 |
Vert |
| vbYellow |
&hFFFF |
Jaune |
| vbBlue |
&hFF0000 |
Bleu |
| vbMagenta |
&hFF00FF |
Magenta |
| vbCyan |
&hFFFF00 |
Cyan |
| vbWhite |
&hFFFFFF |
Blanc |
| vbBinaryCompare |
0 |
Comparaison binaire |
| vbTextCompare |
1 |
Comparaison texte |
| vbSunday |
1 |
Dimanche |
| vbMonday |
2 |
Lundi |
| vbTuesday |
3 |
Mardi |
| vbWednesday |
4 |
Mercredi |
| vbThursday |
5 |
Jeudi |
| vbFriday |
6 |
Vendredi |
| vbSaturday |
7 |
Samedi |
| vbUseSystem |
0 |
Format de date des param regionaux |
| vbUseSystemDayOfWeek |
0 |
Jour semaine des param regionaux |
| vbFirstJan1 |
1 |
Utilise la semaine du 01 Janvier |
| vbFisrtFourDays |
2 |
Première semaine avec 4 jours dans nouvelle annee |
| vbFirstFullWeek |
3 |
Utilise la premiere semaine complete de l'annee |
[modifier] Format de date
| vbGeneralDate |
0 |
Date et heure |
| vbLongDate |
1 |
Date complète |
| vbShortDate |
2 |
Date abrégée |
| vbLongTime |
3 |
Heure complète |
| vbShortTime |
4 |
Heure abrégée |
| vbOkOnly |
0 |
ok |
| vbOkCancel |
1 |
ok/cancel |
| vbAbortRetryIgnore |
2 |
abort/retry/ignore |
| vbYesNoCancel |
3 |
yes/no/cancel |
| vbYesNo |
4 |
yes/no |
| vbRetryCancel |
5 |
retry/cancel |
| vbCritical |
16 |
message critique |
| vbQuestion |
32 |
demande avertissement |
| vbExclamation |
48 |
exclamation |
| vbInformation |
64 |
information |
| vbDefaultButton1 |
0 |
bouton1 |
| vbDefaultButton2 |
256 |
bouton2 |
| vbDefaultButton3 |
542 |
bouton3 |
| vbDefaultButton4 |
768 |
bouton4 |
| vbApplicationModal |
0 |
boite modale pour l'app |
| vbSystemModal |
4096 |
boite modale pour le sys |
| vbEmpty |
0 |
non init (defaut) |
| vbNull |
1 |
pas de data |
| vbInteger |
2 |
sous-type integer |
| vbLong |
3 |
sous-type long |
| vbSingle |
4 |
sous-type single |
| vbDouble |
5 |
sous-type double |
| vbCurrency |
6 |
sous-type currency |
| vbDate |
7 |
sous-type date |
| vbString |
8 |
sous-type string |
| vbObject |
9 |
objet |
| vbError |
10 |
sous-type error |
| vbBoolean |
11 |
sous-type booleen |
| vbVariant |
12 |
variant pour tableau variant |
| vbDataObject |
13 |
objet d'acces aux donnees |
| vbDecimal |
14 |
sous-type decimal |
| vbByte |
17 |
sous-type byte |
| vbArray |
8192 |
tableau |
[modifier] Autre constantes
| vbObjectError |
-2147221504 |
num d'erreur doivent etre superieur |
| vbUseDefault |
-2 |
utiliser valeur par defaut des params |
| vbTrue |
-1 |
true |
| vbFalse |
0 |
false |
[modifier] Codes d'erreur
Il y a deux types d'erreurs :
| NUMERO |
DESCRIPTION |
| 5 |
appel de procedure incorrect |
| 6 |
depassement de capacite |
| 7 |
memoire insuffisante |
| 9 |
indice hors plage |
| 10 |
tableau fixe ou verrouille |
| 11 |
division par zero |
| 13 |
type incompatible |
| 14 |
espace de chaine insuffisant |
| 17 |
operation impossible |
| 28 |
espace pile insuffisant |
| 35 |
sub non definie |
| 48 |
erreur chargement de dll |
| 51 |
erreur interne |
| 91 |
var d'objet non definie |
| 92 |
boucle non init |
| 94 |
utilisation incorrecte de null |
| 424 |
objet requis |
| 429 |
activex ne peut pas creer l'objet |
| 430 |
classe ne gere pas automation |
| 432 |
fichier ou classe introuvable |
| 438 |
methode ou propriete non gere |
| 445 |
objet ne gere pas action |
| 447 |
objet ne gere pas les param |
| 448 |
arg introuvable |
| 449 |
arg obligatoire |
| 450 |
nbre arg ou propriete incorrecte |
| 451 |
objet n'est pas une collection |
| 458 |
type automation non gere |
| 462 |
machine distante indisponnible |
| 481 |
image incorrecte |
| 500 |
variable indefinie |
| 502 |
objet non securise pour script |
| 503 |
objet non securise pour init |
| 504 |
objet non securise pour creation |
| 505 |
reference incorrecte ou non qualifiee |
| 506 |
classe non definie |
| 507 |
exception |
| 5008 |
affectation illegale |
| 5017 |
Erreur syntaxique dans ER |
| 5018 |
quantifiant innatendu |
| 5019 |
']' attendu dans ER |
| 5020 |
')' attentu dans ER |
| 5021 |
jeu de char incorrect |
| NUMERO |
DESCRIPTION |
| 1052 |
trop de methodes et proprietes |
| 1044 |
parentheses interdites |
| 1053 |
classe sans arg |
| 1058 |
'default' que dans get |
| 1057 |
'default' + 'public' |
| 1005 |
'(' attendu |
| 1006 |
')' attendu |
| 1011 |
'=' attendu |
| 1021 |
'case' attendu |
| 1047 |
'class' attendu |
| 1025 |
fin ins attendu |
| 1014 |
'end' attendu |
| 1023 |
expr attendu |
| 1015 |
'function' attendu |
| 1010 |
identificateur attendu |
| 1012 |
'lf' attendu |
| 1046 |
'ln' attendu |
| 1026 |
constante (int) attendu |
| 1049 |
let, get, set attendu |
| 1045 |
constante (string) attendu |
| 1019 |
'loop' attendu |
| 1020 |
'next' attendu |
| 1050 |
'property' attendu |
| 1022 |
'select' attendu |
| 1024 |
ins attendu |
| 1016 |
'sub' attendu |
| 1017 |
'then' attendu |
| 1013 |
'to' attendu |
| 1018 |
'wend' attendu |
| 1027 |
'while' 'until' attendu |
| 1028 |
'while' 'until' ou fin ins attendu |
| 1029 |
'with' attendu |
| 1030 |
identificateur trop long |
| 1014 |
char incorrect |
| 1039 |
'exit' incorrect |
| 1040 |
variable de ctrl de 'for' incorrecte |
| 1013 |
nbre incorrect |
| 1037 |
utilisation incorrecte de 'me' |
| 1038 |
'loop' sans 'do' |
| 1048 |
doit etre defini dans classe |
| 1042 |
doit premiere ins de ligne |
| 1041 |
nom redefini |
| 1051 |
nombre arg inegal |
| 1001 |
memoire insuffisante |
| 1054 |
arg manquant dans let ou set |
| 1002 |
erreur sythaxe |
| 1055 |
next attendu |
| 1015 |
constante de chaine non terminee |
[modifier] LIENS INTERNES
Initiation au VBScript par l'exemple
[modifier] LIENS EXTERNES
Cet article fait partie du livre Programmation