Forum Moderators: phranque
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'get command peramiters
Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
For i As Integer = 0 To CommandLineArgs.Count - 1
Dim myvariable As String
myvariable = (CommandLineArgs(i))
Label1.Text = myvariable.Length 'only used for debug
If myvariable.Length = 0 Then
do something
End If
If myvariable.Length > 0 Then
do somethign else
End If
Next
End Sub
When a paramiter is sent it handles it correctly, but if no peramiter is sent it simple ignores both if statements.
The calue being sent is collected and passed to a variale (dim) so the value exists, even if it has no content. By checking the variable lenghth I was hoping to be able to confirm or eny if a value had been passed.
Is there somethign else I need to look into to determine if a peramiter has been passed to the exe. Does having no value passed bean that peramiter.lenghth = "0" would still not work?
I can confirm the value has been sent and received. I debuged this by assigning its value to a label, it showed the correct value within the app itself.
Thanks in advance.
Mack.
To make it work...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'get command peramiters
Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
For i As Integer = 0 To CommandLineArgs.Count - 1
Dim myvariable As String
myvariable = (CommandLineArgs(i))
Label1.Text = myvariable.Length 'only used for debugIf myvariable.Length = 0 Then
do something
exit sub
End If
Nextdo somethign else
End Sub
by exiting the sub I don't need a second conditional statement, and can run the code that the 2nd if statement would have contained.
Mack.
1) The for loop is executed only if at least one command-line argument is supplied.
OR
2) Is Nothing should be used as the test.
I could be way off the mark.
Kaled.