在数组

时间:2017-12-04 22:15:18

标签: arrays vb.net

我想知道如何在里面创建一个包含多个数组的数组,因为我已经有了创建的数组,你可以在代码中看到它们。但我想将这些数组放在一个名为“患者”的数组中。而更多的是以下数组中的所有索引1名称,年龄,等等,可以在患者的索引1下看到。谢谢

Public Class DataEntry

Dim Patients()

Dim Surname(200)
Dim Firstname(200)
Dim Age(200) As String
Dim HeightA(200) As String
Dim Weight(200)

2 个答案:

答案 0 :(得分:2)

你最好做一个类似于以下的病人课程

Public Class Patient
    Private _surName As String
    Private _firstName As String
    Private _age As Integer

    Property SurName() As String
        Get
            Return _surName
        End Get
        Set(ByVal Value As String)
            _surName = Value
        End Set
    End Property

    Property FirstName() As String
        Get
            Return _firstName
        End Get
        Set(ByVal Value As String)
            _firstName = Value
        End Set
    End Property

    Property Age() As String
        Get
            Return _age
        End Get
        Set(ByVal Value As Integer)
            If Value >= 0 Then
                _age = Value
            End If
        End Set
    End Property
End Class

然后创建该类的实例

Dim p As Patient = New Patient() 
p.FirstName = "john"
p.LastName = "Smith"
p.Age = 50

Dim p1 As Patient = New Patient() 
p.FirstName = "james"
p.LastName = "bond"
p.Age = 47

'etc

然后将患者添加到列表或数组中:

Dim patients As List(Of Patient) = New List(Of Patient)
patients.Add(p)
patients.Add(p1)

答案 1 :(得分:0)

    BIM = FormatNumber(Val(txtWeight.Text) / Val((txtHeight.Text / 1000) ^ 2))

    If BIM < 18.5 Then
        Health = "Underweigth"
    ElseIf BIM > 18.5 And BIM < 24.9 Then
        Health = "Healthy Weight"
    ElseIf BIM > 24.9 And BIM < 29.9 Then
        Health = "Overweight"
    ElseIf BIM > 29.9 And BIM < 39.9 Then
        BIM = "Obese"
    ElseIf BIM > 40 Then
        Health = "Morbidly Obese"
    End If

    Dim p As Patient = New Patient()
    p.FirstName = txtFirst.Text
    p.SurName = txtSur.Text
    p.Age = txtAge.Text
    p.Height = txtHeight.Text
    p.Weight = txtWeight.Text

    Dim textAppend As String

    textAppend = "  " & p.SurName & ", " + p.FirstName & ", " + "Age: " & p.Age & ",  " + "Height: " & p.Height & "mm" & ",  " + "Weight: " & p.Weight & "kg" & "  ," + BIM & " = " & Health & "."

    Try
        File.AppendAllText(filepath, textAppend)
        MsgBox("Patient Added Successfully")
    Catch ex As Exception
        MsgBox("Error Adding Patient")
    End Try