Jump to content

I need some help with arrays...:P


Recommended Posts

Hello everyone!! ;)

OK...here's my code:

For $x = 1 To $classes ; $classes is a number...:idiot:

Dim $class[$x] = InputBox("What grade?", "What's your grade for class #" & $x & "??")

$x + 1

Next

It tells me the following error when I get to that loop:

Line 18 (File "<not_gonna_tell_u>"):

Dim $class[$x] = InputBox("What grade?", "What's your grade for class #" & $x & "??")

Dim $class[$x] ^ ERROR

Error: Array variable subscript badly formatted.

Why is it giving me that?? :D

Thanx!! :lol:

El-Truchahttp://www.truchasoft.tk[url="ftp://tsfc.homeftp.net"]ftp://tsfc.homeftp.net[/url]hotline://tsfc.ath.cx

Link to comment
Share on other sites

You have to declare an array before you use it. By the way, arrays normally start with index 0 so Dim $array[10] would create elements 0 thru 9. If you want an element with index 10 you need to Dim $a[11].

Also, I'm not sure why you have $x + 1 in your For loop, because $x is incremented automatically and you don't assign the value back to anything.

Dim $class[$classes+1] 
For $x = 1 To $classes; $classes is a number...tongue.gif
   $class[$x] = InputBox("What grade?", "What's your grade for class #" & $x & "??")
Next
Edited by Larry
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Larry, CyberSlug, theres probably no harm in the "Dim $class[$x]" you both left in the For loop, but I think its a very bad example to leave. There also may be a performance hit as a new array is Dim'ed every time before the array is overwritten by the InputBox() return value. Also, looking closer, Larry's code my not even run as Dim $array[0] is illegal, but that is what will happen during the first iteration of the loop.

Link to comment
Share on other sites

I just made one of those, it's in the scripts and scraps forum thing. =-o

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

  • Developers

Now...I have another question: how do u make it return a decimal number with periods?? because:

1 + 3 + 2 + 1 = 7 / 4 = 1.75

And it just returns 1...:D

How do I fix that?? :idiot:

Thanx!! :lol:

<{POST_SNAPBACK}>

when does it return only a 1 ? can you show the code that does ?

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

Yay it works!! ;):D

It says 1.75...thanx!! :D

But...I do this:

$finalGrade = $grade / $classes

MsgBox(4096, "", $finalGrade)

And it says the correct number, but then I do this:

$message = StringFormat("Your GPA is %d, that means you got a(n) %s!!", $finalGrade, $gradeLetter)

MsgBox(4096, "Your GPA...", $message)

Which is after the first code, and it says only 1!! :idiot:

Why??

Thanx!! :lol:

El-Truchahttp://www.truchasoft.tk[url="ftp://tsfc.homeftp.net"]ftp://tsfc.homeftp.net[/url]hotline://tsfc.ath.cx

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...