• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Creating a volume calculator

Hi
I am trying to learn Visual basic and am trying to follow a tutorial to calculate the volume of a cylinder.
 I have followed the tutorial but when I run the program I get an error message
saying no Data or method found . I have the interface and all the boxes and labels are as instructed.
 
The tutorial is below without the picture of the interface. am I failing to follow it precise or is it  a typo in the tutorial.


 

Lesson 2.   A program to calculate the Volume of a Cylinder
This program is a simple program that calculates the volume of a cylinder. Let design the interface:

 

First of all, go to the properties window and change the form caption to Volume of Cylinder, then drag and insert three labels into the form and change their captions to Base Radius, height and volume respectively. After that, insert three Text Boxes and clear its text contents so that you get three empty boxes. Named the text boxes as radius, hght (we cannot use height as it is the built-in control name of VB) and volume respectively. Lastly, insert a command button and change its caption to O.K and its name to OK. Now save the project as cylinder.vbp and the form as cylinder.vbp as well


Now we shall attempt to write the codes for the cylinder program where the interface is shown in Figure 2.8. First of all, name the textbox as radius, hght, and volume. To get the values of the various textboxes, use Val(radius.text), Val(hght.Text) and assign them to the variables r and h. In addition, assign the value 22/7 to the variable pi. After that, write the equation v = pi * (r ^ 2) * h to compute the value of volume of cylinder and then assign it to the variable v. Finally, display the value in the volume textbox using the function Str$.

 Private Sub OK_Click( )

r = Val(radius.Text)

h = Val(hght.Text)

pi = 22 / 7

v = pi * (r ^ 2) * h

volume.Text= Str$(v)

End Sub

 When you run the program, you should be able to see the interface as shown in Figure 2.8.  If you enter a value each in the radius box and the height box, then click OK; the value of the Volume will be displayed in the volume box.
Its when I click OK  is were I get an error, saying no data or method found.

Regards Planner
0
planner1234
Asked:
planner1234
  • 2
2 Solutions
 
Mark_FreeSoftwareCommented:

make sure you have named the button OK

and the textboxes

hght
radius
volume


than should it work....
0
 
AtanAsfalothCommented:
I don't know if you ever plan on using this program for exact calculations, but if you do want to, I recommend another approximation of pi, because 22 / 7 is... well... very rough.
What I'd recommend is:

pi = CDbl(4 * Atn(1))

Which means 4 * arctan(1)
and arctan(1) = pi / 4

Regards,
Atan Asfaloth
0
 
PockyMasterCommented:
you're looking at: http://members.tripod.com/~vkliew/VBtutor.html probably?
0
 
PockyMasterCommented:
Found other sites to learn vb6:
http://www.vtc.com/products/vb6.htm

http://www.vbtutor.net/vbtutor.html

and look in your local bookstore, you probably can pick up a good book about VB6 for a dollar or so, since it's become quite ancient already :D

If you want to learn something, better learn it the right way at once. It saves you a lot of troubles and gives you a better learning experience and result in the end.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now