VB.NET - Using one button to respond/answer multiple questions

I'm still learning my VB.NET and this is something I have not yet had a need for.

I need to have a form that works as a translator. The visitor first selects a country flag as a chosen language and will then be guided through a series of questions. They would answer these questions with Yes, No, or a choice.
The difficulty is that I want the Yes and No buttons to be used multiple times to respond to a series of questions. In other words I dont want to have to create multiple Yes/No buttons.

Is there a way to assign a button to have multiple events?
This is the code so far:
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        btnYes.Hide()
        btnNo.Hide()
        btnReset.Hide()
    End Sub
    ' #####################################################################################
    ' ################                       ROMANIAN                    ##################
    ' #####################################################################################
    Private Sub btnRomania_Click(sender As Object, e As EventArgs) Handles btnRomania.Click
        Dim language As String = "Romanian"
        btnYes.Show()
        btnYes.Text = "da"
        btnNo.Show()
        btnNo.Text = "nu"
        btnReset.Show()
        btnReset.Text = "incepe din nou"
        lblLanguage.Text = "Language selected: " & language
        '1st Question - You have selected Romanian. Is this correct?
        txtQuestion.Text = "Ați selectat române ca limba . Este corect ?" '"ai actele ta ?"
        If btnYes = btnYes.Select() Then

        End If
    End Sub
    Private Sub btnYes_Click(sender As Object, e As EventArgs) Handles btnYes.Click

    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        btnYes.Hide()
        btnNo.Hide()
        btnReset.Hide()
        lblLanguage.Text = "Language selected: "
    End Sub


End Class

Open in new window

LVL 2
fruitloopyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
I would create a user control first.

Then it depends on how the user should see or navigate through the questions. Should he see all questions at once or should it be like a wizard, one single question at a time?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>Is there a way to assign a button to have multiple events?

each button would only has one click event, so to diversify and differentiate the possible actions within, you need to have a "select case" statement within your click event, so that the scripts know how to react based on your selection.

do you think this make sense to you?
fruitloopyAuthor Commented:
Ste5an - He would see each question one at a time. My intention is that based on the response the txtQuestion filed will then display the next question.

Ryan - Yes it makes sense but I'm not familiar with this type of code. Can you point me to any examples or help me get started please?
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
what i was initially suggested would be an easy approach, so probably you can try like:

Private Sub btnYes_Click(sender As Object, e As EventArgs) Handles btnYes.Click
      Select Case currentIndex
      Case 1:
              'show next question...
      Case 2:
              'show next question...
      Case 3:
              'show next question...
      End Select
End Sub

Private Sub btnNo_Click(sender As Object, e As EventArgs) Handles btnNo.Click
      Select Case currentIndex
      Case 1:
              'show next question...
      Case 2:
              'show next question...
      Case 3:
              'show next question...
      End Select
End Sub

Private Sub btnSkip_Click(sender As Object, e As EventArgs) Handles btnSkip.Click
      Select Case currentIndex
      Case 1:
              'show next question...
      Case 2:
              'show next question...
      Case 3:
              'show next question...
      End Select
End Sub

Open in new window


IF you need a more robust solution..

It would be better if we can make dynamic comparison within the click event, meaning to say, once the question is being answered (user clicked the button), the current question index with the answer (user's selection) will be passed to a backend repository for comparison, and provide the next question, like..

Private Sub btnYes_Click(sender As Object, e As EventArgs) Handles btnYes.Click
      Call getNextQuestion('Yes', currentIndex)
End Sub

Private Sub btnNo_Click(sender As Object, e As EventArgs) Handles btnNo.Click
      Call getNextQuestion('No', currentIndex)
End Sub

Private Sub btnSkip_Click(sender As Object, e As EventArgs) Handles btnSkip.Click
      Call getNextQuestion('Skip', currentIndex)
End Sub

Open in new window


Then in the sub getNextQuestion, we will need to put question selection logic there...

The backend repository could be in any format, like a database, XML, text file.

hope this illustration gives you some ideas how to progress next.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
>>The difficulty is that I want the Yes and No buttons to be used multiple times to respond to a series of questions. In other words I dont want to have to create multiple Yes/No buttons.

Buttons have ONLY one click event.
What you want is possible as you see from the previous comments but it makes things a lot more complex.  It is simpler to have a button on each page you display to handle the question on that one page.  It is simpler for you to code and it is simpler for someone to maintain that code at a later date.

(Would it make sense for you to have only one light switch in your house to turn lights on and off in the other rooms?  Think of the wiring involved in that.)
ste5anSenior DeveloperCommented:
As you're still learning it:

How do you store your questions? How do you want to store the users answers?
fruitloopyAuthor Commented:
Thanks Ryan. Much appreciate the code to get me started.

Ste5an - No, I have no need to store the responses but it would be useful to have all questions in all languages in a back-end database or XML file as suggested

AndyAinscow - You've got a good point. That same question would have to be asked in multiple languages, perhaps as many as 18 (its a transport area which receives deliveries from international lorry drivers) so maintaining that level of complexity would be huge.

My immediate thoughts are to have a front end to select the language and after selection it opens another form with questions on their chosen language with questions. How would you handle each question after the Yes/No/Skip button? How would you move to the next question?
AndyAinscowFreelance programmer / ConsultantCommented:
The display language is one thing, the code and events another separate thing altogether (display language independent).
ste5anSenior DeveloperCommented:
The language selection means to present only the questions in those language or do you need to adjust the UI language also?

The problem is also software architecture.. what kind of solution do you want to build?

I would start with creating my classes for the questions and answers. Then I would build a user control which can be feed with a question to show it in the UI.
louisfrCommented:
You can change the code called on the Click event using the RemoveHandler and AddHandler statements: https://msdn.microsoft.com/en-us/library/7taxzxka.aspx
fruitloopyAuthor Commented:
I selected both you guys as you came up with constructive answers. Thanks for all other responses though.

I intend to ask this as another question more along the lines of "How should I go about building this application" as it is not something I have done before.

Thanks again
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.