Assistance please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BairnsRus
    New Member
    • Dec 2007
    • 3

    Assistance please

    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
    Last edited by Dököll; Dec 16 '07, 04:12 AM. Reason: [CODE=VB]
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by BairnsRus
    Many Thanks in advance
    Nice work it seems thus far BairnsRus, I'd have to run your code to see what you are refering to and perhaps give you some direction. Please stay tuned, perhaps someone will beat me to it.

    Also you are calling modules, perhaps adding part of relating code can help shed some light:-)

    In a bit!
    Last edited by Dököll; Dec 16 '07, 04:20 AM. Reason: added remark...

    Comment

    • BairnsRus
      New Member
      • Dec 2007
      • 3

      #3
      Thanks for the reply Dokoll,
      I have made one slight change but now although it displays all five records as they are entered, it does not calculate all BMIs

      Code:
      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_And_Height(weight(), height())
      Call CalcuateStore(BMI, weight(), height())
      Call Display(height(), weight(), BMI, NumMembers, ctr)
      Next ctr
      End Sub
      
      Public Sub Enter_Weight_And_Height(ByRef weight() As String, ByRef height() As String)
      weight(5) = InputBox("Please enter the member's weight in kilograms")
      height(5) = InputBox("Please enter the member's height in metres")
      End Sub
      
      Public Sub CalcuateStore(ByRef 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
      Thanks again

      Comment

      Working...