Solved

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

Posted on 2002-04-12
10
227 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
Industry Leaders: 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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 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