Function doesn't work when stepping into?

Doodoo

Golden Member
Feb 14, 2000
1,423
0
76
I'm working on a function that reads an excel spreadsheet into a multidimensional array, but when I go to debug the program in VS2005 it runs fine, but when I was trying to debug some other stuff and stepping through the program, the function doesn't work. When the program gets to Dim RouteArray As Object(,) = excelSheet.UsedRange.Value, it errors out with HRESULT: 0x800401A8. Doesn't look like it matters what is in the worksheet either...i created a new worksheet with just a few numbers and still get the same error. I haven't programmed since college, so any help is appreciated.
Code:
Public Function getWriteSchedule(ByVal sheet As String) As Object
        Dim provider As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture

        Dim excel = New Microsoft.Office.Interop.Excel.Application()
        excel = CreateObject("Excel.Application")
        excel.Workbooks.Open(SchedulePathTextBox.Text)
        Dim excelSheet As Microsoft.Office.Interop.Excel.Worksheet
        excelSheet = excel.Workbooks(1).Worksheets(sheet) '

        Dim RouteArray As Object(,) = excelSheet.UsedRange.Value

        excel.Workbooks.Close()
        excel.quit()
        excel = Nothing
        excelSheet = Nothing
        Return RouteArray
    End Function
 
Last edited:

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Are you sure these both succeeded with the given values for sheet, SchedulePathTextBox.Text?

> excel.Workbooks.Open(SchedulePathTextBox.Text)

> excelSheet = excel.Workbooks(1).Worksheets(sheet)
 

Doodoo

Golden Member
Feb 14, 2000
1,423
0
76
As far as i know it works. When i run the program, it seems to run fine. I'm just adding a few things to the program and wanted to step through a few if statements and saw that it bombed out on that function. The text box is tied to a button with a file dialog. The function gets called with the sheet name within the worksheet. The program will use the same spreadsheet each time.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
I haven't used VB in many years, but when you say this:

> As far as i know it works.

Did you actually look at the values of the sheet and textbox while stepping, and the results of the Open and = steps?

You might find the incoming values aren't what you expected (when stepping), or that one of the two statements returned an error result.
 

Doodoo

Golden Member
Feb 14, 2000
1,423
0
76
The textbox and sheet values look correct when I'm stepping through. I've added some test output when actually running the program and it correctly reads in the spreadsheet. I can't seem to figure out why it bombs out when stepping through though. Its the same spreadsheet and same program....
 

sm625

Diamond Member
May 6, 2011
8,172
137
106
The textbox and sheet values look correct when I'm stepping through. I've added some test output when actually running the program and it correctly reads in the spreadsheet. I can't seem to figure out why it bombs out when stepping through though. Its the same spreadsheet and same program....

It may be the same program but who knows how many DLLs could be debug DLLs rather than release DLLs. When that happens to me I always consider the option of running release code and using messageboxes to help me debug. If what I need to do is simple enough then this is usually faster than tryign to figure out what is going on with the stupid debugger.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
The textbox and sheet values look correct when I'm stepping through. I've added some test output when actually running the program and it correctly reads in the spreadsheet. I can't seem to figure out why it bombs out when stepping through though. Its the same spreadsheet and same program....

Did you look at the values of the open function and = assignment before the UseRange command to make sure they succeeded?
 

Tweak155

Lifer
Sep 23, 2003
11,448
262
126
Two things -

excelSheet needs to be checked to make sure its not nothing

and

excelSheet.UsedRange needs to checked to return a valid range.

Also if you have error handling above the function, the error you're seeing may be misleading.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |