1

I have a windows form app in VB I wanted to condition that if arguments were passed through command line, then form should not show. I am not sure why that the following code is not working Any suggestions will be appreciated Thanks Davey

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim args As String() = Environment.GetCommandLineArgs()
    MsgBox(args.count())
    If args.Count() > 1 Then
        If args(1) = "delete" Then
            If args.Count() = 3 Then
                deletepage(args(2), args(5))
                Close()
            End If
        ElseIf args(1) = "add" Then
            If args.Count() >= 5 Then
                addpage(args(2), args(3), args(4), args(5))
                Close()
            End If
        End If
    End If
    loadnames()
End Sub

The message box is coming up and displaying 5 (5 arguments passed) But then the program totally ignores the if statement, and brings up the form??

DaveyD
  • 337
  • 1
  • 5
  • 15
  • Have you debugged to check the value being returned in the arg()? Is It reaching the Close? Consider replacing the latter by Me.Close() – Nadeem_MK Sep 19 '14 at 04:41

1 Answers1

0

looking at your code you have:

If args.Count() = 3 Then
    deletepage(args(2), args(5))

...

You are stating that if the number of args is equal to 3, then proceeding to try to access args(5) which would be the 6th argument. You are also doing this in the Load event of a Form, which if your OS is a 64 bit OS any unhandled errors will be silently swallowed without any notification.

Community
  • 1
  • 1
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
  • Thanks Mark. The problem was exactly as you said - I had an error in my typing, but because it was in Form Load, it didnt tell me. In turn, the program skipped straight to the form. – DaveyD Sep 19 '14 at 13:18