CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2013
    Posts
    5

    how to break For...next Statement loop

    hello guys please help me to get out of this problem
    im making quiz project but im stuck for loop
    example(i have 60 array form loop.. i i can't stop the loop if the user get 5 wrong or get 40 correct..

    here is the sample code
    Code:
     
    intNumberOfForms = 40
    
        frmQuizArray = Shuffle(intNumberOfForms - 1)
        
        For i = 0 To intNumberOfForms - 1
             
            Set frmQuiz = Forms.Add("frmQuiz" & frmQuizArrArray(i))
            frm.Show vbModal
            Set frm = Nothing
        Next i
    i want to break it or insert this code but does not work.. sorry im realy noob

    Code:
    If quiz.markWrong = 5 then
                 formfail.show
             elseif quiz.markCheck  = 40 then
                  formpassed.show
             else
                  quiz.markWrong = quiz.markWrong
                   quiz.markCheck = quiz.markCheck
    End if

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: how to break For...next Statement loop

    Use a Exit For when you want to exit the for loop... so like this..

    Code:
    intNumberOfForms = 40
    
        frmQuizArray = Shuffle(intNumberOfForms - 1)
        
        For i = 0 To intNumberOfForms - 1
             
            Set frmQuiz = Forms.Add("frmQuiz" & frmQuizArrArray(i))
            frm.Show vbModal
            Set frm = Nothing
    
            If quiz.markWrong = 5 then
                 formfail.show
                 Exit For
             elseif quiz.markCheck  = 40 then
                  formpassed.show
                  Exit For
             End if
        Next i
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Nov 2013
    Posts
    5

    Re: how to break For...next Statement loop

    Quote Originally Posted by GremlinSA View Post
    Use a Exit For when you want to exit the for loop... so like this..

    Code:
    intNumberOfForms = 40
    
        frmQuizArray = Shuffle(intNumberOfForms - 1)
        
        For i = 0 To intNumberOfForms - 1
             
            Set frmQuiz = Forms.Add("frmQuiz" & frmQuizArrArray(i))
            frm.Show vbModal
            Set frm = Nothing
    
            If quiz.markWrong = 5 then
                 formfail.show
                 Exit For
             elseif quiz.markCheck  = 40 then
                  formpassed.show
                  Exit For
             End if
        Next i
    sir thanks i try my best to understand it.. its working but sometimes its showing a debug. (object unloaded) did i mistaken using if.. else.. statement methods

  4. #4
    Join Date
    May 2005
    Location
    Sterling Heights, MI
    Posts
    74

    Re: how to break For...next Statement loop

    On what line do you get the error, and under what conditions?

  5. #5
    Join Date
    May 2005
    Location
    Sterling Heights, MI
    Posts
    74

    Re: how to break For...next Statement loop

    And you should not be using one form for each question. Place all 40 questions on one form and I think your results will be easier to accomplish and the people taking this quiz will be less likely to get lost in the forms.

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