If I'm not mistaken, this is VB .NET code, not VB6 or 5. Why not post your
question over on the vb_dotnet board? I can't help you.
Pete
-----Original Message-----
From: Gurinderpal Dhillon [mailto:gdhillon@e...]
Sent: Tuesday, February 18, 2003 7:55 PM
To: professional vb
Subject: [pro_vb] RE: Command Lines Parameters
Here is what doing
sub Main()
ParseCommandLineParameters()
........
......
end sub
Private Function GetCommandLineArgs() As String()
' Declare variables.
Dim separators As String = "-"
Dim commands As String = Microsoft.VisualBasic.Command()
Dim args() As String = commands.Split(separators.ToCharArray)
Return args
End Function
Public Sub ParseCommandLineParameters()
Dim lstrParameters() As String
Dim lintCount As Integer
Dim lobjExepHandling As EIT_ErrorUtil.cErrorUtil
Try
lstrParameters = GetCommandLineArgs()
For lintCount = 0 To UBound(lstrParameters)
If Len(lstrParameters(lintCount)) > 0 Then
Select Case LCase(lstrParameters(lintCount).Chars(0))
Case "s"c
If ValidateParameters(Trim(lstrParameters
(lintCount).Substring(2)), "date") Then
gdtStartDateForExch = CDate(Trim(lstrParameters
(lintCount).Substring(2)))
Else
Console.WriteLine("Invalid start date argument")
System.Environment.Exit(-1)
End If
Case "e"c
'If ValidateParameters(Trim(lstrParameters
(lintCount).Substring(2)), "date") Then
' gdtEndDateForExch = CDate(Trim(lstrParameters
(lintCount).Substring(2)))
'Else
' Console.WriteLine("Invalid start date argument")
'End If
End Select
End If
Next
Catch ex As Exception
lobjExepHandling = New EIT_ErrorUtil.cErrorUtil()
lobjExepHandling.LogException(ex)
End Try
End Sub
Private Function ValidateParameters(ByVal astrParameter As String,
ByVal astrType As String) As Boolean
Select Case LCase(astrType)
Case "string"
Return True
Case "integer"
Try
Dim lintInteger As Integer = Integer.Parse(astrParameter,
Globalization.NumberStyles.Any)
Return True
Catch ex As Exception
' invalid date
Return False
End Try
Case "date"
Try
Dim ldtDate As DateTime = Date.ParseExact(astrParameter,
System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern,
System.Globalization.DateTimeFormatInfo.CurrentInfo)
Return True
Catch ex As Exception
' invalid date
Return False
End Try
End Select
End Function
> What do you mean?
-----Original Message-----
From: Gurinderpal Dhillon [mailto:gdhillon@e...]
Sent: Tuesday, February 18, 2003 2:36 PM
To: professional vb
Subject: [pro_vb] RE: Command Lines Parameters
Thanx Peter! but i'm using this code only
-Guri
> Here's code that does recognize parameters supplied after the program
name
when run from the command line:
Dim msOriginalCommandLine As String
Dim msCommandLine As String
Dim miMaxMinutes As Integer
Dim
Private Sub Main()
msOriginalCommandLine = Command()
Call psParseCommandLine
'...program logic
End Sub
Private Function pfParseCommandLine()
' Parse command line parameters entered when program is started
' Valid parameter example: /M=5 /S=3
Dim Parms() As String
Dim i As Integer
' pfParseCommandLine = True ' Init to success
' get rid of commas, equal signs and slashes, then change to upper
case
msCommandLine = Replace(msOriginalCommandLine, ",", " ")
msCommandLine = Replace(msCommandLine, "/", " ")
msCommandLine = Replace(msCommandLine, "=", "")
msCommandLine = UCase(msCommandLine) & " " ' add space for split
' get individuals parm(s)
Parms = Split(msCommandLine, " ")
' analyze and validate each parameter
For i = 0 To UBound(Parms)
Select Case Left(Parms(i), 1)
Case "M"
If IsNumeric(Mid(Parms(i), 2)) _
And Len(Parms(i)) = 2 Then
miMaxMinutes = Mid(Parms(i), 2)
Else
MsgBox "Minutes '" & Mid(Parms(i), 2) & "'" & _
" is invalid, must be numeric and < 10"
pfParseCommandLine = False
End If
Case "S"
If IsNumeric(Mid(Parms(i), 2)) _
And Len(Parms(i)) = 2 Then
miMaxSeconds = Mid(Parms(i), 2)
MsgBox "Seconds '" & Mid(Parms(i), 2) & "'" & _
" is invalid, must be numeric and < 10"
pfParseCommandLine = False
End If
Case Else
If Parms(i) <> "" _
And Parms(i) <> " " Then
MsgBox "Unknown Parameter = '" & Left(Parms(i), 1)
& "'"
pfParseCommandLine = False
End If
End Select
Next i
End Function
Hope this helps,
Pete
-----Original Message-----
From: Gurinderpal Dhillon [mailto:gdhillon@e...]
Sent: Tuesday, February 18, 2003 2:53 AM
To: professional vb
Subject: [pro_vb] Command Lines Parameters
I'm making a console application in VB. net which take 2 command line
parameters. if run application in debug mode and give parameters in
Project properties its working fine but i run the application(exe) at
command prompt with parameter it doesn't recoganise the parameters.
Any Ideas....
Thanx
-Guri