Solved

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

Posted on 2002-04-12
10
228 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
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:kcm76
ID: 6938343
Very strange,

well, Try to replace the comma with some other special characters like " ^ ", before spliting with vbTab. and after spliting again Replace ^ with comma before adding to the listview.


btw, can u post the contents of the text.

kcm

0
 

Author Comment

by:jsm11482
ID: 6938347
Here is some example text that i am trying to load into a listview.  Again, fields are tab delimited!

03/23/2002 10:07:25 PM     4.20.74.62     no     bighead     BMP To Html.zip
03/23/2002 10:07:46 PM     4.20.74.62     no     bighead     BMP To Html.zip
03/23/2002 11:07:35 PM     63.164.173.124     no     seNtienT     1080 Snowboarding (NTSC).z64
03/23/2002 11:35:22 PM     203.57.1.53     no     bio-k     210 - Put Your Head on my Shoulder.rm
03/23/2002 11:47:52 PM     4.33.208.84     no     Keizer     0111 - The Crepes of Wrath.rm
03/24/2002 12:00:47 AM     162.83.199.223     no     resonance     250 Photoshop.EXE
03/24/2002 12:20:13 AM     24.50.175.2     no     Monsterfest     Mario64.v64
03/24/2002 12:20:42 AM     24.50.175.2     no     Monsterfest     315.rm
03/24/2002 12:34:02 AM     65.101.51.208     no     Torus  -+=PCEZ=+- 23k     The Best of Chris Farley.avi
03/24/2002 12:35:25 AM     65.101.51.208     no     Torus -+=PCEZ=+-     The Best of Chris Farley.avi
03/24/2002 12:59:47 AM     4.33.208.84     no     Keizer     0204 - Two Cars in Every Garage, and Three Eye.rm

This last record is the one that errors, because of the ', '!

Thanks,
-Josh
0
 

Author Comment

by:jsm11482
ID: 6938368
Here is some example text that i am trying to load into a listview.  Again, fields are tab delimited!

03/23/2002 10:07:25 PM     4.20.74.62     no     bighead     BMP To Html.zip
03/23/2002 10:07:46 PM     4.20.74.62     no     bighead     BMP To Html.zip
03/23/2002 11:07:35 PM     63.164.173.124     no     seNtienT     1080 Snowboarding (NTSC).z64
03/23/2002 11:35:22 PM     203.57.1.53     no     bio-k     210 - Put Your Head on my Shoulder.rm
03/23/2002 11:47:52 PM     4.33.208.84     no     Keizer     0111 - The Crepes of Wrath.rm
03/24/2002 12:00:47 AM     162.83.199.223     no     resonance     250 Photoshop.EXE
03/24/2002 12:20:13 AM     24.50.175.2     no     Monsterfest     Mario64.v64
03/24/2002 12:20:42 AM     24.50.175.2     no     Monsterfest     315.rm
03/24/2002 12:34:02 AM     65.101.51.208     no     Torus  -+=PCEZ=+- 23k     The Best of Chris Farley.avi
03/24/2002 12:35:25 AM     65.101.51.208     no     Torus -+=PCEZ=+-     The Best of Chris Farley.avi
03/24/2002 12:59:47 AM     4.33.208.84     no     Keizer     0204 - Two Cars in Every Garage, and Three Eye.rm

This last record is the one that errors, because of the ', '!

Thanks,
-Josh
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 22

Accepted Solution

by:
cookre earned 100 total points
ID: 6938430
The following ran fine:

x = "03/24/2002 12:59:47 AM@4.33.208.84@no@Keizer@0204 - Two Cars in Every Garage, and ThreeEye.rm"
z = Replace(x, "@", vbTab)
strSplit = Split(z, vbTab)

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


One would tend to suspect extra tabs in your input data.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6938433
The only problem that i can see is that there is not a real tab character.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6938434
Do this:
Create a little file with 2 lines and last one as its contents replacing every "tab" with a "real" one and try again.
I did a test with your code and works OK.

Public Sub LoadLog(Lv As ListView, strFile As String)
   Dim ff As Integer
   Dim strLine As String
   Dim strSplit
   Dim li As ListItem
   
   ff = FreeFile
   Open strFile For Input As #ff
   
   Do Until EOF(ff)
       Line Input #ff, strLine
       If strLine = "" Then Exit Do
       strSplit = Split(strLine, vbTab, , vbBinaryCompare)
       
       Set li = Lv.ListItems.Add(, , strSplit(0))
       Dim i As Integer
       For i = 1 To UBound(strSplit)
        li.ListSubItems.Add i, , strSplit(i)
       Next i
   Loop
   
   Close #ff
End Sub
0
 
LVL 22

Expert Comment

by:cookre
ID: 6938436
If your data really is clean, you might avoid Split() and do something like:

i=0
tp=instr(linein,vnTab)
while tp>0
      i=i+1
      field(i)=left(linein,tp-1)
      linein=substr(linein,tp+1)
      tp=instr(linein,vnTab)
      wend
field(i+1)=linein
0
 

Author Comment

by:jsm11482
ID: 6938445
thank you, good work!
-Josh
0
 
LVL 5

Expert Comment

by:kcm76
ID: 6939978
The question states that
**I am trying to split a log file and load it into a listview**. I suppose there should not be any extra tab.


..and what's wrong with my comment!!!. I had posted almost a similar thing what cookre did.



0
 

Author Comment

by:jsm11482
ID: 6940371
i accepted cookre's comment because he gave me actual code! Your was a good comment too though! ;-)
-Josh
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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