Jump to content

Help splitting a string


Recommended Posts

Ive never made a real program with AutoIt before and Im having some trouble splitting a String from a txtBox. My goal here is to take the String from a AutoIt form txtBox and type (Send) the String letter-by-letter. I receive no errors but I believe Im getting an infinate loop of Null substrings. Should I be using the StingMid function for this?

My Code:

CODE

Dim $UN = "abc"

Dim $subStr = ""

Dim $i = 0;

Dim $UNLen = StringLen($UN)

MsgBox(4096, "UserName Length", $UNLen)

$i = 0

While $i < $UNLen

$subStr = StringMid($UN,$i,1)

;If $subStr NOT=="" Then;//Ive taken this test out for now because the returned substring always seems to be Null

MsgBox(4096, "UserName", $subStr)

Sleep(Random(200,400,1))

Send($subStr); //type in username element

;EndIf

WEnd

Link to comment
Share on other sites

  • Developers

Dim $UN = "abc"
Dim $subStr = ""
Dim $UNLen = StringLen($UN)
MsgBox(4096, "UserName Length", $UNLen)
For $i = 1 to $UNLen
    $subStr = StringMid($UN, $i, 1)
    Sleep(Random(200, 400, 1))
    Send($subStr)   ; //type in username element
Next

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hmm, seems like you're used to a syntax of another language...

Dim $UN = "abc"
Dim $subStr = ""
Dim $i = 0;
Dim $UNLen = StringLen($UN)
MsgBox(4096, "UserName Length", $UNLen)


$i = 0
While $i < $UNLen
$subStr = StringMid($UN,$i,1)
;If $subStr NOT=="" Then;//Ive taken this test out for now because the returned substring always seems to be Null
MsgBox(4096, "UserName", $subStr)
Sleep(Random(200,400,1))
Send($subStr); //type in username element
;EndIf
WEnd
oÝ÷ Ø*.ÖÞjëh×6
Dim $UN = "abc"

MsgBox(4096, "UserName Length", StringLen($UN))

For $i = 1 To StringLen($UN)
    MsgBox(4096, "UserName", StringMid($UN,$i,1))
    Sleep(300)
    Send($subStr)
Next

I'd prefer not using so many variables, though using variables to store a string length is faster than running the StringLen() function several times in a loop(though one extra time is not that bad, as in this case), depends on how many times it's called in a loop basically...

Edited by FreeFry
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...