Hallo,
ich hatte mal ein kleines Script für die Arbeit gemacht, mit dem ein paar Kollegen Ersatzteile aus einem Lager ausbuchen können. Das Programm lief bisher einwandfrei, bis ich die Spalte Bemerkungen hinzugefügt habe, seither erhalte ich die Meldung:
System.ArgumentOutOfRangeException: "startIndex darf nicht länger als die Länge der Zeichenfolge sein.Parametername: startIndex"
Spoiler anzeigen
System.ArgumentOutOfRangeException
HResult=0x80131502
Nachricht = startIndex darf nicht länger als die Länge der Zeichenfolge sein.
Parametername: startIndex
Quelle = mscorlib
Stapelüberwachung:
bei System.String.Substring(Int32 startIndex, Int32 length)
bei System.String.Substring(Int32 startIndex)
bei Lagerentnahmen.Form1.Button1_Click(Object sender, EventArgs e)
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bei Lagerentnahmen.My.MyApplication.Main(String[] Args)
Diese Ausnahme wurde ursprünglich von dieser Aufrufliste ausgelöst:
[Externer Code]
Ich dachte mir, dass ich die Änderung einfach rückgängig mache und dann passt es schon, jedoch tritt der Fehler nun auch so sporadisch auf. Nachvollziehbar ist der Fehler für mich momentan nicht, ich denke er kommt aus dem Excel Interop?
Spoiler anzeigen
ich hatte mal ein kleines Script für die Arbeit gemacht, mit dem ein paar Kollegen Ersatzteile aus einem Lager ausbuchen können. Das Programm lief bisher einwandfrei, bis ich die Spalte Bemerkungen hinzugefügt habe, seither erhalte ich die Meldung:
System.ArgumentOutOfRangeException: "startIndex darf nicht länger als die Länge der Zeichenfolge sein.Parametername: startIndex"
System.ArgumentOutOfRangeException
HResult=0x80131502
Nachricht = startIndex darf nicht länger als die Länge der Zeichenfolge sein.
Parametername: startIndex
Quelle = mscorlib
Stapelüberwachung:
bei System.String.Substring(Int32 startIndex, Int32 length)
bei System.String.Substring(Int32 startIndex)
bei Lagerentnahmen.Form1.Button1_Click(Object sender, EventArgs e)
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bei Lagerentnahmen.My.MyApplication.Main(String[] Args)
Diese Ausnahme wurde ursprünglich von dieser Aufrufliste ausgelöst:
[Externer Code]
Ich dachte mir, dass ich die Änderung einfach rückgängig mache und dann passt es schon, jedoch tritt der Fehler nun auch so sporadisch auf. Nachvollziehbar ist der Fehler für mich momentan nicht, ich denke er kommt aus dem Excel Interop?
VB.NET-Quellcode
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Datum = Now.ToString("yyyy-MM-dd HH:mm")
- ListBox1.Items.Clear()
- If cmb_BME.Text = "" Or cmb_Entnehmer.Text = "" Or cmb_Maschine.Text = "" Or cmb_MatNr.Text = "" Then
- MessageBox.Show("Das Ersatzteil kann nicht gebucht werden, da die Eingaben unvollständig sind!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
- Exit Sub
- End If
- Dim xlApp As New Excel.Application
- Dim xlWorkBook As Excel.Workbook
- Dim Tabelle As Excel.Worksheet
- Dim KW As String = DateToWeek(Now)
- Dim file As String = Form2.tb_path.Text & Form2.tb_filename.Text & "_" & KW & ".xlsx"
- If Not System.IO.File.Exists(file) Then
- xlWorkBook = xlApp.Workbooks.Add
- Tabelle = xlWorkBook.Sheets(1)
- xlApp.Visible = False
- 'Überschriften
- Tabelle.Cells(1, 1).Value = Buchung
- Tabelle.Cells(1, 2).Value = Materialnr
- Tabelle.Cells(1, 3).Value = Bezeichnung
- Tabelle.Cells(1, 4).Value = Anzahl
- Tabelle.Cells(1, 5).Value = BME
- Tabelle.Cells(1, 6).Value = Maschine
- Tabelle.Cells(1, 7).Value = Vorname
- Tabelle.Cells(1, 8).Value = DatumString
- Tabelle.Cells(1, 9).Value = Bemerkung
- xlWorkBook.SaveAs(file)
- xlWorkBook.Close()
- xlApp.Quit()
- End If
- xlApp = DirectCast(CreateObject("Excel.Application"), Excel.Application)
- xlWorkBook = xlApp.Workbooks.Open(file)
- Tabelle = xlWorkBook.Sheets(1)
- xlApp.Visible = False
- Dim row = xlWorkBook.Sheets(1).Cells(xlWorkBook.Sheets(1).Rows.Count, 1).End(Excel.XlDirection.xlUp).Offset(1).Row
- 'Buchungsdaten eintragen
- Tabelle.Cells(row, 1).Value = " "
- Tabelle.Cells(row, 2).Value = Microsoft.VisualBasic.Left(cmb_MatNr.Text, 8)
- Tabelle.Cells(row, 3).Value = cmb_MatNr.Text.Substring(9)
- Tabelle.Cells(row, 4).Value = TextBox1.Text
- Tabelle.Cells(row, 5).Value = cmb_BME.Text
- Tabelle.Cells(row, 6).Value = cmb_Maschine.Text
- Tabelle.Cells(row, 7).Value = cmb_Entnehmer.Text
- Tabelle.Cells(row, 8).Value = Datum
- Tabelle.Cells(row, 9).Value = TextBox2.Text
- 'Formatierung
- Tabelle.Range("A1:I1").Font.Bold = True
- Tabelle.Columns.AutoFit()
- xlApp.DisplayAlerts = False
- xlWorkBook.Save()
- xlWorkBook.Close()
- xlApp.Quit()
- Kill_ExcelInstanz()
- ListBox1.Items.Add(TextBox1.Text & " | " & cmb_BME.Text & " | " & cmb_MatNr.Text & " | " & cmb_Maschine.Text & " | " & cmb_Entnehmer.Text & " | " & Datum)
- cmb_BME.Text = "ST"
- cmb_Entnehmer.Text = ""
- cmb_Maschine.Text = ""
- cmb_MatNr.Text = ""
- TextBox1.Text = ""
- TextBox2.Text = ""
- End Sub