954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

splitting string into using vb6 or vb.net

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

Attachments data.docx (88.18KB)
rhone0809
Newbie Poster
15 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

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
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

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

Reverend Jim
Posting Shark
Moderator
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
 

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.. :)

rhone0809
Newbie Poster
15 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You