Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys I need help with this practice question.I have managed to place data into the arrays but haven't been able to display all the details in the label when I tried it I only got 2 items which were repeating instead of showing specific details required for each patient
I have also copied the question at the top in case I'm missing something in my interpretation of the question and the code is at the bottom.Thanks


Write and test a program that allows the user to enter the name of each patient at a GP clinic who has been called in for cholesterol screening, and their blood cholesterol level. There are 15 patients at the clinic.
 This data should be stored in two separate arrays (one array for the patient names and another array for the blood cholesterol levels).
 The patient names should be stored as strings.
 The blood cholesterol levels should be stored as real numbers.
 The input data should be validated before being entered into the array. Patient names must be at least 3 characters long and cannot contain more than 20 characters. Only values between 0.1 and 30.5 should be accepted and stored in the blood cholesterol level array.
 If an invalid entry is attempted, a message should be displayed informing the user that the entry will not be stored and that the name must be between 3 and 20 characters long and that a value between 0.1 and 30.5 must be entered for the blood cholesterol level.
 Once the arrays are full, the ‘Input data’ button should be disabled and the ‘Show contents’ button should be enabled which, when pressed, will print out the patient name and blood cholesterol level for each patient, in the order entered, to a label.

Question 3
Blood cholesterol levels over 6.5 are dangerous and require treatment. Extend the program from Question 2 so that it includes a button which, when pressed, will find, store in separate arrays (patients with raised cholesterol and patient high cholesterol levels), and print out to a label, the names of all patients with a cholesterol level greater than 6.5, along with their cholesterol level.

Introduction to Programming
Question 4
The data for the candidates at risk of high cholesterol needs to be stored permanently. Extend the program from Question 3 so that it writes out the patient name and corresponding blood cholesterol level for the patients with a blood cholesterol level greater than 6.5. These should be written out to a text file called “HighCholesterol”.
 The patient names and their blood cholesterol levels should be paired on the same line, with the first patient name followed by their blood cholesterol level on the same line with no spaces between them, and so on for all patients with cholesterol levels greater than 6.5.
 There should be a ‘Save results’ button which will write the data to file when pressed. This button should not be enabled until the ‘Find at risk patients’ button (or whatever name was given to the button for question 3) has been pressed.
 Test the extended functionality of the program.


This is what I've been able to do

VB
 Public Class Form1
    Private strPatients(15) As String
    Private dblCholesterol(15) As Double
    Private Max As Integer = 15
   
    Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click
        Dim intCount As Integer = 14
        For intCount = 0 To strPatients.Length - 1
            Try
                strPatients(Max) = InputBox("Please enter a patient name")
            Catch
                MessageBox.Show("Invalid entry")

            End Try

            If strPatients(Max).Length < 3 Then
                MessageBox.Show("Patient name must be more than 3 characters")
            ElseIf strPatients(Max).Length > 20 Then
                MessageBox.Show("Patient name must not be more than 20 characters long")
            Else
                For strCholesterol = 0 To 14
                    Try
                        dblCholesterol(Max) = CDbl(InputBox("Please enter a Cholesterol level"))
                        If dblCholesterol(Max) < 0.1 Or dblCholesterol(14) > 30.5 Then
                            MessageBox.Show("Cholesterol must be between 0.1 and 30.5")
                        Else
                            Exit For
                        End If
                    Catch
                        MessageBox.Show("Please enter only numeric values for Cholesterol")
                    End Try
                Next
            End If
        Next intCount

        'Disable input button and enable the show contents button
        btnInput.Enabled = False
        btnShow.Enabled = True
    End Sub

    Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
        Dim intCount As Integer
        For intCount = 0 To 14
            'To print all entries to the label
            lblPatients.Text = lblPatients.Text & strPatients(15) & dblCholesterol(15) & vbCrLf
        Next
    End Sub
End Class 
Posted
Updated 12-Nov-15 21:39pm
v3

This is your homework, so no code!
But it's pretty simple.
Create a StringBuilder, and inside your For loop just add the elements to that, using the Append method.
First Append the patient name, then a space, then the patient data value, and finally Append Environment.NewLine. Each time, instead of using a fixed value "15" use the counter of the For loop.
After the loop, set the label to the stringbuilder value using the ToString method.

Try it! It's really pretty simple.
 
Share this answer
 
Comments
Member 12136392 13-Nov-15 5:20am    
No this is not homework it is an exam paper I can give you the link to prove it.
Anyways do I have to add the index of every array element in the loop?
Other words please dumb it down a bit.
OriginalGriff 13-Nov-15 5:29am    
An exam? That's even worse!

So what do you think a For loop does? What is the index?
Member 12136392 13-Nov-15 5:57am    
I do know what a for loop does and I mean the subscript of each array element
OriginalGriff 13-Nov-15 6:01am    
Good!
So why is it giving you difficulty?

I'm not trying to be annoying here - this is very, very simple and you should easily be able to see what I mean...
Member 12136392 13-Nov-15 6:07am    
To be honest I don't know why it is giving me problems,I've been going at it for a week now and my lecturer who was supposed to help out has been missing for close to 3 weeks (Probably marking our end of semester assignments),got an exam on the 26th that is why I'm so interested
Okay so I have tried it and it gives me a string of zeroes and only the final index
has the data displayed correctly,here is the code I tried

VB
Dim intCount As Integer
      For intCount = 0 To 14

          'To print all entries to the label
          lblPatients.Text = lblPatients.Text & strPatients(intCount) &       dblCholesterol(intCount) & vbCrLf
      Next
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900