2014-09-19 65 views
1

我有一个Windows窗体应用程序在VB 我想要的条件是,如果通过命令行传递参数,则窗体不应该显示。 我不知道为什么,下面的代码是不能工作 任何建议,可以理解 感谢 戴维防止窗体加载,除非条件得到满足

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 

消息框就要到了,并显示5(5参数传递) 但随后的程序完全忽略if语句,并调出表单?

+0

您是否调试过检查arg()中返回的值?它是否达到了关闭?考虑用Me.Close替换后者() – 2014-09-19 04:41:46

回答

0

看着你的代码有:

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

... 

就表示,如果args来数为3行,再进行尝试访问ARGS(5),这将是第六届的说法。 您还在表单的加载事件which if your OS is a 64 bit OS any unhandled errors will be silently swallowed中执行此操作,而没有任何通知。

+0

感谢Mark。问题与您所说的完全相同 - 我的打字错误,但是因为它是在Form Load中,所以没有告诉我。反过来,该程序直接跳到表单。 – DaveyD 2014-09-19 13:18:06

+0

很高兴工作。我自己被这种情况困扰了。 – 2014-09-19 13:19:12