notta Posted March 11, 2008 Share Posted March 11, 2008 Guys, I have some strange stuff going on here and would appreciate some help. Under one account I receive no problems running this script, but while under another account the script will fail stating "Variable used without being declared $stringsp[0] = 3 ^ ERROR Scite never reports an error during SyntaxCheck. Here is the code: for loop about 1000 times if FileExists("X:\" & $scriptDir & $computerName & ".csv") Then $fOpen1 = FileOpen("X:\" & $scriptDir & $computerName & ".csv",0) $cLine = FileReadLine($fOpen1) FileClose($fOpen1) $stringsp = StringSplit($cLine,",") Else $stringsp[0] = 3 ;<- problem $stringsp[1] = "-------";<- problem $stringsp[2] = " ";<- problem $stringsp[3] = "-------";<- problem EndIf end of loop I'm writing to an excel spreadsheet, so if the file is found, split the comma delimited csv file and write only the first 3 fields. If the file is not found fill the cells with "-------". This is weird how it works under one account without issue, but will not run under another. Thanks. Link to comment Share on other sites More sharing options...
jokke Posted March 11, 2008 Share Posted March 11, 2008 (edited) Ubound is what you should use. if FileExists("X:\" & $scriptDir & $computerName & ".csv") Then $fOpen1 = FileOpen("X:\" & $scriptDir & $computerName & ".csv",0) $cLine = FileReadLine($fOpen1) FileClose($fOpen1) $stringsp = StringSplit($cLine,",") If UBound($stringsp) >= 4 Then $stringsp[0] = 3 ;<- problem $stringsp[1] = "-------";<- problem $stringsp[2] = " ";<- problem $stringsp[3] = "-------";<- problem EndIf EndIf BTW, removed else since $stringsp was then unusefull. Edited March 11, 2008 by jokke UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt. Link to comment Share on other sites More sharing options...
notta Posted March 11, 2008 Author Share Posted March 11, 2008 (edited) Ubound is what you should use. if FileExists("X:\" & $scriptDir & $computerName & ".csv") Then $fOpen1 = FileOpen("X:\" & $scriptDir & $computerName & ".csv",0) $cLine = FileReadLine($fOpen1) FileClose($fOpen1) $stringsp = StringSplit($cLine,",") If UBound($stringsp) >= 4 Then $stringsp[0] = 3 ;<- problem $stringsp[1] = "-------";<- problem $stringsp[2] = " ";<- problem $stringsp[3] = "-------";<- problem EndIf EndIf BTW, removed else since $stringsp was then unusefull. Thanks man. $stringsp will always be greater than 4. $computername.csv file is in the form of first,last,phone,mode,....., There are about 35 elements in that array. It wants $stringsp declared before it's used, but I'm not too sure how to do it. I don't understand why it works under one account, but not another. Oh yea I ran it and here were the results: C:\computer.au3 (70) : ==> Variable used without being declared.: If UBound($stringsp) >= 4 Then If UBound(^ ERROR Edited March 11, 2008 by notta Link to comment Share on other sites More sharing options...
jokke Posted March 11, 2008 Share Posted March 11, 2008 probably $cLine was a blank line. thus making split not kicking inn. add another if where you check if line has "," inn it. if FileExists("X:\" & $scriptDir & $computerName & ".csv") Then $fOpen1 = FileOpen("X:\" & $scriptDir & $computerName & ".csv",0) $cLine = FileReadLine($fOpen1) FileClose($fOpen1) If StringInStr($cLine,",") > 0 Then $stringsp = StringSplit($cLine,",") If UBound($stringsp) >= 4 Then $stringsp[0] = 3 ;<- problem $stringsp[1] = "-------";<- problem $stringsp[2] = " ";<- problem $stringsp[3] = "-------";<- problem EndIf EndIf EndIf UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt. Link to comment Share on other sites More sharing options...
notta Posted March 11, 2008 Author Share Posted March 11, 2008 I want to initialize the array to a default value on each iteration of the loop, but I'm getting a bad syntax command. I'm initializing just as the manual states, but it's not liking the syntax. Why is this incorrect? Dim stringsp[0] = "3" Dim stringsp[1] = "-----" Dim stringsp[2] = "-----" Dim stringsp[3] = "-----" Link to comment Share on other sites More sharing options...
jokke Posted March 11, 2008 Share Posted March 11, 2008 Best guess is using a 2 dimensional array. Since i dont quite understand what you are doing. UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt. Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 11, 2008 Share Posted March 11, 2008 I want to initialize the array to a default value on each iteration of the loop, but I'm getting a bad syntax command. I'm initializing just as the manual states, but it's not liking the syntax. Why is this incorrect? Dim stringsp[0] = "3" Dim stringsp[1] = "-----" Dim stringsp[2] = "-----" Dim stringsp[3] = "-----"First, AutoIt variables start with a dollar sign "$". You can't DIM a single element in the array, just the whole thing. Either DIM the array and then set the values without DIM, or DIM the array and set the values on the same line of code:; Method one Dim $stringsp[4] $stringsp[0] = "3" $stringsp[1] = "-----" $stringsp[2] = "-----" $stringsp[3] = "-----" ; Method two Dim $stringsp[4] = ["3", "-----", "-----", "-----"] 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...
notta Posted March 11, 2008 Author Share Posted March 11, 2008 I have to be more careful with my posts. I got ripped yesterday because I posted incorrect code because I manually typed it in compared to just copying from my script. I had the dollar signs on my variables Anyway, I resolved the use by adding: Dim $stringsp[50] for $i = 1 To 3 $stringsp[$i] = "------" Next to the first line of my loop. Thanks for clearing that up though Psalty. Thanks for the help as well jokke. Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 11, 2008 Share Posted March 11, 2008 I have to be more careful with my posts. I got ripped yesterday because I posted incorrect code because I manually typed it in compared to just copying from my script. I had the dollar signs on my variables Anyway, I resolved the use by adding: Dim $stringsp[50] for $i = 1 To 3 $stringsp[$i] = "------" Next to the first line of my loop. Thanks for clearing that up though Psalty. Thanks for the help as well jokke. Note that you don't have to initialize all the elements in the array. The "Method Two" I posted will work for just setting the first four elements of a 50 element array too. 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...
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