Solved

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

Posted on 2002-04-12
13
173 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 69

Expert Comment

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

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 69

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 69

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 69

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 69

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now