Jump to content
Sign in to follow this  
computergroove

StringSplit Confusion

Recommended Posts

computergroove

I have a txt file that has info like the following:

Tony;Yang;123@yahoo.com;password1;192.168.1.1;3564

The above is one of several lines in the txt file. I want to read one line at a time and assign the data to variables to call later in the program. I hae setup the following:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=junk auto clicker qb.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
$Paused = $Paused
Global $f_in = @ScriptDir & "\FakeNames.txt"
Global $regNum
$regNum = 1

Func Start_Script()
Local $f_in = @ScriptDir & "\FakeNames.txt"; search for and scan database.txt for validity
        $fh_in = FileOpen($f_in, 0)
        If $fh_in = -1 Then ; Check if file opened for reading OK
            MsgBox(0, "Error 1", "Can't find FakeNames.txt.")
            Sleep(5000)
            exit
        EndIf
    EndFunc


While 1
    local $array[1]
$File = FileReadLine($f_in,0)     <-------Problem area
StringSplit ( "$File", ";", 0)
MsgBox(4096, "Error 2", $array[1])   <--------End problem area

WEnd

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

I have looked at the documentation online with no luck. What I want to do is:

1 read the nest line in the txt file and assign the first snippet of data to a variable. So something like:

$array[1]=$firstName

$array[2]=$lastName

$array[3]=$emailAddress

etc

How should I declare the variables and what is the correct syntax to store the data?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
memoryoverflow

$File = FileReadLine($f_in,0) <-------Problem area

StringSplit ( "$File", ";", 0)

MsgBox(4096, "Error 2", $array[1]) <--------End problem area

Leave the doublequotes out: $File should be a string variable not a string literal.

Edited by memoryoverflow

(The signature is placed on the back of this page to not disturb the flow of the thread.)

Share this post


Link to post
Share on other sites
computergroove

$File = FileReadLine($f_in,0) <-------Problem area

StringSplit ( "$File", ";", 0)

MsgBox(4096, "Error 2", $array[1]) <--------End problem area

Leave the doublequotes out: $File should be a string variable not a string literal.

OK I am not getting an error message when I run the script however I am getting a looping blank message window and I still dont know the correct syntax to use to identify the information in the array so I can pull out array item 4 for example. The number of variables in the array will be constant. Do I need to declare all the variables that I will be using in the function? Also what do I need to do to output the first part of the array to the message window?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
memoryoverflow

Hard to guess the content of $File, if you don't tell. Your question was re StringSplit and it could be answered, if the string to be split was known.


(The signature is placed on the back of this page to not disturb the flow of the thread.)

Share this post


Link to post
Share on other sites
computergroove

The contents of FakeNames.txt is:

tony;yang;projectorbvalor@yahoo.com;vionx;vionx

tnoy;yang;tnoyyang@ymail.com;duce2;duce2

Anthony;Yang;Yanga51@yahoo.com;folls6;folls6

Tony;Yaj;yajtony@yahoo.com;banoku;banoku

Toni;Yaj;toniyaj@rocketmail.com;solpil;solpil

Anthony;Yaj;Anthonyyaj@yahoo.com;kalas;kalas

Tony;Yan;yantony@rocketmail.com;slaad2;slaad2

Anthony;Yan;yananthony@ymail.com;abc12;abc12

We are going to add more to it though. Does this help? I want to test the script to get a message window saying "tony" and then make a modification and get it to say "vionx". Ill have enough information at that point to move forward.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
memoryoverflow

o dear, how simple - StringSplit's result hadn't been assinged:

$array = StringSplit( $File, ";" )


(The signature is placed on the back of this page to not disturb the flow of the thread.)

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.