Jump to content

StringSplit probelm


Recommended Posts

Hi all,

Please help for this problem :

see bellow my code is for listing and extracting computer names from a file which have 850 lines

Arrive after 368 (i made test) it crash and said to me error.

I don't know if it is a size limitation or something else, could you help plz ? ty

C:\_DSA_\autoIt\mapRapide\mapGUI.au3 (228) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Local $listLine, $listsplit, $listdatelock, $listpcname, $listlogin, $listcontext, $fileNbLines, $fileRef

$fileNbLines = _FileCountLines("G:\Help_Desk\AutoIt\Login\listLogins-PCs.txt")

$fileRef = FileOpen("G:\Help_Desk\AutoIt\Login\listLogins-PCs.txt", 0)

If $fileRef <> -1 Then

If StringLen(GUICtrlRead($loginInput4PC)) = 5 Then

For $i = 1 To $fileNbLines Step 1

$listLine = FileReadLine($fileRef, $i)

$listsplit = StringSplit($listline,";", 1)

$listdatelock = $listsplit[2]

$listpcname = $listsplit[3]

$listlogin = $listsplit[4]

;$listcontext = $listsplit[5]

If $listlogin = GUICtrlRead($loginInput4PC) Then

GUICtrlSetData($ctrlInputComputer, StringUpper($listpcname))

ExitLoop

ElseIf $listpcname = GUICtrlRead($loginInput4PC) Then

GUICtrlSetData($listpcname, StringUpper($listdatelock))

ExitLoop

EndIf

Next

Else

MsgBox(0, "INFO", "5 car needed")

GUICtrlSetData($loginInput4PC, "")

EndIf

FileClose($fileRef)

Else

MsgBox(0, "ERROR" , "try again")

EndIf

Link to comment
Share on other sites

is the last line empty??

if so For $i = 1 To $fileNbLines-1 Step 1

or $fileNbLines = _FileCountLines - 1

just a thought

Edited by Rick

Who needs puzzles when we have AutoIt!!

Link to comment
Share on other sites

is the last line empty?? if so For $i = 1 To $fileNbLines-1 Step 1

just a thought

nop

i don't understand because it is a code that i got from a friend, and this code was working in his program.

i'll put this code as a function in my code and in his one it was a simple if loop.

Link to comment
Share on other sites

debug it with MsgBox(0,"",$listsplit [0] & @cr & $listsplit [1]) ;etc

it may come apparent then as one of the lines dont contain 4 or 5 splits

Edited by Rick

Who needs puzzles when we have AutoIt!!

Link to comment
Share on other sites

debug it with MsgBox(0,"",$listsplit [0] & @cr & $listsplit [1]) ;etc

it may come apparent then as one of the lines dont contain 4 or 5 splits

the split return 9 splits but i juste need 3 of them.

The file used is created by my program and i tried to filter just the 3 parameters i need at it creation but the same problem appeared

Link to comment
Share on other sites

i would like but i don't now a site were i can do that could you help me for that too (yes i'm noob :))

you attach it to a message, like this one

Who needs puzzles when we have AutoIt!!

Link to comment
Share on other sites

you attach it to a message, like this one

Lower on the screen, when you are writing your reply, find "File Attachments", click "browse" button, find the directory and file, then "Add this attachment" button, then wait, and "Add Reply" button

Best, Randall

Link to comment
Share on other sites

The problems is that the information in Line 369 of your data is "Different" so you have to check the number of strings returned by StringSplit function:

Local $listLine, $listsplit, $listdatelock, $listpcname, $listlogin, $listcontext, $fileNbLines, $fileRef

;$fileNbLines = _FileCountLines("G:\Help_Desk\AutoIt\Login\listLogins-PCs.txt")
$fileNbLines = _FileCountLines("listLogins-PCs.txt")
;$fileRef = FileOpen("G:\Help_Desk\AutoIt\Login\listLogins-PCs.txt", 0)
$fileRef = FileOpen("listLogins-PCs.txt", 0)

If $fileRef <> -1 Then
    If StringLen(GUICtrlRead($loginInput4PC)) = 5 Then
        For $i = 1 To $fileNbLines Step 1
            $listLine = FileReadLine($fileRef, $i)
            $listsplit = StringSplit($listline,";", 1)

            ;Check Here
            If $listsplit[0] >= 5 Then
                $listdatelock = $listsplit[2]
                $listpcname = $listsplit[3]
                $listlogin = $listsplit[4]
                ;$listcontext = $listsplit[5]

                If $listlogin = GUICtrlRead($loginInput4PC) Then
                    GUICtrlSetData($ctrlInputComputer, StringUpper($listpcname))
                    ExitLoop
                ElseIf $listpcname = GUICtrlRead($loginInput4PC) Then
                    GUICtrlSetData($listpcname, StringUpper($listdatelock))
                    ExitLoop
                EndIf
            Else
                ;you may comment or delete this line
                MsgBox(48, "Warning", "Line " & $i & " skipped",1)
            EndIf
        Next
    Else
        MsgBox(0, "INFO", "5 car needed")
        GUICtrlSetData($loginInput4PC, "")
    EndIf
    FileClose($fileRef)
Else
    MsgBox(0, "ERROR" , "try again")
EndIf
Link to comment
Share on other sites

The problems is that the information in Line 369 of your data is "Different" so you have to check the number of strings returned by StringSplit function:

It is crazy i wasn't see it !!!!!!!!! :\

Thanks a lot

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