Jump to content
Sign in to follow this  
GeekS

Reading array numbers one by one.

Recommended Posts

GeekS

Well, kinda hard to explain but here we go.

$Number = GUICtrlCreateInput("Number", 368, 75-20, 31, 20, $ES_CENTER, $WS_EX_TRANSPARENT)

Lets say you insert 178 into that Input box, so that we have

$Number = 178

Now what i want to do is seperate it into 3 numbers: 1, 7 and 8. So that i can use it another place like

$Number1 = 1
$Number2 = 7
$Number3 = 8

Thanks in advance, Gnu / GeekS.

Share this post


Link to post
Share on other sites
Szhlopp

Well, kinda hard to explain but here we go.

$Number = GUICtrlCreateInput("Number", 368, 75-20, 31, 20, $ES_CENTER, $WS_EX_TRANSPARENT)

Lets say you insert 178 into that Input box, so that we have

$Number = 178

Now what i want to do is seperate it into 3 numbers: 1, 7 and 8. So that i can use it another place like

$Number1 = 1
$Number2 = 7
$Number3 = 8

Thanks in advance, Gnu / GeekS.

Here it is in Array form:

Array[0] = Full string

Array[1] = First digit

ect

$Number = 178
Global $NumberArray[1]
$NumberArray[0] = 178
ReDim $NumberArray[StringLen($Number) + 1]
For $I = 1 To UBound($NumberArray) - 1
    $NumberArray[$I] = StringMid($Number, $I, 1)
Next

MsgBox(0, "Done", $NumberArray[2])

Share this post


Link to post
Share on other sites
DW1

Simpler yet:

$Number = 178
$ss = StringSplit( $Number, "" )

now you have an array

$ss[0] = 3 (number of entries in array)

$ss[1] = 1

$ss[2] = 7

$ss[3] = 8

EDIT: Changed "String($Number)" to just "$Number", as after testing it seemed to have the same results.

Edited by danwilli

Share this post


Link to post
Share on other sites
GeekS

Got both working, however Danwilli's is way easier to use for my (generally?) purpose. Thanks alot for the help guys ;)

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.