启动VB.Net WinForms程序时出现异常
这个程序在我自己的机器上完美地工作-程序总是在开发机器上工作,对吗 它似乎在发射时感到不安。申请有两种形式。默认表单检查是否有/buy命令行参数,如果是真的,则通过显示另一个表单[formSB_buy.Show()]并隐藏自身[Me.Hide()],切换到另一个表单 此应用程序只能从工具栏运行,该工具栏将有一个/sell或/buy作为单个命令行参数。它只检查/buy,因此任何其他内容都将直接使用默认表单。非常感谢您为解决此错误提供的任何帮助-我不确定如何解决此问题 例外情况:启动VB.Net WinForms程序时出现异常,vb.net,winforms,exception,Vb.net,Winforms,Exception,这个程序在我自己的机器上完美地工作-程序总是在开发机器上工作,对吗 它似乎在发射时感到不安。申请有两种形式。默认表单检查是否有/buy命令行参数,如果是真的,则通过显示另一个表单[formSB_buy.Show()]并隐藏自身[Me.Hide()],切换到另一个表单 此应用程序只能从工具栏运行,该工具栏将有一个/sell或/buy作为单个命令行参数。它只检查/buy,因此任何其他内容都将直接使用默认表单。非常感谢您为解决此错误提供的任何帮助-我不确定如何解决此问题 例外情况: System.In
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)
at System.Array.GetValue(Int32 index)
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetArrayValue(Object[] Indices)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.InternalLateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames, Boolean ReportErrors, ResolutionFailure& Failure, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateInvokeDefault(Object Instance, Object[] Arguments, String[] ArgumentNames, Boolean ReportErrors, Boolean[] CopyBack)
at SellBuy.formSB_Sell.formSB_Sell_Shown(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnShown(EventArgs e)
at System.Windows.Forms.Form.CallShownEvent()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
守则:
Imports System.IO
Imports System.Xml
Imports System.Xml.Linq
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Public Class formSB_Sell
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub formSB_Sell_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
If CommandLineArgs(0) = "/buy" Then
formSB_Buy.Show()
Me.Hide()
Else
Dim GMResult As String
Dim wholeline As String = Nothing
Dim arTextlines As Array
Dim arLinefields As Array
' Load the arTextlines array with the result of the profiles request
GMResult = GetMacro("&profiles.schwab..4")
'TextBox129.Text = GMResult
arTextlines = GMResult.Split(vbNewLine)
' Load the arLinefields array with the field data of the current arTextline
For x = 0 To arTextlines.Length - 1
arLinefields = Split(arTextlines(x), vbTab)
For y = 0 To arLinefields.Length - 1
wholeline = wholeline & Trim(arLinefields(y)) & " : "
Next y
Me.comboSBSell_ClientName.Items.Add(arLinefields(1) & " " & arLinefields(3))
wholeline = Nothing
Next x
Me.comboSBSell_ClientName.SelectedIndex = 0
End If
End Sub
只是一个猜测…你确定你正在通过,并且它正在读取命令行参数吗?你能为CommandLineArgs.length添加一个msgbox并查看它是否为1吗?这是一个数组索引越界错误,出现在
表单中。哪一行抛出异常?此时引用的数组的大小是多少?此时尝试引用它的索引值是什么?运行时环境没有提供所需的数据/状态,或者您需要添加一些边界检查代码来处理数据/状态与预期不同的情况。@如果CommandLineArgs.Count=0
,则错误为ArgumentOutOfRangeException。他有一种非同寻常的感觉。他的问题在于arLinefields
或arTextlines
。另一种可能是项。添加(arLinefields(1)&“&arLinefields(3))
。我打赌那就是臭虫所在的地方。我可能错了。如果您从OP检查堆栈跟踪,它会说System.Array是引发错误的地方。SelectedIndex不会抛出IndexOutfrange,但会抛出ArgumentOutOfRange。src:msdn^ 5分钟后无法编辑我的评论。src: