I am brand new in VB and I need help with my programs. I need to write a program that will give me the circumference of a circle with a given radius. Can anyone help?
12-06-2002 at 11:41 AM
|
dcostelloe Level: VB Guru Registered: 11-06-2002 Posts: 74
quote:greenough157 wrote:
I am brand new in VB and I need help with my programs. I need to write a program that will give me the circumference of a circle with a given radius. Can anyone help? ???
Try this. It is very simple. After knowing te concept you can improve your form by changing the controls, codes etc. Good luck.
'Add two text boxes and name them as txtRadius and txtCircum to receive input and display output respectively.
'Add three command buttons and name them cmdCalculate, cmdClear, cmdExit
Option Explicit
'Variable types are variant by default. Type can be specified as Int, Single etc.
Dim Radius 'Declare variable Name for radius
Dim Circum 'Declare variable Name for Circumference
Private Sub cmdClear_Click()
txtRadius.Text = "" 'This is to clear the Radius text box when you click the Clear button
txtCircum.Text = "" 'This is to clear the Circumference text box when you click the Clear button
End Sub
Private Sub cmdExit_Click()
End ' This is to exit the program when Exit button is clicked
End Sub
Private Sub cmdFind_Click()
Const PI = 22 / 7 ' Constant is defined
Radius = txtRadius.Text 'Variable is assigned to text box to receive input from the user
Circum = PI * 2 * Radius 'Variable is defined (formulae for circumference)
txtCircum.Text = Circum ' Variable assigned to text box to disply output
End Sub