返回列表 上一主題 發帖

如何可以抓到檔案的最後一筆資料?

我也是這樣子玩的,因為它是字串的觀念,不是陣列的觀念,所以它讀檔是循序的...
是學程式而不是要程式,是進步的基礎

TOP

Dim TextStr As New System.IO.StreamReader(FileTxt, System.Text.Encoding.Default)
Dim Ia As Long = 0
   Do While TextStr.Peek > -1
     Dim Data As String = TextStr.ReadLine
     Ia +=1
     SELECT CASE IA
        CASE  1
           Dim 日期 As String = Mid(Data, 1, 8)
           Dim 時間 As String = Mid(Data, 9, 6)
        CASE ELSE
            Dim 日期 As String = Mid(Data, 1, 8)
            Dim 時間 As String = Mid(Data, 9, 6)
     END SELECT
   Loop

我的用法 ...  你參考看看..
是學程式而不是要程式,是進步的基礎

TOP

任一筆喔..
dim  XoX as long = 99    '任一筆

SELECT CASE IA
        CASE  XoX
           Dim 日期 As String = Mid(Data, 1, 8)
           Dim 時間 As String = Mid(Data, 9, 6)
        CASE ELSE
            Dim 日期 As String = Mid(Data, 1, 8)
            Dim 時間 As String = Mid(Data, 9, 6)
     END SELECT
是學程式而不是要程式,是進步的基礎

TOP

那你設定一個 datatable 吧
是學程式而不是要程式,是進步的基礎

TOP

本帖最後由 暗黑 於 2011-1-6 17:10 編輯

datatable  是資料表...  說穿了  也是一個陣列
dtattable  的好處是  有很多的指令...  缺點..佔記億体較大  , 且  txt  資料並非是 標準資料庫格式,需轉資料

txt 檔案轉成 datatable 方式如下
以下是友站提供的資料片段
  1. Dim ansFile As FileInfo
  2.             For Each ansFile In New DirectoryInfo(answerPath).GetFiles("*.txt")
  3.                 Dim dr As DataRow = dtAnswer.NewRow
  4.                 dr("no") = ansFile.Name
  5.                 dr("ans") = ReadCount(ansFile.FullName)
  6.                 dtAnswer.Rows.Add(dr)
  7.             Next
  8.              
  9.             '學生成績
  10.             Dim dt As DataTable = New DataTable
  11.             dt.Columns.Add(New DataColumn("no", Type.GetType("System.String")))   '學號         
  12.             dt.Columns.Add(New DataColumn("right", Type.GetType("System.Int32"))) '答對
  13.             dt.Columns.Add(New DataColumn("wrong", Type.GetType("System.Int32"))) '答錯
  14.             dt.Columns.Add(New DataColumn("score", Type.GetType("System.Int32"))) '得分
複製代碼
http://www.blueshop.com.tw/board/FUM20050124191756KKC/BRD200612150034214VL.html
是學程式而不是要程式,是進步的基礎

TOP

        靜思自在 : 犯錯出懺悔心,才能清淨無煩惱。
返回列表 上一主題