By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

Assistance please

P: 3
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:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  3. Private Sub cmdExit_Click()
  4. End
  5. End Sub
  7. Private Sub cmdStart_Click()
  8. Dim weight(5) As String
  9. Dim height(5) As String
  10. Dim BMI As Single
  11. Dim NumMembers As Integer
  12. Dim ctr As Integer
  13. For ctr = 1 To 5
  14. Call Enter_Weight_And_Height(weight(), height())
  15. Call CalcuateStore(BMI, weight(), height())
  16. Next ctr
  17. Call Display(height(), weight(), BMI, NumMembers, ctr)
  18. End Sub
  20. Public Sub Enter_Weight_And_Height(ByRef weight() As String, ByRef height() As String)
  21. weight(5) = InputBox("Please enter the member's weight in kilograms")
  22. height(5) = InputBox("Please enter the member's height in metres")
  23. End Sub
  25. Public Sub CalcuateStore(ByRef BMI As Single, ByRef weight() As String, ByRef height() As String)
  26. Dim underweight As Integer
  27. Dim ideal_weight As Integer
  28. Dim overweight As Integer
  29. underweight = 0
  30. ideal_weight = 0
  31. overweight = 0
  32. BMI = weight(5) / (height(5) * height(5))
  33. End Sub
  35. Public Sub Display(ByRef height() As String, ByRef weight() As String, ByRef BMI As Single, ByRef NumMembers As Integer, ByRef ctr As Integer)
  36. Dim inval As Single
  37. BMI = CSng(BMI)
  38. picResult.Print ""
  39. picResult.Print "Height in metres "; Tab; "Weight in kilograms"; Tab; "BMI"
  40. picResult.Print height(5); Tab; Tab; weight(5); Tab; Tab; Format(BMI, "##0.0")
  41. End Sub
Many Thanks in advance
Dec 14 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 2,364
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!
Dec 16 '07 #2

P: 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

Expand|Select|Wrap|Line Numbers
  2. Option Explicit
  4. Private Sub cmdExit_Click()
  5. End
  6. End Sub
  8. Private Sub cmdStart_Click()
  9. Dim weight(5) As String
  10. Dim height(5) As String
  11. Dim BMI As Single
  12. Dim NumMembers As Integer
  13. Dim ctr As Integer
  14. For ctr = 1 To 5
  15. Call Enter_Weight_And_Height(weight(), height())
  16. Call CalcuateStore(BMI, weight(), height())
  17. Call Display(height(), weight(), BMI, NumMembers, ctr)
  18. Next ctr
  19. End Sub
  21. Public Sub Enter_Weight_And_Height(ByRef weight() As String, ByRef height() As String)
  22. weight(5) = InputBox("Please enter the member's weight in kilograms")
  23. height(5) = InputBox("Please enter the member's height in metres")
  24. End Sub
  26. Public Sub CalcuateStore(ByRef BMI As Single, ByRef weight() As String, ByRef height() As String)
  27. Dim underweight As Integer
  28. Dim ideal_weight As Integer
  29. Dim overweight As Integer
  30. underweight = 0
  31. ideal_weight = 0
  32. overweight = 0
  33. BMI = weight(5) / (height(5) * height(5))
  34. End Sub
  36. Public Sub Display(ByRef height() As String, ByRef weight() As String, ByRef BMI As Single, ByRef NumMembers As Integer, ByRef ctr As Integer)
  37. Dim inval As Single
  38. BMI = CSng(BMI)
  39. picResult.Print ""
  40. picResult.Print "Height in metres "; Tab; "Weight in kilograms"; Tab; "BMI"
  41. picResult.Print height(5); Tab; Tab; weight(5); Tab; Tab; Format(BMI, "##0.0")
  42. End Sub
Thanks again
Dec 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.