Solved

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

Posted on 2002-04-12
13
202 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
Technology Partners: 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!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Suggested Courses
Course of the Month4 days, 11 hours left to enroll

636 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