Results 1 to 3 of 3

Thread: Keeping text the same after case changes.

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    1

    Keeping text the same after case changes.

    What happens here is when I click on anyone of the radio buttons the text box score sets the value to either 0,1,2,3,4 but when I go the next
    case it goes back to 0 instead of keeping the value. I tried many different techniques while going about this none seem to work.

    Private Sub btnNextQuestion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextQuestion.Click
    Static questionCount As Integer
    Select Case questionCount
    Case 0
    'Question 1
    radAlways.Visible = True
    radUsually.Visible = True
    radSometimes.Visible = True
    radSeldom.Visible = True
    radNever.Visible = True
    lblQuestion.Text = "I can easily recognize practical needs" + vbCrLf + "and I am quick to meet them"
    lblQuestion.Font = New System.Drawing.Font("Seguoe UI", 10)
    lblQuestionsLeft.Text = "1 / 175"
    Case 1
    'Question 2
    radAlways.Checked = False
    radUsually.Checked = False
    radSometimes.Checked = False
    radSeldom.Checked = False
    radNever.Checked = False
    lblQuestion.Text = "I give to support and bless others or to" + vbCrLf + "advance an effective cause or vision"
    lblQuestionsLeft.Text = "2 / 175"
    Private Sub radAlways_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radAlways.CheckedChanged
    Static score As Integer
    txtScore.Text = score + 4
    End Sub
    Private Sub radUsually_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radUsually.CheckedChanged
    Static score As Integer
    txtScore.Text = score + 3
    End Sub
    Private Sub radSometimes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radSometimes.CheckedChanged
    Static Score As Integer
    txtScore.Text = Score + 2
    End Sub
    Private Sub radSeldom_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radSeldom.CheckedChanged
    Static score As Integer
    txtScore.Text = score + 1
    End Sub
    Private Sub radNever_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radNever.CheckedChanged
    Static score As Integer
    txtScore.Text = score + 0
    End Sub

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Keeping text the same after case changes.

    As far as score variable is shared between many procedures then you must declare it as module level variable.

    Add this line at the top of your form code Private score As Integer (just below Public Class Form1) and remove Static Score As Integer from all procedures.



  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Keeping text the same after case changes.

    Welcome to the VBForums. Let me give you a little tip:
    Please, use the [code] and the [/code] tags around your source code so that it gets formatted correctly. Many people in here will simply refuse to help you because it's to hard to read unformatted source code.

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