• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

help with: 'tab' and ', ' seem to be the same with split function???

I am trying to split a log file and load it into a listview.

The fields in the file are delimited with a tab (vbtab).

I open the file, load the entire line into a string variable, i then attempt to use the split function as follows:

strSplit = Split(strLine, vbTab)

This should split the fields where ever there is a tab! it doesnt work! It splits the fields when there is a tab, but also when there is a ", " (command & space)! why would this happen and how do i fix it??

I have tried to split with chr(9) (tab ascii value) and that doesnt work either!

*******************************
HERE IS MY SUB CODE:

Public Sub LoadLog(Lv As ListView, strFile As String)
    Dim intFileNum As Integer
    Dim strLine As String
    Dim strSplit() As String
    Dim Li As ListItem
   
    intFileNum = FreeFile
    Open strFile For Input As #intFileNum
   
    Do Until EOF(intFileNum)
        Input #intFileNum, strLine
        If strLine = "" Then Exit Do
        strSplit = Split(strLine, vbTab)
       
        Set Li = Lv.ListItems.Add(, , strSplit(0))
        Li.SubItems(1) = strSplit(1)
        Li.SubItems(2) = strSplit(2)
        Li.SubItems(3) = strSplit(3)
        Li.SubItems(4) = strSplit(4)
    Loop
   
    Close #intFileNum
End Sub


Thanks for the help!
-Josh
0
jsm11482
Asked:
jsm11482
1 Solution
 
ShaneCourtrilleCommented:
Have you checked the value of strLine prior to the split command? And if so can you post an example value?
0
 
tppradeep18Commented:
First use Replace Function to replace all tabs with commas. and then use the split function as shown below



strLine = Replace(strLine,vbtab,",")
strSplit = Split(strLine, ",")

0
 
Éric MoreauSenior .Net ConsultantCommented:
if this is a duplicate http://www.experts-exchange.com/visualbasic/Q.20288379.html, please delete.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
jsm11482Author Commented:
I used debug.print to get the value of strLine...this is the line where it gets screwed up:

03/24/2002 12:59:47 AM  4.33.208.84 no  Keizer  0204 - Two Cars in Every Garage
and Three Eye.rm

the original line reads:

03/24/2002 12:59:47 AM     4.33.208.84     no     Keizer     0204 - Two Cars in Every Garage, and Three Eye.rm

So what is happening is the ', ' is being read as a tab! makes no sense i think! In TextPad I turned "visible spaces on" to see the invisible characters, and the ', ' is simply ', ' (no tab, no line break, no carriage return, just, and space!) this is so weird....

THanks,
Josh
0
 
jsm11482Author Commented:
emoreau - what do you mean?-Josh
0
 
Éric MoreauSenior .Net ConsultantCommented:
you have posted this same question at the link above (so it is a duplicate) and have accepted cookre comment. To me, it seems that this must be closed!
0
 
Éric MoreauSenior .Net ConsultantCommented:
If the commas screws the line, use another character!

strLine = Replace(strLine,vbtab,"~")
strSplit = Split(strLine, "~")
0
 
jsm11482Author Commented:
oH! i know why its not working!!!

I am opening the file with Input, i nee4d to open it with GET LINE or something because input seperates commas out!!!Right?>
-josh
0
 
Éric MoreauSenior .Net ConsultantCommented:
give a try to "line input"

Dim TextLine
Open "TESTFILE" For Input As #1   ' Open file.
Do While Not EOF(1)   ' Loop until end of file.
   Line Input #1, TextLine   ' Read line into variable.
   Debug.Print TextLine   ' Print to the Immediate window.
Loop
Close #1   ' Close file.
0
 
jsm11482Author Commented:
thanks everyone but i figured it out!
-Josh
0
 
Éric MoreauSenior .Net ConsultantCommented:
and which comment helped you the most?
0
 
jsm11482Author Commented:
Thanks, your comment got me the closest to my answer!
-Josh
0
 
jsm11482Author Commented:
emoreau - i did accidentally (dont even know how) post this question twice, is there anyway i can get my 100 points back for one of the questions?
-Josh
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now