Solved

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

Posted on 2002-04-12
13
198 Views
Last Modified: 2010-05-02
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
Comment
Question by:jsm11482
13 Comments
 
LVL 1

Expert Comment

by:ShaneCourtrille
ID: 6938468
Have you checked the value of strLine prior to the split command? And if so can you post an example value?
0
 
LVL 2

Accepted Solution

by:
tppradeep18 earned 100 total points
ID: 6938620
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6938796
if this is a duplicate http://www.experts-exchange.com/visualbasic/Q.20288379.html, please delete.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:jsm11482
ID: 6938842
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
 

Author Comment

by:jsm11482
ID: 6938844
emoreau - what do you mean?-Josh
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6938850
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6938854
If the commas screws the line, use another character!

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

Author Comment

by:jsm11482
ID: 6938924
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6938931
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
 

Author Comment

by:jsm11482
ID: 6938969
thanks everyone but i figured it out!
-Josh
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6939089
and which comment helped you the most?
0
 

Author Comment

by:jsm11482
ID: 6939171
Thanks, your comment got me the closest to my answer!
-Josh
0
 

Author Comment

by:jsm11482
ID: 6940835
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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question