Assigning a value to radio buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpmcafee
    New Member
    • Apr 2007
    • 22

    #1

    Assigning a value to radio buttons

    Hi Guys,
    Iam new to vb2005 and programming and I could really use some help. I have finished my book on vb2005 and i cant find what I am looking for,

    Essentially I want to create a form with 3 columns, down each of these colums will be about 20 radio buttons. I need to assign a value to each radio button such as( -4 thur +4) at the bottom of each column I need it to add them up for a final score. Any advice would be great!

    Thanks in advance
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by jpmcafee
    Hi Guys,
    Iam new to vb2005 and programming and I could really use some help. I have finished my book on vb2005 and i cant find what I am looking for,

    Essentially I want to create a form with 3 columns, down each of these colums will be about 20 radio buttons. I need to assign a value to each radio button such as( -4 thur +4) at the bottom of each column I need it to add them up for a final score. Any advice would be great!

    Thanks in advance
    Greetings and salutations, jpmcafee!

    I am not familiar with VB Express just yet. I did pick up this link for you. See what it does:

    Beginning Visual Basic 2005 Express Edition is the affordable, accessible route to learning the .NET programming languages. Author Peter Wright proved his ability to teach Visual Basic to over 100,000 aspiring programmers during the 1990s with his line of best–sellers. Now that Microsoft is launching its new Express products, Wright is repeating his mission to teach you how to program, providing a friendly, clear message along the way.Wright helps you explore Visual Basic 2005 Express. You’ll learn about core programming principles that will enable you to move towards more complex and rewarding programming tasks. This book guides you through every major aspect of Visual Basic 2005 Express, and guarantees that you’ll learn how everything fits together—from the first programming principles to Express Start Kits that advance you in your own programming. By the end of the book, you’ll be able to write your own programs.


    Good luck with the project!

    Dököll

    Comment

    • jpmcafee
      New Member
      • Apr 2007
      • 22

      #3
      Bump,
      Anyone other advice?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        What have you attempted so far? Which part of it is giving you trouble?

        (Don't be too impatient, we're all in different timezones and only volunteering when we can spare the time.)

        Comment

        • jpmcafee
          New Member
          • Apr 2007
          • 22

          #5
          To be honest the whole concept is driving me nuts. I can use vb2005 to draw the radios; I just need to be able to assign the value to it and add it up at the bottom.and I have no clue how to do this. Iam not a student just a dabler so to say. But what i am trying to accomplish is to have 4 verticle rows of radio buttons(approx 30 radios in each row) each will have its own question. I would like to be able to assign them a number value of -4 through +4 depending on there importance and then have it add up each row at the bottom.

          Any help would be great.

          Comment

          • Dököll
            Recognized Expert Top Contributor
            • Nov 2006
            • 2379

            #6
            Originally posted by jpmcafee
            To be honest the whole concept is driving me nuts. I can use vb2005 to draw the radios; I just need to be able to assign the value to it and add it up at the bottom.and I have no clue how to do this. Iam not a student just a dabler so to say. But what i am trying to accomplish is to have 4 verticle rows of radio buttons(approx 30 radios in each row) each will have its own question. I would like to be able to assign them a number value of -4 through +4 depending on there importance and then have it add up each row at the bottom.

            Any help would be great.
            It looks like it should work, have you read the information included?

            If you remove references to checkboxes in the code (there's actually a bit of code included), you should be golden.

            If all else fails, build a pseudocode to have an idea what you need to achieve...I'll just bet a light should come on eventually. You'll get it, no worries:-)

            In a bit!

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by jpmcafee
              To be honest the whole concept is driving me nuts. I can use vb2005 to draw the radios; I just need to be able to assign the value to it and add it up at the bottom.and I have no clue how to do this. Iam not a student just a dabler so to say. But what i am trying to accomplish is to have 4 verticle rows of radio buttons(approx 30 radios in each row) each will have its own question. I would like to be able to assign them a number value of -4 through +4 depending on there importance and then have it add up each row at the bottom.
              This sounds like a job for checkboxes rather than radio buttons. The idea of radio buttons is to allow you to choose one out of a set of options. If you want each item to be selected or de-selected individually, you're talking about checkboxes.

              If you want each column to allow one item to be selected (which would be a job for radio buttons) then you should be able to achieve it by placing each column of radio buttons into a separate container, such as a frame.

              Comment

              • Dököll
                Recognized Expert Top Contributor
                • Nov 2006
                • 2379

                #8
                Originally posted by Killer42
                This sounds like a job for checkboxes rather than radio buttons. The idea of radio buttons is to allow you to choose one out of a set of options. If you want each item to be selected or de-selected individually, you're talking about checkboxes.

                If you want each column to allow one item to be selected (which would be a job for radio buttons) then you should be able to achieve it by placing each column of radio buttons into a separate container, such as a frame.
                That's not a bad idea at all. I'll start with radio button's first. Here's a quick step, pretty basic:

                Form

                Code:
                If Option1 = True Then 'first button on frame on its own
                    MinusOne = 1 'you are adding value to this button
                ElseIf Option2 = True Then 'second button on frame on its own
                    PlusOne = 2 'you are adding value to this button
                End If
                
                
                If MinusOne = 1 Then
                    you can make somehting happen here for - value...
                ElseIf PlusOne = 2
                    do somehting else here specific to + value...
                End If
                
                
                
                End Sub
                I do not see why VB 2005 would be too far from this. Again, checkboxes should be the choice here if you have a number instances. Above code can be modified to use checkboxes instead while ignoring the frames.

                Comment

                • SammyB
                  Recognized Expert Contributor
                  • Mar 2007
                  • 807

                  #9
                  Originally posted by jpmcafee
                  Hi Guys,
                  Iam new to vb2005 and programming and I could really use some help. I have finished my book on vb2005 and i cant find what I am looking for,

                  Essentially I want to create a form with 3 columns, down each of these colums will be about 20 radio buttons. I need to assign a value to each radio button such as( -4 thur +4) at the bottom of each column I need it to add them up for a final score. Any advice would be great!

                  Thanks in advance
                  This is easy and quick to do. Since you are a novice, just follow these instructions exactly and after it works, do it again like you want it. Since this is just a demo, we are going to keep it simple: two columns of four checkboxes (as Killer said, use checkboxes) with two textboxes at the bottom for the sum:
                  1. Create a new VB windows app
                  2. Add eight CheckBox controls to the form and arrange them into two columns.
                  3. Add a textbox at the bottom of each column.
                  4. Change the names of the controls in the first column to A1, A2, A3, A4. The numbers are not important, the code will only look at the first letter.
                  5. Change the names of the controls in the first column to B1, B2, B3, B4
                  6. We will keep the "value" of each textbox in the Tap property and to make sure that it is working, we will use the same number in the Text property. We will not use the Text property in the code, so in the actual app, you can make the text whatever you want.
                  7. So, change the Tag and Text property of each control. You can keep it simple, 1 , 2, 3, 4, or use any numbers you want. Just make sure that for a single control, the Text & Tag property are the same.
                  8. Using the mouse, lasso all of the checkboxes so that they are all selected. Do not select the Textboxes. If lassoing is difficult for you, just click on the first and Ctrl-click on the rest.
                  9. After all of the Checkboxes are selected, in the Properties window, click on the lightning bolt, so that events are shown.
                  10. Double-click on the CheckedChanged text. That will setup a single event for all of the checkboxes.
                  11. Add code:
                  Code:
                  	Private Sub B4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B4.CheckedChanged, B3.CheckedChanged, B2.CheckedChanged, B1.CheckedChanged, A4.CheckedChanged, A3.CheckedChanged, A2.CheckedChanged, A1.CheckedChanged
                  		Dim s1 As Integer = 0, s2 As Integer = 0
                  		For Each c As Control In Me.Controls
                  			If TypeOf c Is CheckBox Then
                  				Dim chk As CheckBox = c
                  				If chk.Checked Then
                  					If chk.Name.StartsWith("A") Then
                  						s1 += chk.Tag
                  					ElseIf chk.Name.StartsWith("B") Then
                  						s2 += chk.Tag
                  					End If
                  				End If
                  			End If
                  		Next c
                  		TextBox1.Text = s1.ToString()
                  		TextBox2.Text = s2.ToString()
                  	End Sub
                  The pseudocode would be:
                  Code:
                  Whenever a checkbox is checked or unchecked:
                  init the sums to zero
                  For every control on the form:
                  If the control is a checkbox and the checkbox is checked then
                  	 If the checkbox's name starts with A, then add its Tab to the first sum
                  	 If the checkbox's name starts with B, then add its Tab to the 2nd sum
                  After looping thru all of the controls, put the sums in the TextBoxes

                  Comment

                  • jpmcafee
                    New Member
                    • Apr 2007
                    • 22

                    #10
                    What is the pseudocode? and where would it go if anywhere... Again thank you all for your help.

                    Comment

                    • SammyB
                      Recognized Expert Contributor
                      • Mar 2007
                      • 807

                      #11
                      Originally posted by jpmcafee
                      What is the pseudocode? and where would it go if anywhere... Again thank you all for your help.
                      :D the pseudocode is just to help you understand the actual code so that you can change it to do what you want.

                      Comment

                      • jpmcafee
                        New Member
                        • Apr 2007
                        • 22

                        #12
                        Can I say idot Gosh...... Thank you I guess I sound Stupid...

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #13
                          Originally posted by jpmcafee
                          Can I say idot Gosh...... Thank you I guess I sound Stupid...
                          I'd say you sound like someone who hasn't done this before. :)

                          Experience is what makes the difference. In a couple of years you'll probably laugh at anyone who suggests you ever had trouble with this.

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #14
                            Originally posted by SammyB
                            ...follow these instructions exactly and after it works ...
                            Isn't it great to see such confidence? :D

                            Comment

                            • jpmcafee
                              New Member
                              • Apr 2007
                              • 22

                              #15
                              Thats Awesome..... Tell Me somthing it is possible to have a combo box or sometype of drop down boxes with choices that have values assigned (along the same lines as this?. I was thinking it would save space on the form. So another words in a label I could ask a question. In the drop down they could select the right answer and then have it add up at the end.

                              Instead of having a check box for each answer? Thanks Again

                              Comment

                              Working...