El-Trucha Posted December 5, 2004 Share Posted December 5, 2004 Hello everyone!! OK...here's my code:For $x = 1 To $classes ; $classes is a number... Dim $class[$x] = InputBox("What grade?", "What's your grade for class #" & $x & "??") $x + 1NextIt 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] ^ ERRORError: Array variable subscript badly formatted.Why is it giving me that?? Thanx!! 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 More sharing options...
CyberSlug Posted December 5, 2004 Share Posted December 5, 2004 (edited) 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 December 5, 2004 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 More sharing options...
Valik Posted December 5, 2004 Share Posted December 5, 2004 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 More sharing options...
El-Trucha Posted December 5, 2004 Author Share Posted December 5, 2004 Yay it worked!! Thanx u all!! Now...I have another question: how do u make it return a decimal number with periods?? because:1 + 3 + 2 + 1 = 7 / 4 = 1.75And it just returns 1...How do I fix that?? Thanx!! 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 More sharing options...
the_lord_mephy Posted December 5, 2004 Share Posted December 5, 2004 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 More sharing options...
Developers Jos Posted December 5, 2004 Developers Share Posted December 5, 2004 Now...I have another question: how do u make it return a decimal number with periods?? because:1 + 3 + 2 + 1 = 7 / 4 = 1.75And it just returns 1...How do I fix that?? Thanx!! <{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 More sharing options...
El-Trucha Posted December 5, 2004 Author Share Posted December 5, 2004 Yes, here:$x = 1Dim $gradeFor $x = 1 To $classes $grade = $grade + $class[$x]Next$finalGrade = $grade / $classesOr if u'd like to see the whole thing, it's in the attachment...GPACalc.au3 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 More sharing options...
El-Trucha Posted December 6, 2004 Author Share Posted December 6, 2004 Nope, still get 1...thanx anyways... 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 More sharing options...
El-Trucha Posted December 6, 2004 Author Share Posted December 6, 2004 Yay it works!! It says 1.75...thanx!! But...I do this:$finalGrade = $grade / $classesMsgBox(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!! Why??Thanx!! 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 More sharing options...
El-Trucha Posted December 6, 2004 Author Share Posted December 6, 2004 That's what I was doing!! Yah, I tried %g and it worked!! Much, much thanx!! 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now