-2

いくつかのレコードを含む8MBのファイルがあります。特定の場所から特定のレコードを読みたい。ファイル内のすべてのレコードの開始バイトインデックスと終了バイトインデックスがあります。

私の問題は、ファイルダイアログボックスを使用して特定のファイルを選択し、ファイルを読み取って特定のレコードをテキストボックスに保存する関数を作成する方法です。

また、すべてのテキストボックスで一度にすべてのレコードを読み取る方法についても疑問があります。

4

1 に答える 1

0

First,I need an index of my file values suppose product id =id09876543 location =india then index values of id09876543 is " 12 to 23 " then i will pass 12 and 23 in function calling.

  1. make a user define function called "read_value" pass the 2 argument in it in integer form and make function as string i.e. it will return value in string format.

  2. call that function in your specific place where you want the answer.

like this.

1)

Public Function read_value(ByVal strat As Integer, ByVal end1 As Integer) As String

    Dim fs As FileStream = New FileStream(f_name, FileMode.Open, FileAccess.Read)

    Dim n As Integer = 0
    Dim s As String = Nothing
    Dim i As Integer = 0
    Dim l As Long = strat
    fs.Seek(l, SeekOrigin.Begin)
    'Seek(strat)
    For i = strat To end1
        n = fs.ReadByte()
        s = s + Convert.ToChar(n)
    Next
    Return s
End Function

Dim ofd1 As New OpenFileDialog ' Dim file_name As String Try If ofd1.ShowDialog = Windows.Forms.DialogResult.OK Then f_name = ofd1.FileName

            product_id_txt.Text = read_value(12, 23)
            location_txt.Text = read_value(34, 50)
            form.Show()
        End If
    Catch ex As Exception
        MessageBox.Show("File Not Found")
    End Try

Output of this code is label----->Product Id: id09876543 <---- this is my text box value

于 2013-03-09T08:21:47.870 に答える