Ces deux fonctions permettrent de recuperer "proprement" le nombre de parametres passes a un shell et de les adresser par leur numero.
Source / Exemple :
Public Function LitParametre(Compte As Integer) As String
Dim i As Long
Dim j As Integer
Dim c As String
Dim bInside As Boolean
Dim bQuoted As Boolean
j = 1
bInside = False
bQuoted = False
LitParametre = ""
For i = 1 To Len(Command)
c = Mid$(Command, i, 1)
If bInside And bQuoted Then
If c = """" Then
j = j + 1
bInside = False
bQuoted = False
End If
ElseIf bInside And Not bQuoted Then
If c = " " Then
j = j + 1
bInside = False
bQuoted = False
End If
Else
If c = """" Then
If j > Compte Then Exit Function
bInside = True
bQuoted = True
ElseIf c <> " " Then
If j > Compte Then Exit Function
bInside = True
bQuoted = False
End If
End If
If bInside And j = Compte And c <> """" Then LitParametre = LitParametre & c
Next i
End Function
'------------------------------------------------
Public Function NbParametres() As Integer
Dim i As Long
Dim c As String
Dim bInside As Boolean
Dim bQuoted As Boolean
NbParametres = 0
bInside = False
bQuoted = False
For i = 1 To Len(Command)
c = Mid$(Command, i, 1)
If bInside And bQuoted Then
If c = """" Then
NbParametres = NbParametres + 1
bInside = False
bQuoted = False
End If
ElseIf bInside And Not bQuoted Then
If c = " " Then
NbParametres = NbParametres + 1
bInside = False
bQuoted = False
End If
Else
If c = """" Then
bInside = True
bQuoted = True
ElseIf c <> " " Then
bInside = True
bQuoted = False
End If
End If
Next i
If bInside Then NbParametres = NbParametres + 1
End Function
Conclusion :
La fonction NbParametres renvoie un entier représentant le nombre de paramètres passés en ligne de commande..
La fonction LitParametre permet de lire l'un de ces parametres.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.