Jump to content

EASY Array excersies


layer
 Share

Recommended Posts

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
Link to comment
Share on other sites

Guest Mixture63

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.

Link to comment
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]
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
Link to comment
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)
Link to comment
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
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...