CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    2

    Smile 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

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  3. #3
    Join Date
    Sep 2010
    Posts
    2

    Smile 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
  •  





Click Here to Expand Forum to Full Width

Featured