Wonder if anyone can point me in the right direction? For part of my coursework I have been asked to create a BMI monitor which calculates height, weight and displays BMI for up to 5 records. So far I can only display the last one I enter. I know I am overwriting all of the others but not why? I don't know much about arrays or even if I should use one. I know the data has to be stored somewhere before it is displayed. Can some kind person please help?
Here is my coding so far:
[CODE=VB]
Option Explicit
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdStart_Click( )
Dim weight(5) As String
Dim height(5) As String
Dim BMI As Single
Dim NumMembers As Integer
Dim ctr As Integer
For ctr = 1 To 5
Call Enter_Weight_An d_Height(weight (), height())
Call CalcuateStore(B MI, weight(), height())
Next ctr
Call Display(height( ), weight(), BMI, NumMembers, ctr)
End Sub
Public Sub Enter_Weight_An d_Height(ByRef weight() As String, ByRef height() As String)
weight(5) = InputBox("Pleas e enter the member's weight in kilograms")
height(5) = InputBox("Pleas e enter the member's height in metres")
End Sub
Public Sub CalcuateStore(B yRef BMI As Single, ByRef weight() As String, ByRef height() As String)
Dim underweight As Integer
Dim ideal_weight As Integer
Dim overweight As Integer
underweight = 0
ideal_weight = 0
overweight = 0
BMI = weight(5) / (height(5) * height(5))
End Sub
Public Sub Display(ByRef height() As String, ByRef weight() As String, ByRef BMI As Single, ByRef NumMembers As Integer, ByRef ctr As Integer)
Dim inval As Single
BMI = CSng(BMI)
picResult.Print ""
picResult.Print "Height in metres "; Tab; "Weight in kilograms"; Tab; "BMI"
picResult.Print height(5); Tab; Tab; weight(5); Tab; Tab; Format(BMI, "##0.0")
End Sub
[/CODE]
Many Thanks in advance
Here is my coding so far:
[CODE=VB]
Option Explicit
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdStart_Click( )
Dim weight(5) As String
Dim height(5) As String
Dim BMI As Single
Dim NumMembers As Integer
Dim ctr As Integer
For ctr = 1 To 5
Call Enter_Weight_An d_Height(weight (), height())
Call CalcuateStore(B MI, weight(), height())
Next ctr
Call Display(height( ), weight(), BMI, NumMembers, ctr)
End Sub
Public Sub Enter_Weight_An d_Height(ByRef weight() As String, ByRef height() As String)
weight(5) = InputBox("Pleas e enter the member's weight in kilograms")
height(5) = InputBox("Pleas e enter the member's height in metres")
End Sub
Public Sub CalcuateStore(B yRef BMI As Single, ByRef weight() As String, ByRef height() As String)
Dim underweight As Integer
Dim ideal_weight As Integer
Dim overweight As Integer
underweight = 0
ideal_weight = 0
overweight = 0
BMI = weight(5) / (height(5) * height(5))
End Sub
Public Sub Display(ByRef height() As String, ByRef weight() As String, ByRef BMI As Single, ByRef NumMembers As Integer, ByRef ctr As Integer)
Dim inval As Single
BMI = CSng(BMI)
picResult.Print ""
picResult.Print "Height in metres "; Tab; "Weight in kilograms"; Tab; "BMI"
picResult.Print height(5); Tab; Tab; weight(5); Tab; Tab; Format(BMI, "##0.0")
End Sub
[/CODE]
Many Thanks in advance
Comment