Results 1 to 8 of 8

Thread: Assistance with "Next" logic

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Assistance with "Next" logic

    This isn't too hard to grasp, but I'm not usually very good at explaining things

    When the User launches the application, they'll hit "Next" to go to the next form. This second form allows the User to choose between 5 additional forms. If the user opts in for all 4, I'll just go to each form when appropriate.

    For example:

    Next: Form1, Next: Form2, Next: Form3, Next: Form4.

    That's about as easy and straight forward as it gets. The issue, is that I have no idea, without writing a bunch of spaghetti code, to launch each form when each one is selected.

    I've set up variables to determine which form is selected, but that only helps so much.

    Let's say the User select form's 1,3, and 4. I've set up a nested conditional logic statement to check if the first variable is true. If it is, the we launch the form, move on and do all of the check again.

    I could do this in every "Next" button, but it seems sloppy and might get confusing. Also, I'd need to set the variable to false after launching so that the checks aren't messed up in every other form. That causes an issue when the User wants to go back.

    This might not be the best explanation, so if need be, I can provide a visual or code example, just to get an idea of what I'm saying.

    Any information is appreciated.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Assistance with "Next" logic

    What programming language are you working in?

    Some pictures and code would be helpful.

  3. #3

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Assistance with "Next" logic

    It's in VB .NET, but I figured the language was irrelevant for this section, since it's solely logic that I'm having an issue with.

    But, here's a quick example:

    VB.NET Code:
    1. Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
    2.         If UninstallManager = True Then
    3.             ChangePageForward(1)
    4.         Else
    5.             If ShortcutManager = True Then
    6.  
    7.             Else
    8.                 If InstallCriticalWindowsUpdates = True Then
    9.  
    10.                 Else
    11.                     If InstallOptionalWindowsUpdates = True Then
    12.  
    13.                     Else
    14.                         If TechTweaks = True Then
    15.  
    16.                         Else
    17.                             MessageBox.Show("Please select a task to begin", "No task selected...", MessageBoxButtons.OK, MessageBoxIcon.Information)
    18.                         End If
    19.                     End If
    20.                 End If
    21.             End If
    22.         End If
    23.     End Sub

    I check if the first variable is True. If it is, I move to the next form and then run, basically, that same nested logic over again. I skip the first form of course, since it's already been launched.

    This seems to work just fine. But, on the consecutive forms, how do I determine which form has already been launched? So that I don't attempt to launch it again. And then I need to figure out how to go backwards. I could of course, just set the launched form's variables to False, but that would screw things up when trying to go backwards, then forwards again.

    If the user didn't have to select the options, then it would be cake.

    Does this help clarify what I mean?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Assistance with "Next" logic

    First idea that comes to mind is to create a Public (in a Module, but I'm talking VB6 here, might be a bit different in .Net) array of booelans that would correspond to forms you need to show. For example you have five forms, array(0) is for Form1, array(1) Form2 and so on.

    At the beginning set the True/False values for each form you want to show, then when launching them, simply set the array value to False. The next time the code goes through the array it will skip that form because you set it to False.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Assistance with "Next" logic

    I would use a variable to say which form is currently active, then extend the If's like this:
    Code:
            If UninstallManager = True And CurrentForm = 1 Then
                ChangePageForward(1)
            Else
                If ShortcutManager = True And CurrentForm = 2 Then

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Assistance with "Next" logic

    Personally I wouldn't have used multiple forms... but that's just me...

    I would have put (and I realize that the designing is already done, so it may not be feasable to go back and try this... but I'm offering my 2centavos anyways... ) everything into panels or tab pages... then loaded them into a list or dictionary... use an index, or some kind of indicator to keep track of the currently displayed element... then there's one set of controls for navigation, which should make it easier to move between the different steps, in any order. If you wanted to take it far enough, when loading the list or dictionary... you could simply just load the frames/panels/tabs that the user has selected, ignoring the others...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Assistance with "Next" logic

    Back in 2003, when all programs started with Sub Main, I tended to write code into Main that looked a bit like this:
    Code:
    'As a global variable
    Public TheState as Integer
    
    'In the sub
    Do While TheState <> 0
     Ladder
    Loop
    
    Public Sub Ladder
     Select Case TheState
      Case 1   
       form1.ShowDialog
      Case 2
       form2.ShowDialog
     End Select
    End Sub
    That gives you the idea. It's a state machine. There was one near perpetual loop that called a sub which switched on the state variable to select which form to show. When a form closed, all it had to do was set TheState to the next form that needed to be shown, then close. That caused ShowDialog to return, which caused Ladder to return, and the loop ran a second time, showing the next form.

    I have used this in mobile apps, and wizard style apps, but it's standard state machine stuff. Each form gets shown, and when it comes time to close, it need only set the state for the next form to be shown.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Assistance with "Next" logic

    Quote Originally Posted by techgnome View Post
    Personally I wouldn't have used multiple forms... but that's just me...

    I would have put (and I realize that the designing is already done, so it may not be feasable to go back and try this... but I'm offering my 2centavos anyways... ) everything into panels or tab pages... then loaded them into a list or dictionary... use an index, or some kind of indicator to keep track of the currently displayed element... then there's one set of controls for navigation, which should make it easier to move between the different steps, in any order. If you wanted to take it far enough, when loading the list or dictionary... you could simply just load the frames/panels/tabs that the user has selected, ignoring the others...

    -tg
    I agree. And I may end up going to that. However, using form's allows me to be a bit more organized. Otherwise, I'll need to create a component that allows me to do everything during design time. I think someone, maybe Nick, created a control like this. I could maybe just modify that.

    Thanks for the info, guys
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

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