## 5 replies

Last post Apr 01, 2008 12:28 PM by Ken Tucker

• Dolo001

None

0 Points

3 Posts

### Visual Studio problem

I need help in figuring this out

I have the form designed and i am so stuck

This is my 1st Visual Basic class and i have a problem i have tried and tried to figure out on my own, maybe someone can help

Joe's pizza palace needs an application to calculate the nuber of slices a pizza of any size can be divided into. The application should do the following:

Allow the user to enter the diameter of the pizza, in inches

Calculate the number of slices that may be taken from a pizza of that size

Display a message telling the number of slices
-----------------------------------------------------------------------
To calculate the number of slices that may be taken from the pizza, you must know the following:

Each slice should have an area of 14.125 inches.

To calculate the number of slices, divide the area of the pizza by 14.125.

The area of the pizza is calculated with the formula area=pi^2

• Ken Tucker

Star

11932 Points

2647 Posts

MVP

### Re: Visual Studio problem

Mar 30, 2008 01:37 PM|Ken Tucker|LINK

The area of a circle or pizza = Math.pi * (diameter / 2) ^ 2

Dim diameter As Double = 12
Dim area As Double = Math.PI * (diameter / 2) ^ 2
Dim slices As Double = area / 14.125
Me.Text = slices.ToString

• Dolo001

None

0 Points

3 Posts

### Re: Visual Studio problem

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim diameter As Double = 12
Dim area As Double = Math.PI * (diameter / 2) ^ 2
Dim slices As Double = area / 14.125
MeText.Text = slices.ToString

Ok its working only thing it only calculates the number after 1st statement (12) how do i get it linked to the text box i input number into besides that all is well im so darn confused.

• Bruno Yu - M...

Member

332 Points

19 Posts

### Re: Visual Studio problem

Apr 01, 2008 03:39 AM|Bruno Yu - MSFT|LINK

Dolo001,

Did you use the code snippet properly? The last statement by Ken Tucker is Me.Text, this means you need to change "Me" to the proper control name. In your example, it is the TextBox. So please change the Me to the name of your TextBox control, such as the default textBox1:

textBox1.Text = slices.ToString

Sincerely,
Bruno Yu
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
• Dolo001

None

0 Points

3 Posts

### Re: Visual Studio problem

Dim diameter As Double = 12

Dim area As Double = Math.PI * (diameter / 2) ^ 2

Dim slices As Double = area / 14.125

txtslices.Text = slices.ToString

yes i did. what is happening is it will only show the answer for 12 inch no other number how do i get it to calculate any number i put in the textbox. If i change the number in code i get the correct answer when i click button but it only works for the number after

Dim diameter As Double = 12

• Ken Tucker

Star

11932 Points

2647 Posts

MVP

### Re: Visual Studio problem

Apr 01, 2008 12:28 PM|Ken Tucker|LINK

Dim diameter As Double

If double.tryparse(textbox1.text, diameter) then

Dim area As Double = Math.PI * (diameter / 2) ^ 2

Dim slices As Double = area / 14.125

txtslices.Text = slices.ToString

else

' did not enter a valid number let the user know

end if