Solved

# Creating a volume calculator

Posted on 2006-04-07
183 Views
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( )

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
Question by:planner1234

LVL 13

Assisted Solution

make sure you have named the button OK

and the textboxes

hght
volume

than should it work....
0

LVL 5

Accepted Solution

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

LVL 14

Expert Comment

you're looking at: http://members.tripod.com/~vkliew/VBtutor.html probably?
0

LVL 14

Expert Comment

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

### Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…