I am posting extensive details and code here, including the runtime error message I receive that keeps killing my application. I am about to pull my hair out because I cannot find anything wrong with the code, and I do not get the error when debugging the application in VB! Basically a user enters some medical information on a form in text boxes and adds some medical conditons and medications into two listbox controls on the form, on for medical problems and one for medications they are on. When Button1 (command button) is clicked, it calls a subroutine stored in a module1. Then the application throws and Index out of Bounds error and crashes, losing all information that was entered. Here is the code on Button1:
Here is the code for Store_MedData in the module. The error occurs on red text:Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext5.Click Call Store_MedData End Sub
AND, here is the Runtime error message when running the application compiled and installed on a workstation. I don't see how or why the index out of bounds error is occurring. It should never count anywhere outside of the number of items in the listbox according to the code:Code:Dim ClientLastName as string, ClientMI as String, ClientFirstName as string, ClientAddress as String, _ ClientAddress2 as String, ClientCity as String, ClientState as String, ClientZip as String, ClientDOB as String, _ ClientBloodType as String,ClientActiveMeds(frmmain.lstActiveMeds.Items.Count - 1) As String, _ ClientActiveMedProbs(frmmain.lstActiveMedProbs.Items.Count - 1) as String Public Sub Store_MedData() 'Store all client information as string values ClientLastName = Trim(frmmain.txtLastname.Text) ClientMI = Trim(frmmain.txtMI.Text) ClientFirstname = Trim(frmmain.txtFirstname.Text) ClientAddress = Trim(frmmain.txtAddress1.Text) ClientAddress2 = Trim(frmmain.txtAddress2.Text) ClientCity = Trim(frmmain.txtCity.Text) ClientState = Trim(frmmain.cmbState.Text) ClientZip = Trim(frmmain.mtxtZip.Text) ClientDOB = Trim(frmmain.mtxtDOB.Text) ClientBloodType = Trim(frmmain.cmbBloodType.Text) 'Store the path of the client photo ClientPhotoPath = Trim(frmmain.openPic.FileName) 'store all active medications information in an array & build a string For i As Integer = 0 To frmmain.lstActiveMeds.Items.Count - 1 ClientActiveMeds(i) = frmmain.lstActiveMeds.Items.Item(i).ToString Next If frmmain.lstActiveMeds.Items.Count = 0 Then ActiveMedsResult = "" Else ActiveMedsResult = String.Join(", ", ClientActiveMeds) ActiveMedsResult = Left(ActiveMedsResult, Len(ActiveMedsResult) - 2) End If 'store all active medical problem information in an array & build a string For i As Integer = 0 To frmmain.lstActiveMedProbs.Items.Count - 1 ClientActiveMedProbs(i) = frmmain.lstActiveMedProbs.Items.Item(i).ToString Next If frmmain.lstActiveMedProbs.Items.Count = 0 Then ActiveMedProbsResult = "" Else ActiveMedProbsResult = String.Join(", ", ClientActiveMedProbs) ActiveMedProbsResult = Left(ActiveMedProbsResult, Len(ActiveMedProbsResult) - 2) End If End Sub
The application is being run on a PC running Windows Vista Home Premium w/ SP1. (aka. Windows "Worthless Edition")Code:See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.IndexOutOfRangeException: Index was outside the bounds of the array. at MYAPP.Medical.Store_Data() at MYAPP.frmmain.Button1_Click(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) ************** Loaded Assemblies ************** mscorlib Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3074 (QFE.050727-3000) CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll ---------------------------------------- MyAPP Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0 CodeBase: file:///C:/Program%20Files/MYAPP/MYAPP.exe ---------------------------------------- Microsoft.VisualBasic Assembly Version: 8.0.0.0 Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll ---------------------------------------- System Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll ---------------------------------------- System.Windows.Forms Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- System.Drawing Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ---------------------------------------- System.Runtime.Remoting Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll ---------------------------------------- System.Configuration Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll ---------------------------------------- System.Xml Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3074 (QFE.050727-3000) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- AxInterop.csXImage Assembly Version: 3.4.0.0 Win32 Version: 3.4.0.0 CodeBase: file:///C:/Program%20Files/MYAPP/AxInterop.csXImage.DLL ---------------------------------------- Interop.csXImage Assembly Version: 3.4.0.0 Win32 Version: 3.4.0.0 CodeBase: file:///C:/Program%20Files/MYAPP/Interop.csXImage.DLL ---------------------------------------- ************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled. For example: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.
Any help getting this issue resolved is extremely appreciated as it is driving me crazy and is the only thing keep my application from being used. I have been trying to resolve this issue for over a month now with no success. Thanks in advance for any insight.
-Jeremy





Reply With Quote