0

我在这里看到完全相同的问题,但我想知道 vb(窗口形式)中的代码。我已将变量存储在

暗淡姓氏,姓氏,中间名,年龄作为字符串

并将数据保存在记事本中。我怎样才能将它们放回它们的确切标签中。我的标签之一是

lbl_surname.Text

谢谢。

4

1 回答 1

0

我发现下面的代码对我有帮助,

将 TextLine 调暗为字符串

    Dim objReader As New System.IO.StreamReader(openfile)
    Dim aryTextFile() As String  'this sets up an array to store the seperate parts of the line
    ' round brackets are blank because we don’t know how many we need (separate items) there are on each line
    If System.IO.File.Exists(openfile) = True Then 'see if file exists

        While objReader.Peek() <> -1  'takes a peek to find end of file, rteturns -1 if no more lines
            TextLine = objReader.ReadLine() 'Read line
            lbl_data.Text = lbl_data.Text & vbNewLine & TextLine
            'Extracting required data fr
            aryTextFile = TextLine.Split(",") 'Inside the round brackets is symbol is used to separate each element in the line, in this case a comma.

            ' For i = 0 To UBound(aryTextFile) 'UBound means upper boundary of array, ie max number of variables
            'MsgBox(aryTextFile(i))
            ' Next i
            ' Put required bits from line in appropriate places on form

            Surname = aryTextFile(0) 'first part needed
            age = aryTextFile(3) 'second part needed
            Middlename = aryTextFile(1)
            Lastname = aryTextFile(2)
            mobile = aryTextFile(4)
            lbl_surname.Text = Surname 'Storing data into label for display
            lbl_lastname.Text = Lastname
            lbl_middlename.Text = Middlename
            lbl_age.Text = age 'Storing data into label for display
            lbl_mob.Text = mobile

        End While

    End If
End Sub

希望对需要的人有所帮助!

于 2012-05-03T02:06:51.463 回答