Solved

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

Posted on 2002-04-12
10
223 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

759 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

25 Experts available now in Live!

Get 1:1 Help Now