|
-
Apr 9th, 2010, 10:31 AM
#1
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
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Apr 9th, 2010, 10:41 AM
#2
Re: Assistance with "Next" logic
What programming language are you working in?
Some pictures and code would be helpful.
-
Apr 9th, 2010, 10:49 AM
#3
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:
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If UninstallManager = True Then
ChangePageForward(1)
Else
If ShortcutManager = True Then
Else
If InstallCriticalWindowsUpdates = True Then
Else
If InstallOptionalWindowsUpdates = True Then
Else
If TechTweaks = True Then
Else
MessageBox.Show("Please select a task to begin", "No task selected...", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
End If
End If
End If
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
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Apr 9th, 2010, 10:58 AM
#4
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.
-
Apr 9th, 2010, 10:59 AM
#5
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
-
Apr 9th, 2010, 01:45 PM
#6
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
-
Apr 9th, 2010, 02:05 PM
#7
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
 
-
Apr 10th, 2010, 10:39 AM
#8
Re: Assistance with "Next" logic
 Originally Posted by techgnome
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
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|