G
Guest
I am writing an application and I want to be able to setup an array when the
form loads with some data I will use throughout the program.
Public Shared ptrArray() As String
Public Sub Initilize_Variables()
'Load Default Directory Information
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
'Start a new workbook in Excel
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open("C:\Program Files\Requisition
Print\Requisition Print Default Directories.xls")
oSheet = oBook.Worksheets("Printers")
Dim i As Integer
Dim CellA As String
Dim CellB As String
For i = 1 To 10
CellA = "$A$" & i
CellB = "$B$" & i
ptrArray(oSheet.Range(CellA).Text) = oSheet.Range(CellB).Text
Next
oBook.Close(False)
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
End SubT
This code gets an error "Conversion from string "F3075" to type 'Integer' is
not valid" in this line of code:
ptrArray(oSheet.Range(CellA).Text) = oSheet.Range(CellB).Text
"F3075" should be the Array subscript
What I want to end up with is an array like this:
ptrArray("F3075") = "Epson Printer"
ptrArray("Form2") = "HP Printer"
etc.
Both the subscript and the data are picked up from a predefined file.
Any help would be appreciated.
form loads with some data I will use throughout the program.
Public Shared ptrArray() As String
Public Sub Initilize_Variables()
'Load Default Directory Information
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
'Start a new workbook in Excel
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open("C:\Program Files\Requisition
Print\Requisition Print Default Directories.xls")
oSheet = oBook.Worksheets("Printers")
Dim i As Integer
Dim CellA As String
Dim CellB As String
For i = 1 To 10
CellA = "$A$" & i
CellB = "$B$" & i
ptrArray(oSheet.Range(CellA).Text) = oSheet.Range(CellB).Text
Next
oBook.Close(False)
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
End SubT
This code gets an error "Conversion from string "F3075" to type 'Integer' is
not valid" in this line of code:
ptrArray(oSheet.Range(CellA).Text) = oSheet.Range(CellB).Text
"F3075" should be the Array subscript
What I want to end up with is an array like this:
ptrArray("F3075") = "Epson Printer"
ptrArray("Form2") = "HP Printer"
etc.
Both the subscript and the data are picked up from a predefined file.
Any help would be appreciated.