hi to all vb6 and vb.net expert!
i need help. i want to split the data from a text file and save it to the sql database.
attached here is the .txt file and the format.this data is from a chronolog machine im thinking of using string token but it does not have a separator.how can i split the strings. thanks any suggestions and comments will do.. this is the code that i've started. i've extracted the .txt file but i have no idea yet how to split it.

Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
con.Open "DSN=chrono"
rec.Open "Select * FROM DT102T01.txt ", con, 3, 3

Set DataGrid.DataSource = rec 'display only to show that i get the data

Recommended Answers

All 3 Replies

I'm confused at how you're opening the text file BUT, here is how to use Substring to parse your fixed-format records.

Module Module1
   Sub Main()
      Dim strData As String = "0300002158A2012010921343" ' sample data

      Dim strBarCode As String = strData.Substring(0, 10)
      Dim chrTerminal As Char = strData(10)
      Dim dtDate As DateTime = DateTime.Parse(
            strData.Substring(11, 4) + "-" +
            strData.Substring(15, 2) + "-" +
            strData.Substring(17, 2))
      Dim intDOW As Integer = Integer.Parse(strData.Substring(19, 1))
      Dim strTime As String = strData.Substring(20, 4)
   End Sub
End Module

I can't open your document. Don't assume everyone has Office 2010. Posting in txt format would be preferable.

I'm confused at how you're opening the text file BUT, here is how to use Substring to parse your fixed-format records.

Module Module1
   Sub Main()
      Dim strData As String = "0300002158A2012010921343" ' sample data

      Dim strBarCode As String = strData.Substring(0, 10)
      Dim chrTerminal As Char = strData(10)
      Dim dtDate As DateTime = DateTime.Parse(
            strData.Substring(11, 4) + "-" +
            strData.Substring(15, 2) + "-" +
            strData.Substring(17, 2))
      Dim intDOW As Integer = Integer.Parse(strData.Substring(19, 1))
      Dim strTime As String = strData.Substring(20, 4)
   End Sub
End Module

thanks bro.. it really helps a lot.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.