## Crashing Higher Computing?

### Dave

Posted 22 January 2007 - 05:09 PM

if you look at my example again you will see i have a counter variable called "x" this is what does the picking of the elements in the array

What you have written is saying "for the whole array data structure equalling 0-9 do all this other stuff"

So that is wrong you want to have For counter =0 to 9 instead there

The next problem is this line

Do while valid <> guest()

You are trying to compare a String with a Array object so you will get a data type mismatch you need to compare the variable valid with each element in the array

valid = InputBox("Ur name?")
Integer counter = 0

Do while valid <> guest(counter) OR counter<10
valid = InputBox("re-enter ur name")
loop

Just to confuse you i would do the cook like above read it and see if you understand that look at how the array is being used and the use of OR

### verticalforce

Posted 22 January 2007 - 05:33 PM

Tell me if I understand this correctly:

valid = InputBox("Ur name?")
Integer counter = 0

Do while valid <> guest(counter) OR counter<10
valid = InputBox("re-enter ur name")
loop

The integer counter is set to 0 to properly intialise it at first? Since there is 9 guests, the counter is put as <10?

Why is it OR and not AND.. hmmm...

Do I have to do this whenever I loop an array?

DAMMIT lol... having a teacher who can't teach vb and don't even know vb is depressing... (he can only do BASIC and our coursework is coming shortly and we haven't revised vb for months!)

### verticalforce

Posted 22 January 2007 - 05:47 PM

I tried the code but got caught in the loop of death..it just kept looping at the same part although i've inputted the correct answer..

arghh...

### Dave

Posted 22 January 2007 - 05:52 PM

yeh tht is why you have the infinite loop is cos o my error you should use AND

### verticalforce

Posted 22 January 2007 - 06:02 PM

Thanks. It works... Lol.. that piece of programming took me ages to do and I am not even 1/20 through the program yet....

Don't worry, the code that I gave doesn't even look remotely like the coursework, only the steps are similar...

EDIT: The program works but it will only accept the first value after I retry it.. maybe this had to to with the counter = 0?

### verticalforce

Posted 22 January 2007 - 06:14 PM

room = InputBox("Choose a room")

Do While room < 1 Or room > 5 Or room = 3
room = InputBox("The selection might have been out of range. (Note: Room 3 is booked)")
Loop

ok, what I am trying to do here is to notify the users that room <1 or >5 is out of range and that room 3 is booked. How do I seperate these 2 things? Is it possible to do a loop in a loop? (hope this makes sense)

I am suppose to show that a room is reserved and another selection has to be made. Do I create the scenario myself or is there a proper way to do it?

### st-and Paul

Posted 22 January 2007 - 09:57 PM

It is possible to do nested loops but this makes the algorithm less efficient, avoid it if you can!

It makes more sense to loop only when the conditions arent met, so you want to do something like:

if(room > 1 && room <5)
if(room == 3) (note this double equals is just a personal thing i use in psuedocode so as not to confuse it with assignment)
print "room booked choose another"

Edit: Just ignore this, someone delete it please.

### verticalforce

Posted 23 January 2007 - 05:14 PM

Thanks for all of your help. I think I know enough to start my coursework now.

Thanks again.