我有程序args
设置为Dim args As String() = Environment.GetCommandLineArgs()
。我使用arg
作为String
的args
。程序检查arg
是否以".lee"
结束,然后继续。否则,如果arg
以".txt"
结尾,它仍然继续下一步。否则,如果arg
不符合要求,则应弹出MsgBox
。防止arg显示MsgBox(),如果arg以“.lee”结尾 - VB.Net
什么问题是即使支持的类型文件执行,我的程序似乎显示错误对话框。
代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim args As String() = Environment.GetCommandLineArgs()
For Each arg As String In args
If arg.EndsWith(".lee") Then
leeReader.RichTextBox1.LoadFile(arg, RichTextBoxStreamType.PlainText)
TextBox1.Text = leeReader.RichTextBox1.Text
Btn1.PerformClick()
Else
If arg.EndsWith(".txt") Then
leeReader.RichTextBox1.LoadFile(arg, RichTextBoxStreamType.PlainText)
TextBox1.Text = leeReader.RichTextBox1.Text
Btn1.PerformClick()
Else
MsgBox("We don't recommend unsupported files")
Me.Close()
End If
End If
Next
End Sub
我试图添加Exit Sub
但它是行不通的。更改后
代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim args As String() = Environment.GetCommandLineArgs()
For Each arg As String In args
If arg.EndsWith(".lee") Then
leeReader.RichTextBox1.LoadFile(arg, RichTextBoxStreamType.PlainText)
TextBox1.Text = leeReader.RichTextBox1.Text
Btn1.PerformClick()
Exit Sub
Else
If arg.EndsWith(".txt") Then
leeReader.RichTextBox1.LoadFile(arg, RichTextBoxStreamType.PlainText)
TextBox1.Text = leeReader.RichTextBox1.Text
Btn1.PerformClick()
Exit Sub
Else
MsgBox("We don't recommend unsupported files. Give it a try?")
End If
End If
Next
End Sub
如果你知道解决方案/如果我要去的地方错了/你需要更多的帮助,请回答以下/评论。
您可以显示命令行的典型示例吗?你遇到空间还是其他的东西?在尝试解决导致问题的原因时,在消息框中显示'arg'。 –