Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB program flow, forgot how to get it going

Posted on 2009-07-15
3
Medium Priority
?
180 Views
Last Modified: 2012-05-07
Hi all,

It's been a really long time since I've done VB and I was never any good at it.

I'm trying to write a simple program with two buttons and a label. The two buttons are Yes and No. The label will ask a question.

I'm having trouble getting it to flow, for example:

Are you over 21? User clicks Yes.
Are you a male? User clicks No.
Is your name Jane? User clicks Yes.
etc.

I have some code below that doesn't work at all. I forget what I'm missing in order for this to work, obviously calling the MainFlow sub would be a start but I can't even remember how to do that or if that's possible in VB. Maybe I'm mixing up my languages, I don't know!

I had it working with out the MainFlow sub but after 1 click it would just stop working.



Thanks,
Primus
Public Class Form1
 
    Dim BtnOne As Boolean = False
 
    Dim BtnTwo As Boolean = False
 
    Declare Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)
 
 
    Public Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
 
        BtnOne = True
 
    End Sub
 
    Public Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
 
        BtnTwo = True
 
    End Sub
 
    Public Sub MainFlow()
 
        If BtnOne = True Then
 
            lbl1.Text = "Are you a male?"
 
            BtnOne = False
 
            If BtnOne = True Then
 
                lbl1.Text = "Is your name Jane?"
 
            End If
 
        ElseIf BtnTwo = True Then
 
            lbl1.Text = "Alright, then you can't continue"
 
            Sleep(5000)
 
            End
 
        End If
 
    End Sub
 
End Class

Open in new window

0
Comment
Question by:PrimusPilus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Assisted Solution

by:3_S
3_S earned 800 total points
ID: 24861001
You can use a msgbox to ask the 3 questions


 
     
    Dim age As Integer
    age = MsgBox("Are you over 21?", vbYesNo, "Age")
    
    If age = vbYes Then
        ...
    Else
        ...
    End If

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1200 total points
ID: 24862855
Create a New Project with lblQuestion, btnYes and btnNo:
Public Class Form1
 
    Private Class Prompt
        Public Question As String
        Public CorrectAnswer As Boolean
    End Class
 
    Private CurrentPrompt As Prompt
    Private Prompts As New List(Of Prompt)
    Private PromptEnumerator As System.Collections.Generic.List(Of Prompt).Enumerator
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Prompts.Add(New Prompt() With {.Question = "Are you over 21?", .CorrectAnswer = True})
        Prompts.Add(New Prompt() With {.Question = "Are you a male?", .CorrectAnswer = False})
        Prompts.Add(New Prompt() With {.Question = "Is your name Jane?", .CorrectAnswer = True})
        PromptEnumerator = Prompts.GetEnumerator
        NextPrompt()
    End Sub
 
    Private Sub NextPrompt()
        If PromptEnumerator.MoveNext Then
            CurrentPrompt = PromptEnumerator.Current
            Label1.Text = CurrentPrompt.Question
        Else
            MessageBox.Show("You Passed!")
        End If
    End Sub
 
    Private Sub CheckAnswer(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnYes.Click, btnNo.Click
        Dim Answer As Boolean = (sender Is btnYes)
        If Answer = CurrentPrompt.CorrectAnswer Then
            NextPrompt()
        Else
            Me.Close()
        End If
    End Sub
 
End Class

Open in new window

0
 

Author Closing Comment

by:PrimusPilus
ID: 31603814
Thanks guys,

That works out great!

Primus
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question