Archives de catégorie : Scripting

vbscript – FileSystemObject.CreateTextFile

**METHOD:** `fso.CreateTextFile(path[, overwrite[, unicode]])`

**Description**
Crée un fichier texte et retourne un `TextStream` pour écrire.

**Syntax**
`fso.CreateTextFile(path[, overwrite[, unicode]])`

**Paramètres**
– `path` : Chemin du fichier.
– `overwrite` : `True` pour écraser si existe.

**Retour**
Un objet `TextStream`.

**Exemples**
« `vb
Dim fso, ts
Set fso = CreateObject(« Scripting.FileSystemObject »)
Set ts = fso.CreateTextFile(« C:tempdemo.txt », True)
ts.WriteLine « Hello from VBScript »
ts.Close
« `

**Voir aussi**
`TextStream.WriteLine`, `FileSystemObject.OpenTextFile`

vbscript – DateAdd

**FUNCTION:** `DateAdd(interval, number, date)`

**Description**
Ajoute un intervalle (jours, mois, années, etc.) à une date.

**Syntax**
`DateAdd(interval, number, date)`

**Paramètres**
– `interval` : Code d’intervalle (ex: « d » jours, « m » mois, « yyyy » années).
– `number` : Nombre d’unités à ajouter (peut être négatif).
– `date` : Date de base.

**Retour**
Nouvelle date.

**Exemples**
« `vb
WScript.Echo DateAdd(« d », 7, Date)
WScript.Echo DateAdd(« m », 1, CDate(« 2026-02-09 »))
« `

**Output :** `date+7j ; date+1mois`

**Voir aussi**
`DateDiff`, `DatePart`, `DateSerial`

vbscript – TextStream.ReadLine

**METHOD:** `ts.ReadLine`

**Description**
Lit une ligne (jusqu’au retour à la ligne) dans un `TextStream`.

**Syntax**
`ts.ReadLine`

**Paramètres**
– *(aucun)*

**Retour**
Chaîne (la ligne).

**Exemples**
« `vb
Dim fso, ts
Set fso = CreateObject(« Scripting.FileSystemObject »)
Set ts = fso.OpenTextFile(« C:tempdemo.txt », 1)
Do While Not ts.AtEndOfStream
WScript.Echo ts.ReadLine
Loop
ts.Close
« `

**Voir aussi**
`TextStream.AtEndOfStream`, `FileSystemObject.OpenTextFile`

vbscript – Trim

**FUNCTION:** `Trim(string)`

**Description**
Supprime les espaces au début et à la fin d’une chaîne.

**Syntax**
`Trim(string)`

**Paramètres**
– `string` : Chaîne à nettoyer.

**Retour**
Chaîne nettoyée.

**Exemples**
« `vb
WScript.Echo « [ » & Trim( » hello « ) & « ] »
« `

**Output :** `[hello]`

**Voir aussi**
`LTrim`, `RTrim`

vbscript – LCase / UCase

**FUNCTION:** `LCase(string) / UCase(string)`

**Description**
Convertit une chaîne en minuscules (`LCase`) ou majuscules (`UCase`).

**Syntax**
`LCase(string) / UCase(string)`

**Paramètres**
– `string` : Chaîne source.

**Retour**
Chaîne convertie.

**Exemples**
« `vb
WScript.Echo LCase(« ABC »)
WScript.Echo UCase(« abc »)
« `

**Output :** `abc ; ABC`

**Voir aussi**
`StrComp`, `Replace`

vbscript – WScript.Arguments

**PROPERTY:** `WScript.Arguments`

**Description**
Accès aux arguments de ligne de commande.

**Syntax**
`WScript.Arguments`

**Paramètres**
– *(aucun)*

**Retour**
Objet `WScript.Arguments`.

**Exemples**
« `vb
Dim i
For i = 0 To WScript.Arguments.Count – 1
WScript.Echo i & « :  » & WScript.Arguments(i)
Next
« `

**Voir aussi**
`WScript.Arguments.Count`, `WScript.Arguments.Item`

vbscript – IsNumeric

**FUNCTION:** `IsNumeric(expression)`

**Description**
Indique si une expression est convertible en nombre.

**Syntax**
`IsNumeric(expression)`

**Paramètres**
– `expression` : Valeur/chaîne à tester.

**Retour**
`True` ou `False`.

**Exemples**
« `vb
WScript.Echo IsNumeric(« 12.3 »)
WScript.Echo IsNumeric(« 12a »)
« `

**Output :** `True ; False`

**Voir aussi**
`CDbl`, `CInt`, `CLng`

vbscript – WshShell.Run

**METHOD:** `shell.Run(command[, windowStyle[, waitOnReturn]])`

**Description**
Exécute une commande/programme.

**Syntax**
`shell.Run(command[, windowStyle[, waitOnReturn]])`

**Paramètres**
– `command` : Commande (ex: « notepad.exe » ou « cmd /c dir »).
– `waitOnReturn` : `True` pour attendre la fin.

**Retour**
Code retour si `waitOnReturn=True`, sinon 0 (selon contexte).

**Exemples**
« `vb
Dim shell
Set shell = CreateObject(« WScript.Shell »)
shell.Run « notepad.exe », 1, False
« `

**Voir aussi**
`WshShell.Exec`, `WshShell.Popup`

vbscript – FormatNumber

**FUNCTION:** `FormatNumber(expression[, numdigitsafterdecimal[, includeleadingdigit[, useparensfornegativenumbers[, groupdigits]]]])`

**Description**
Formate une valeur numérique en chaîne (décimales, séparateurs, etc.).

**Syntax**
`FormatNumber(expression[, numdigitsafterdecimal[, includeleadingdigit[, useparensfornegativenumbers[, groupdigits]]]])`

**Paramètres**
– `expression` : Valeur numérique.

**Retour**
Chaîne formatée.

**Exemples**
« `vb
WScript.Echo FormatNumber(12345.678, 2, -1, 0, -1)
« `

**Output :** `12’345.68 (selon locale)`

**Voir aussi**
`FormatCurrency`, `FormatPercent`, `CStr`