Math Tutorial Sum Problem

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 6863 Views - Last Post: 01 September 2011 - 02:02 PM Rate Topic: -----

#1 pcboyyyy   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 29-August 10

Math Tutorial Sum Problem

Posted 31 August 2011 - 09:55 AM

Can someone please tell me why this VB 2008 does not recognize this line of code as valid?

Public Class Form1

    ' Create a Random object to generate random numbers.
    Dim randomizer As New Random

    ' These Integers will store the numbers in the addition problem.
    Dim add1 As Integer
    Dim add2 As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
    End Sub
Public Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startButton.Click
        ' Fill in the addition problem.
        add1 = randomizer.Next(51)
        add2 = randomizer.Next(51)
        leftLabel.Text = add1.ToString()
        rightLabel.Text = add2.ToString()
        sum.Value = 0


My problem operator is sum.Value.
VB keeps telling me sum is not declared.

Why is this not working if it is a Microsoft example?

Math Quiz

Is This A Good Question/Topic? 0
  • +

Replies To: Math Tutorial Sum Problem

#2 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 11:12 AM

I had a quick look at that example from Microsoft's website it says change the name property of the NumericUpDown to sum did you do that it was the first step Q9.

Drag a NumericUpDown control from the Toolbox, and then do the following:

Change the font size to 18, and then make it narrower so that the width is 100.

Drag it until it lines up with the Label controls for the addition problem.

Change the (Name) property to sum. (You learn more about the NumericUpDown control later.) The quiz now has a first row, as shown in the following picture.

This post has been edited by m_wylie85: 31 August 2011 - 11:13 AM

Was This Post Helpful? 0
  • +
  • -

#3 pcboyyyy   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 29-August 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 11:45 AM

View Postm_wylie85, on 31 August 2011 - 11:12 AM, said:

I had a quick look at that example from Microsoft's website it says change the name property of the NumericUpDown to sum did you do that it was the first step Q9.

Drag a NumericUpDown control from the Toolbox, and then do the following:

Change the font size to 18, and then make it narrower so that the width is 100.

Drag it until it lines up with the Label controls for the addition problem.

Change the (Name) property to sum. (You learn more about the NumericUpDown control later.) The quiz now has a first row, as shown in the following picture.


Yes, I tried that. I want the user to be able to fill in their own answer. I am finding that there is something wrong with the control, also that method seems prehistoric.
Was This Post Helpful? 0
  • +
  • -

#4 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 12:38 PM

Do you mean you would like the user to input their answer in a textbox the check to see if the textbox = the two labels
Was This Post Helpful? 1
  • +
  • -

#5 pcboyyyy   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 29-August 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 12:51 PM

View Postm_wylie85, on 31 August 2011 - 12:38 PM, said:

Do you mean you would like the user to input their answer in a textbox the check to see if the textbox = the two labels


Precisely. I want user to answer a math problem and then be able to check their answer to see if it's right or wrong. I already have it programed to create random math problems.
Was This Post Helpful? 0
  • +
  • -

#6 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:14 PM

Ok have a look at this this should help you. This may not be the best way to do it but it works i just through it together there but you may want to add stuff to it like check that the users has entered a value into the textbox and so on.

Public Class Form1
    Dim add1 As Integer
    Dim add2 As Integer
    Private randomizer As New Random

    ' These Integers will store the numbers
    ' for the addition problem.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        add1 = CInt(CStr(randomizer.Next(51)))
        add2 = CInt(CStr(randomizer.Next(51)))
        LblLeftLabel.Text = CStr(add1)
        lblRightLabel.Text = CStr(add2)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Fill in the addition problem.

        If add1 + add2 = CDbl(txtAns.Text) Then
            MessageBox.Show("Your answer was right")
        Else
            MessageBox.Show("Your answer was wrong")
        End If

    End Sub
End Class

Was This Post Helpful? 1
  • +
  • -

#7 pcboyyyy   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 29-August 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:19 PM

View Postm_wylie85, on 31 August 2011 - 01:14 PM, said:

Ok have a look at this this should help you. This may not be the best way to do it but it works i just through it together there but you may want to add stuff to it like check that the users has entered a value into the textbox and so on.

Public Class Form1
    Dim add1 As Integer
    Dim add2 As Integer
    Private randomizer As New Random

    ' These Integers will store the numbers
    ' for the addition problem.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        add1 = CInt(CStr(randomizer.Next(51)))
        add2 = CInt(CStr(randomizer.Next(51)))
        LblLeftLabel.Text = CStr(add1)
        lblRightLabel.Text = CStr(add2)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Fill in the addition problem.

        If add1 + add2 = CDbl(txtAns.Text) Then
            MessageBox.Show("Your answer was right")
        Else
            MessageBox.Show("Your answer was wrong")
        End If

    End Sub
End Class


I will try this. Meantime, what does CStr do? Or CInt or CDbl?
Was This Post Helpful? 0
  • +
  • -

#8 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:33 PM

Ok this may help i am not great at explaining things you may be better to just look them up yourself.

CStr() method will convert the value IN the object to a string.

CInt() Converts positive and negative numbers into Integer data type

CDbl() Converts to double

You couls also use Cint Here, like i said just through it together

If add1 + add2 = CInt(txtAns.Text) Then


But best to read up on them for yourself

This post has been edited by m_wylie85: 31 August 2011 - 01:35 PM

Was This Post Helpful? 1
  • +
  • -

#9 pcboyyyy   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 29-August 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:44 PM

View Postm_wylie85, on 31 August 2011 - 01:33 PM, said:

Ok this may help i am not great at explaining things you may be better to just look them up yourself.

CStr() method will convert the value IN the object to a string.

CInt() Converts positive and negative numbers into Integer data type

CDbl() Converts to double

You couls also use Cint Here, like i said just through it together

If add1 + add2 = CInt(txtAns.Text) Then


But best to read up on them for yourself


After I actually stopped to read them I realized what they were doing.

You mentioned checking to see if the user entered numbers for an answer. How do you do that exactly? I've done it before, but not in this kind of program.

Also, what if you want to tell the user how many problems they got correct vs. wrong?

All of your help is much appreciated by the way. B)
Was This Post Helpful? 0
  • +
  • -

#10 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:46 PM

before i start to go into that is this for homework
Was This Post Helpful? 0
  • +
  • -

#11 pcboyyyy   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 29-August 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:57 PM

View Postm_wylie85, on 31 August 2011 - 01:46 PM, said:

before i start to go into that is this for homework


No, I am trying to rework the tutorial. This is for pure practice and more practice.

Now, I realized why I didn't recognize the functions you were using though. They're pretty old right? I confirmed that by reading another thread here.
Was This Post Helpful? 0
  • +
  • -

#12 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 02:06 PM

Yeah ok to check that the text box it not empty.

you will need to change the if statements in the button click event i will give you a hint then try to fix it then if you have problem ask me

The If statement will have three this time:

1. If (Here is were you want to check if the text box is empty)
2. Elseif (then here check if the val of the textbox equals the labels)
3. Else (they have the wrong answer)

So for the first if try reading about how to check if a textbox is empty a hint ("")

PS going for bath back soon

This post has been edited by m_wylie85: 31 August 2011 - 02:08 PM

Was This Post Helpful? 0
  • +
  • -

#13 Psyguy   User is offline

  • D.I.C Regular
  • member icon

Reputation: 84
  • View blog
  • Posts: 365
  • Joined: 12-January 11

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 02:16 PM

View Postpcboyyyy, on 31 August 2011 - 01:57 PM, said:

View Postm_wylie85, on 31 August 2011 - 01:46 PM, said:

before i start to go into that is this for homework


No, I am trying to rework the tutorial. This is for pure practice and more practice.

Now, I realized why I didn't recognize the functions you were using though. They're pretty old right? I confirmed that by reading another thread here.


The "new" .NET way to do those is using the parse or tryparse methods. For example:
Dim myInt as Integer
Dim myIntStr as String="48"
Integer.TryParse(myIntStr, myInt)


That way you can make sure the input from the box IS the datatype you are looking for.
http://www.dreaminco...arse-statement/
Here is another discussion on the subject. From what I understand, the CInt, CStr, etc. is a deprecated way of casting data types.

This post has been edited by Psyguy: 31 August 2011 - 02:17 PM

Was This Post Helpful? 0
  • +
  • -

#14 pcboyyyy   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 29-August 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 02:16 PM

View Postm_wylie85, on 31 August 2011 - 02:06 PM, said:

Yeah ok to check that the text box it not empty.

you will need to change the if statements in the button click event i will give you a hint then try to fix it then if you have problem ask me

The If statement will have three this time:

1. If (Here is were you want to check if the text box is empty)
2. Elseif (then here check if the val of the textbox equals the labels)
3. Else (they have the wrong answer)

So for the first if try reading about how to check if a textbox is empty a hint ("")

PS going for bath back soon


Ok. My guess for #1 is:

If sumText.Text = ""

Was This Post Helpful? 0
  • +
  • -

#15 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 02:26 PM

yeah that would do. there is other things you may want to do like check if the input is numeric you can look that up if you want

also read what psyguy posted it will help you

This post has been edited by m_wylie85: 31 August 2011 - 02:27 PM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3