begin10 Posted February 21, 2008 Share Posted February 21, 2008 I keep getting error with array. Array variable has incorrect number of subscripts or subscript dimension range exceeded.: What I am trying to do is take the values from cvs file and insert them into sqlite database. Could someone please help. Here is my code. I am new at this #include "ExcelCOM_UDF.au3" #include <Array.au3> #include <sqlite.au3> #include <sqlite.dll.au3> ; Script Start - Add your code below here $Path = FileOpenDialog("Select csv File for All", @DesktopDir, "All (*.csv)") $databasePath = FileOpenDialog("Select db File for insert values", @DesktopDir, "All (*.db)") $var1 = _ExcelBookOpen($Path, 0) $sheet_num = _ExcelSheetNameGet($var1) $arrayLastRow = _ExcelSheetUsedRangeGet($var1, $sheet_num) ;$arrayLastRow[3] total line $arrayName = _ExcelReadArray($var1, 1, 1, $arrayLastRow[3], 1) ;ok $arraySSN = _ExcelReadArray($var1, 1, 2, $arrayLastRow[3], 1) ;ok $arrayNotes = _ExcelReadArray($var1, 1, 3, $arrayLastRow[3], 1) ;ok _ExcelBookClose($var1, 0) _SQLite_Startup () _SQLite_Open($databasePath) For $i = 0 To $arrayLastRow Step 1 $insertdb = "INSERT INTO Clients(Name,SSN,Notes,User) VALUES( " & "'" & $arrayName[$i] & "'" & "," & "'" &$arraySSN[$i] & "'" & "," & "'" & $arrayNotes[$i] & "'" & "," & "'" & 'NULL' & "'" & ");" _SQLite_Exec(-1, "BEGIN TRANSACTION") _SQLite_Exec(-1, $insertdb) _SQLite_Exec(-1, "COMMIT TRANSACTION") Next _SQLite_Close() _SQLite_Shutdown() MsgBox(0, "Finished", "All records have been inserted") Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 21, 2008 Share Posted February 21, 2008 I keep getting error with array. Array variable has incorrect number of subscripts or subscript dimension range exceeded.: What I am trying to do is take the values from cvs file and insert them into sqlite database. Could someone please help. Here is my code. I am new at this #include "ExcelCOM_UDF.au3" #include <Array.au3> #include <sqlite.au3> #include <sqlite.dll.au3> ; Script Start - Add your code below here $Path = FileOpenDialog("Select csv File for All", @DesktopDir, "All (*.csv)") $databasePath = FileOpenDialog("Select db File for insert values", @DesktopDir, "All (*.db)") $var1 = _ExcelBookOpen($Path, 0) $sheet_num = _ExcelSheetNameGet($var1) $arrayLastRow = _ExcelSheetUsedRangeGet($var1, $sheet_num) ;$arrayLastRow[3] total line $arrayName = _ExcelReadArray($var1, 1, 1, $arrayLastRow[3], 1) ;ok $arraySSN = _ExcelReadArray($var1, 1, 2, $arrayLastRow[3], 1) ;ok $arrayNotes = _ExcelReadArray($var1, 1, 3, $arrayLastRow[3], 1) ;ok _ExcelBookClose($var1, 0) _SQLite_Startup () _SQLite_Open($databasePath) For $i = 0 To $arrayLastRow Step 1 $insertdb = "INSERT INTO Clients(Name,SSN,Notes,User) VALUES( " & "'" & $arrayName[$i] & "'" & "," & "'" &$arraySSN[$i] & "'" & "," & "'" & $arrayNotes[$i] & "'" & "," & "'" & 'NULL' & "'" & ");" _SQLite_Exec(-1, "BEGIN TRANSACTION") _SQLite_Exec(-1, $insertdb) _SQLite_Exec(-1, "COMMIT TRANSACTION") Next _SQLite_Close() _SQLite_Shutdown() MsgBox(0, "Finished", "All records have been inserted") You didn't post the exact error you got, so we can't tell which of your array references is bad. Don"t assume _ExcelSheetUsedRangeGet() returned an array. Add some error checking to see if it returned what you expected. Do the same for your calls to _ExcelReadArray(). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
randallc Posted February 21, 2008 Share Posted February 21, 2008 Hi, I haven't looked closely, but sometimes; 1. Array needs to be transposed when using Excel Array in AutoIt?; not sure here. 2. Use helpfile example for import in "_SQLite_SQLiteExe "; then you don't need Excel Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now