Computer Science Canada piano keyboard help |
Author: | randomperson#5 [ Sun Jun 11, 2006 2:31 am ] | ||
Post subject: | piano keyboard help | ||
hi...someone pleasee help me.... i'm desperate!! i'm making this piano keyboard program, it kind of works, but the program keeps crashing, and says "variable has no value".
any help will be greatly appreciated!! |
Author: | TheOneTrueGod [ Sun Jun 11, 2006 7:00 am ] |
Post subject: | |
First of all, don't double post. Second of all, read the [Turing FAQ] (Top of the help page) |
Author: | Cervantes [ Sun Jun 11, 2006 9:05 am ] | ||||
Post subject: | |||||
I'm not seeing why that's causing a 'variable has no value' error just from the code you gave us. Is it possible that you are calling 'processPlay' without having called 'userInput'? That would do it (unless you initialized totalInput to equal 0, which you should have). This code can definately be cleaned up. You should look into parameters. Global variables are a bad way to go. Check out the Turing Walkthrough for a link to the tutorial on procedures and functions or check out the Turing Help file under 'prcoedure', 'function', and 'param...' randomperson#5 wrote: if x = 0 then notes (i) := "1" elsif x = 30 then notes (i) := "2"........... (continues) Do you see a pattern here? There's no need to have a giant if structure for this. Even if you did need to do it with conditionals like this, you'd use a case statement. But we can still do better. Try this:
'ceil' is a function that rounds up to the nearest integer. But that's not quite right, is it. That's assigned an integer to 'notes (i)'. We want to give it a string. Easy enough: we can type cast it, using 'intstr'.
|
Author: | Clayton [ Sun Jun 11, 2006 11:18 am ] |
Post subject: | |
or if you dont understand where that came from you could use some kind of a nested for loop, also, i think that maybe one of your if conditions is wrong, so if one of them doesnt work (mainly the ones that give the variables values) then the variables dont get a value and your processPlay is called with no value to the variables |