Solved

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

Posted on 2002-04-12
13
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

752 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