# Math Tutorial Sum Problem

• (3 Pages)
• 1
• 2
• 3

## 33 Replies - 6744 Views - Last Post: 01 September 2011 - 02:02 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=245548&amp;s=a79c59ca3cffac3fd5808a10b8465293&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 pcboyyyy

Reputation: 0
• 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.
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.
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

Reputation: 96
• 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

### #3 pcboyyyy

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

## Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 11:45 AM

m_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.

### #4 m_wylie85

Reputation: 96
• 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

### #5 pcboyyyy

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

## Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 12:51 PM

m_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.

### #6 m_wylie85

Reputation: 96
• 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
Private randomizer As New Random

' These Integers will store the numbers

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

' Fill in the addition problem.

Else
End If

End Sub
End Class
```

### #7 pcboyyyy

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

## Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:19 PM

m_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
Private randomizer As New Random

' These Integers will store the numbers

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

' Fill in the addition problem.

Else
End If

End Sub
End Class
```

I will try this. Meantime, what does CStr do? Or CInt or CDbl?

### #8 m_wylie85

Reputation: 96
• 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

### #9 pcboyyyy

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

## Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:44 PM

m_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.

### #10 m_wylie85

Reputation: 96
• 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

### #11 pcboyyyy

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

## Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 01:57 PM

m_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.

### #12 m_wylie85

Reputation: 96
• 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

### #13 Psyguy

• D.I.C Regular

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

## Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 02:16 PM

pcboyyyy, on 31 August 2011 - 01:57 PM, said:

m_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

### #14 pcboyyyy

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

## Re: Math Tutorial Sum Problem

Posted 31 August 2011 - 02:16 PM

m_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 = ""
```

### #15 m_wylie85

Reputation: 96
• 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