Sign in to follow this  
Followers 0
layer

EASY Array excersies

5 posts in this topic

well, since i REALLY suck with arrays, i need to work on them, i still need some more work with them, but this is as dirty as ive ever gotten with arrays :lmao:

Func makeRndm()
    $num = Random(0, 3, 1)
    return $num
EndFunc

Func chooseGreet()
    $GreetNum = makeRndm()
    Dim $greet[4]
    $greet[0] = "Hello";English
    $greet[1] = "Hei";Norwegin(sp?)
    $greet[2] = "Bonjour";French
    $greet[3] = "Hola";Spanish
    MsgBox(0, "Greetings", $greet[$greetnum])
EndFunc

chooseGreet()

yea i know i didnt need the makeRndm function but making function calls is fun ! :P


FootbaG

Share this post


Link to post
Share on other sites



What?

The great layer has problems with arrays? :P

Your a good coder I'm suprised you having trouble with arrays. Arrays are easy. Of course, I seldom use them anymore. I should start using them again.

I always use them in C++ though.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

another one, im searching for more complex ones now.. but i gotta leave soon for dinner..

GUICreate("Array of control creation")
GUISetState()
Dim $ctrl[6]
For $i = 0 to UBound($ctrl) - 1
    $ctrl[$i] = GUICtrlCreateLabel($i, 10, 10 + ($i*20))
    Sleep(1000)
Next
GUICtrlCreateLabel("Tada !", 10, 10 + ($i*20))
Sleep(1000)
MsgBox(0, "", UBound($ctrl))

edit: modified according to Valik's improved code

Edited by layer

FootbaG

Share this post


Link to post
Share on other sites

another one, im searching for more complex ones now.. but i gotta leave soon for dinner..

GUICreate("Array of control creation")
GUISetState()
Dim $ctrl[6]
$ctrl[0] = GUICtrlCreateLabel("0", 10, 10)
Sleep(1000)
For $i = 1 to 5
    $ctrl[$i] = GUICtrlCreateLabel($i, 10, 10 + ($i*20))
    Sleep(1000)
Next
GUICtrlCreateLabel("Tada !", 10, 10 + ($i*20))
Sleep(1000)
layer, here's a little basic math for you. Anything multiplied by 0 is 0. That means your special case label you create outside the For loop is not necessary. You can get the same results with this:

GUICreate("Array of control creation")
GUISetState()
Dim $ctrl[6]
For $i = 0 to UBound($ctrl) - 1
    $ctrl[$i] = GUICtrlCreateLabel($i, 10, 10 + ($i*20))
    Sleep(1000)
Next
GUICtrlCreateLabel("Tada !", 10, 10 + ($i*20))
Sleep(1000)

Share this post


Link to post
Share on other sites

^

doh ! you're right... ohhh... ok, i knew that anything multiplied by 0 was 0 but clearly i wasnt using that fact in my script :P took me a second to figure how the ubound was working, a little help from the helpfile and you cleared everything up, thanks


FootbaG

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