2012-05-02 72 views

回答

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 

希望它會幫助的人誰需要它!

相關問題