Showing posts with label visual basic. Show all posts
Showing posts with label visual basic. Show all posts

Thursday, 21 March 2013

BMI Calculator | Source Code


Here is the coding for the BMI Calculator, a simple code with switch case statements to get the BMI value.


'Declarations 
Dim wt, ht, bmi, htsq
'On Click of Button
Private Sub Command1_Click()

'The Calculation Part of BMI --- 
'<--- Calculation Starts ----

wt = Val(Text1.Text)
ht = Val(Text2.Text)
'Height ---> Inches to Meters Conversion
ht = ht * 0.0254
htsq = ht * ht

bmi = (wt / htsq)
'Rounding the Float bmi to 2 decimal places
bmi = Format(bmi, "#00.00")

'Display the bmi float value
Label5.Caption = bmi

'To Display the Appropriate Text with respect to the value of BMI
Select Case bmi
Case Is < 18
Label3.Caption = "You are UnderWeight for your Height"
Case Is < 18.5
Label3.Caption = "You are Thin for your Height"
Case 18.6 To 24.9
Label3.Caption = "You are Healthy"
Case25 To 29.9
Label3.Caption = "You are OverWeight for your Height"
Case Is > 30
Label3.Caption = "You are Obese"
End Select
' --- Calculation Ends --->
End Sub

Here the Text1, Text2 are the fields for getting the Weight in Kgs and Height in Inches.

Then on the Click of the Button (Command1) we display the output using Label5 which shows bmi value as float and Label3 which shows the statement as per bmi value.

The final product is as follows,

Wednesday, 20 March 2013

Net Run Rate Calculator | Source Code

So here is our first application, a simple VB 6 application to calculate the Net Run Rate for Cricket Matches. We hope that this would be useful for anyone who manages small scale Cricket Tournaments or such. :)

'Declaring the required variables

Dim t1, t2, ov, rr1, rr2, nrr1, nrr2
______________________________________________________________________________
'Program to Calculate the Net Run Rate and Display on Click of Button

Private Sub Command1_Click()

t1 = Val(Text1.Text)
t2 = Val(Text2.Text)
ov = Val(Text3.Text)

'--- To Avoid Error when button clicked without Entering values to calculate ---
'<---Starts here---

Select Case ov
Case ov = ""
ov = 1
End Select

Select Case t1
Case t1 = ""
t1 = 0
End Select

Select Case t2
Case t2 = ""
t2 = 0
End Select
'--- Ends here--->
'--- Run Rate Calculation ---
rr1 = t1 / ov
rr2 = t2 / ov

nrr1 = rr1 - rr2
nrr2 = rr2 - rr1

Text4.Text = nrr1
Text5.Text = nrr2

End Sub

______________________________________________________________________________


This is the only Coding part. It is very simple, once you get the hang of it.

Here,

Command1 is the Button on which the Calculation Takes place

Text1 is the Text Field used to get the Team 1's score, Text2 is the Text Field for Team 2's score, Text3 is where you input the number of overs.

Text4 and Text5 are used to display the Net Run Rate Calcuated.

This is what the end program looks like