Jump to content

Could use some help


 Share

Recommended Posts

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

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 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

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 by notta
Link to comment
Share on other sites

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

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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...