Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read from .txt file put into listview!

Status
Not open for further replies.

kalle82

Technical User
Apr 2, 2009
163
SE
Back again and on fire ;)

I ahve searched everywhere and come up with this codeee

This is what i have stored in a textfile

Code:
2011-06-30,Testing to read this string,2011-07-01

I use the code below to read it into a listview with three columns.

Problem is that in the first column it only reads the YEAR, and nothing else... I have tried and put like 20111111 in the textfile and it reads that aswell.. everything else is going okay!

Like this

Column1 Column 2 Column 3
2011 Testing to read this string 2011-07-01


Code:
Open filepath For Input As #1

    Do While Not EOF(1)
    
Input #1, date1, loggen, date2
'address2,
                  
        Set lvItems = UserForm1.ListView2.ListItems.Add
        lvItems.Text = date1
        lvItems.SubItems(1) = loggen
        lvItems.SubItems(2) = date2
       
    Loop
    
Close #1
 
Is the column wide enough?
You could try to declare input variables (date1, loggen, date2) as string. Check what you read (breakpoint, debug.print) from the file.

combo
 
Hi! Yes the column header says "Logganteckning" so the date is acctually less chars, so it should fit. Also (date1, loggen, date2) are declared as strings now. But it still does not work.. Im really confused because the file has the information, and everything after get read?!
 
I have tried to add more dates to the file, so now a fil written has this data:
Code:
2011-07-01,testing,2011-07-01,2011-07-01

I'm getting really frustrated. Cause when reading the values into from the textfile. I have problems reading the full date

first value gets read as: "2011"
second value is okay it gets read: in this case "testing"
third value: gets read in full "2011-07-01
fourth value: gets read as "2011"

So I ahve tried several things the value that get read okay comes directly from a calender control. Basicly I have done like this date2 = calender1.value, In order to get antoher date value to get read in full i tried with another calendercontrol. I have tried and designate the variable as date, as string. NOTHING works? Is there anyone who has hade the same problem?

 
Okay I have found the problem! The input will stop reading when it reaches a hyphen "-", if the part that it's reading is last.

That is why i get it to read the last date in full, but not the other...? So I need it to read through the hyphens and only stop for a comma, that way it will be correct ;)

anyone have a tips on how to do that in an easy way?
 
what about something like this ?
Code:
Open filepath For Input As #1
Dim strLine As String, arrInput
Do While Not EOF(1)
  Line Input #1, strLine
  arrInput = Split(strLine, ",")
  Set lvItems = UserForm1.ListView2.ListItems.Add
  lvItems.Text = arrInput(0)
  lvItems.SubItems(1) = arrInput(1)
  lvItems.SubItems(2) = arrInput(2)
Loop
Close #1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hey! Back from the weekend ;) wow Thanks PHV! I found another solution too.
i put the first value inside pound signs "#" that way reading it does not stop when it reeches a hyphen, it's recognized as a date value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top