Soyez le premier à donner votre avis sur cette source.
Vue 5 757 fois - Téléchargée 369 fois
Attribute VB_Name = "MainModule" Option Explicit ' Le projet doit démarrer sur SubMain (Options du projet) Private Sub Main() Dim SaveTitle As String ' Vérifie qu'une autre instance du programme n'est pas déjà en cours... If App.PrevInstance Then SaveTitle = App.Title AppActivate SaveTitle End End If ' Récupère les paramètres de la ligne de commande Dim strArgArray() As String Dim intNbArgs As Integer If GetCommandLine(strArgArray, intNbArgs) Then ' Ici on dispose d'un tableau strArgArray contenant intNbArgs arguments ' On peut afficher la feuille par Load Form1 puis Form1.Show End If End Sub Private Function GetCommandLine( _ ByRef ArgArray() As String, _ ByRef NbArgs As Integer, _ Optional MaxArgs) As Boolean Dim Char As String * 1 Dim CommandLine As String Dim CommandLineLength, CharNumber As Integer Dim InArg, InLongArg As Boolean ' Contrôle si un nombre max d'arguments est précisé, sinon max=3 If IsMissing(MaxArgs) Then MaxArgs = 3 ' Récupère la ligne de commande CommandLine = Command() CommandLineLength = Len(CommandLine) ' Trouve les arguments un par un NbArgs = 0 For CharNumber = 1 To CommandLineLength Char = Mid(CommandLine, CharNumber, 1) ' Vérifie s'il y a des guillemets dans les arguments (pour les noms de fichier long, par exemple If Char = """" Then InLongArg = True If InLongArg Then If Char = """" Then If Not InArg Then If NbArgs = MaxArgs Then Exit For NbArgs = NbArgs + 1 ReDim Preserve ArgArray(1 To NbArgs) As String InArg = True Else InArg = False InLongArg = False End If Else If InArg Then ArgArray(NbArgs) = ArgArray(NbArgs) & Char End If End If Else If Char <> " " And Char <> vbTab Then If Not InArg Then If NbArgs = MaxArgs Then Exit For NbArgs = NbArgs + 1 ReDim Preserve ArgArray(1 To NbArgs) As String InArg = True End If ArgArray(NbArgs) = ArgArray(NbArgs) & Char Else InArg = False End If End If Next CharNumber GetCommandLine = (NbArgs > 0) End Function
29 oct. 2003 à 10:05
22 oct. 2003 à 22:41
Ceci dit, j'ai qd même une remarque. Je pense qu'il serait mieux pour traiter un fichier texte d'utiliser l'objet FileSystemObject. Pour ce faire, il faut d'abord ajouter une référence au projet : la référence Microsoft ScriptingRuntime Ensuite, onpeut faire comme ça :
Dim objFSO as Scripting.FileSystemObject
Dim objTS as Scriptint.TextStream
set objFSO=new FileSystemObject
set objTS=objFSO.OpenTextFile("c: est.txt",ForReading,false)
set objFSO=nothing
! Maintenant on peut lire le fichier ligne par ligne
Do while not objTS.AtEndOfStream
sTxtLine = objTS.ReadLine()
Loop
Set objTS=nothing
20 oct. 2003 à 21:21
21 mai 2003 à 11:38
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.