Results 1 to 7 of 7

Thread: Visual Basic 2010 HELP

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    6

    Visual Basic 2010 HELP

    Ok this might be confusing as I dont know how to explain.

    I'm doing a quiz and am using radio buttons. On a seperate form is a results page with a label which I want the results to show up on. I have made the label public.

    The label should start with zero. There are three questions, each correct question should add a point to the result label.

    I have no idea what I am doing!

    So far I have done:

    Dim lblResult1 As Integer

    If rbtnAnswer1_1_1.Checked = True Then
    lblResult1.Text =

    Can anyone help?

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Visual Basic 2010 HELP

    Hi,

    Try this:

    vb Code:
    1. If rbtnAnswer1_1_1.Checked = True Then
    2. lblResult1.Text =  lblResult1.Text +1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    6

    Re: Visual Basic 2010 HELP

    Cheers, just tryed it. It doesnt work, suggest that lblResult1.Text is not right. but I dont know what to put instead.
    I tried:

    Dim lblResult1 As Integer = 0

    If rbtnAnswer1_1_1.Checked = True Then
    lblResult1 = lblResult1 + 1
    End If

    but this still didnt work

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Visual Basic 2010 HELP

    Hi,

    Try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim lblResult1 As Integer = 0
    4.               If rbtnAnswer1_1_1.Checked = True Then
    5.             lblResult1.Text = lblResult1.Text + lblResult1 + 1
    6.         End If
    7.     End Sub
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Visual Basic 2010 HELP

    You need to give more information then just "it didn't work". Please read the link in my signature on how to create a post that gives you the best chance of getting a good response. Note the title of the thread should not be HELP as it is understood you need help, you are asking a question!

    Now, to your problem. You should know you have a fault, as VS should underline the code in question and tell you what the problem is. Ensure you have Option Strict/Option Explict turned on, they will also tell you of fault that are obvious once you see them.

    I will give you an example of why your code would not work. You want a car to go at 100 mph, so you say

    Code:
    Car = 100
    Of course, this will not work, you are telling the car that is it 100, what you want to tell the car, is to change its speed to 100. So this would be more approriate.

    Code:
    Car.Speed = 100
    You need to tell the object, which property you want to change. Using this on your code above you would get:

    Code:
    lblResult1.Text = lblResult1.Text + 1
    In theory, this would work, except that you are adding 1, a number, to a text value which is a string. What would happen if you did this

    Code:
    "hello 2" + 1
    Do you get "hello 21" or should it be "3" or should it be something else? That is what the options are for, to tell you that you could get the wrong answer as you have not been explicit enough. The simple way to solve this, is to change the value in the label into a number.

    Code:
    lblResult1.Text = Val(lblResult1.Text) + 1
    So now you are almost there. But... The value that comes out of the equation is a number, and again, you are trying to put it back into text! So a final piece should be used.

    Code:
    lblResult1.Text = (Val(lblResult1.Text) + 1).ToString
    Convert the existing .Text value to a number, add 1 to that number, convert the number back into a string, and put the string back into the labels text property.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Visual Basic 2010 HELP

    Grim - I'm a little shocked and somewhat disappointed in you... encouraging the use of a label to keep track of data... tisk tisk tisk...

    This is something I see a lot... I'm beginning to wonder if this is something people just do... or are there instructors out there teaching this carp ... Labels should be used for DISPLAYING DATA... NOT as a storage bin. You're better off creating a variable with the appropriate scope... and incrementing that... and then using that value to update the label... if you want to simplify it, create a sub that will increment the variable and the label at the same time... then all you would need to do is call that.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Visual Basic 2010 HELP

    Hah, I wasn't doing that honest! On something at this level, giving someone a completely different way of working often means they get lost on how it relates to their starting question. Once they have worked out why, then I can hit them with the next bit, honest!

    -1 for teaching skills

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