|
-
September 24th, 2010, 06:13 AM
#1
FOR LOOP dilemma
Hello everyone...im having problem with for loop---
Im making a simple hangaroo type game, everything works fine except for the validation, (where an x appears every wrong entry) heres my code:
----------------------------------------------------
For intX = 0 To UBound(strArr)
If lblhiddenchar(intX).Caption = cmdLetterPool(Index).Caption Then
lblhiddenchar(intX).Visible = True
'show the caption if the letter pressed is correct
Else
wrongGuess
'invokes a procedure to add an "X"
End If
Next intX
-------------------------------------------------------
Private Sub wrongGuess()
errorCount = errorCount + 1
Select Case errorCount
Case 1
imgX.Visible = True
Case 2
imgX2.Visible = True
Case 3
imgX3.Visible = True
Case 4
imgX4.Visible = True
Case 5
imgX5.Visible = True
MsgBox "Watch as this one validates.."
Unload Me
End Select
End Sub
-------------------------------
now, the problem is that when i click a wrong letter for the 1st time, it instantly unloads the form( case 5)..ive tried the exit for, but im still having problems..im new to visual basic, so any ideas?? any reply would be so helpful...thanks a lot
-
September 24th, 2010, 08:30 AM
#2
Re: FOR LOOP dilemma
If you are looking to see if a letter choosen is in the hidden word then you should really be using INSTR() rather than a loop.
Not enough code shown to really know what is going on but my guess would be that the loop is causing the x to add the number of times as there are elements in the array. It also looks like it could bomb on correct letters.
Use INSTR() and you should be fine.
Always use [code][/code] tags when posting code.
-
September 24th, 2010, 09:30 AM
#3
Re: FOR LOOP dilemma
@datamiser:
thanks for the help..i've got it working now..Ciao..
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|