I get this error, can you guys help? someone else wrote this code before I started working here and now its not working so im trying to figure it out. Thanks so much
Here is the error I get.
Here is the Actual Code, I'll Bold the actual lines the error is referring to. Thanks so muchCode:************** Exception Text ************** System.NullReferenceException: Object reference not set to an instance of an object. at ERX_Ad_Hoc.Form1.ASCIIsumOfString(String[] ArrayString) in P:\AD_HOC ERX POLLING\ERX Ad Hoc\Form1.vb:line 172 at ERX_Ad_Hoc.Form1.OpenExcelWkbk_Click(Object sender, EventArgs e) in P:\AD_HOC ERX POLLING\ERX Ad Hoc\Form1.vb:line 147 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)
Code:Private Sub OpenExcelWkbk_Click(sender As Object, e As EventArgs) Handles OpenExcelWkbk.Click Dim xlApp As Object = CreateObject("Excel.Application") 'Creates Excel Object Dim xlWorkbook As Object = xlApp.Workbooks.Open("""G:\ERX Trending.xlsm""") 'Opens Workbook Dim xlSheet As Object = xlWorkbook.Worksheets("Historical Data") 'Opens Worksheets xlSheet.Range("B1").Value = ComboBox1.SelectedItem 'Puts ERX in ComboBox into ERX Selection in Spreadsheet Dim DateEnd As Date = Date.Today 'Gets Todays Date Dim DateStart As Date = DateEnd.AddDays(-1) 'Gets Yesterdays Date Dim Time = Date.Now.ToShortTimeString 'Gets current time xlSheet.Range("D1").Value = DateStart 'Sets Time/Date Options for Last 24 Hours xlSheet.Range("D2").Value = DateEnd 'Sets Time/Date Options for Last 24 Hours xlSheet.Range("F1").Value = Time 'Sets Time/Date Options for Last 24 Hours xlSheet.Range("F2").Value = Time 'Sets Time/Date Options for Last 24 Hours xlSheet = xlWorkbook.Worksheets("Lists") 'Moves to hidden "Lists" Worksheet Dim Counter = 0 'Creates Counter Dim CellValue = xlSheet.Range("A1").VALUE 'Get Value from cell A1 in the hidden "Lists" Worksheet Dim ExcelList(500) As String While CellValue <> Nothing 'This will loop while there is a value in cell A1 CellValue = xlSheet.Range("A" & (Counter + 1).ToString).VALUE 'cell A1 value ExcelList(Counter) = CellValue Counter = Counter + 1 End While Array.Resize(ExcelList, Counter) <--- Line 147 Dim ExcelByte = ASCIIsumOfString(ExcelList) Dim ERXByte = ASCIIsumOfString(ERX_Arrays.objArray) If ExcelByte <> ERXByte Then Counter = 0 While Counter <= ERX_Arrays.objArray.Length - 1 'While Loop Updates ERX Spreadsheet List xlSheet.Range("A" & (Counter + 1).ToString).Value = ERX_Arrays.objArray(Counter) Counter = Counter + 1 End While End If xlWorkbook.Save() 'Saves Workbook xlWorkbook.Close() 'Closes Workbook xlApp.Quit() 'Quits Excel xlSheet = Nothing 'Empties Excel Variables xlWorkbook = Nothing 'Empties Excel Variables xlApp = Nothing 'Empties Excel Variables System.GC.Collect() 'Ends Excel Processes Process.Start("EXCEL.EXE", """G:\ERX Trending.xlsm""") 'Starts UI for Excel Wkbk End Sub Private Function ASCIIsumOfString(ArrayString() As String) Dim sum As Int32 Dim tempString As String For i = 0 To (ArrayString.Length - 1) <---Line 172 tempString = ArrayString(i) For n = 1 To tempString.Length sum = sum + Convert.ToByte(tempString(n - 1)) Next Next Return sum End Function




Reply With Quote
