Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Calculate Your Body Mass Index.

Body mass index (BMI) is a measure of body fat based on height


and weight that applies to adult men and women.

SMALL BASIC PROGRAM CODE

'Set graphics window


GraphicsWindow.Title= "BMI calculator"
GraphicsWindow.Show()
GraphicsWindow.CanResize = "False"
GraphicsWindow.Width = 250
GraphicsWindow.Height= 150
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.BackgroundColor= "Yellow"

'Define first line


lblweight = Shapes.AddText("Weight")
Shapes.Move(lblweight, 20, 25)
lblweightbox = Controls.AddTextBox(70, 20)
Controls.SetSize(lblweightbox,50, 25)
GraphicsWindow.FontBold = "false"
lblweightunit = Shapes.AddText("Kg")
Shapes.Move(lblweightunit, 130, 25)
GraphicsWindow.FontBold = "True"

'Define second line


lblheight = Shapes.AddText("height")
Shapes.Move(lblheight, 20, 55)
lblheightbox = Controls.AddTextBox(70, 52)
Controls.SetSize(lblheightbox,50, 25)
GraphicsWindow.FontBold = "false"
lblheightunit = Shapes.AddText("Cm")
Shapes.Move(lblheightunit, 130, 55)
GraphicsWindow.FontBold = "True"

'Define third line


lblBMI = Shapes.AddText("BMI")
Shapes.Move(lblBMI, 20, 88)
lblResult = Shapes.AddText ("")
Shapes.Move(lblResult, 75, 88)
Controls.TextTyped = UpdateResult

'Define forth line


'lblstatus = Shapes.AddText("")
'Shapes.Move (lblstatus, 75, 118)

'Define subroutin for calculating BMI


Sub UpdateResult
w = Math.Abs(Controls.GetTextBoxText(lblweightbox) * 1)
h = Math.Abs(Controls.GetTextBoxText(lblheightbox) * 1)/100
If h = 0 Then
BMI = "-"
Else
BMI = w/ (h*h)
BMI = Math.Round(BMI*100/100)
EndIf
Shapes.SetText(lblResult, BMI)
ShowStatus()
EndSub

'Define subroutin for showing status of health


Sub ShowStatus
Shapes.Remove(lblstatus)
If BMI <> "-" Then
If BMI < 20 Then
status = "Under Weight"
color = "Blue"
ElseIf BMI <= 25 then
status = "Normal"
color = "LimeGreen"
Else
status = "Over Weight"
color = "Red"
EndIf
GraphicsWindow.BrushColor = color
'Shapes.SetText(lblstatus, status)
lblstatus = Shapes.AddText(status)
Shapes.Move (lblstatus, 75, 118)
GraphicsWindow.BrushColor = "Black"
EndIf
EndSub

You might also like