Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 14th, 2005, 01:06 PM
QHjr QHjr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 3 QHjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question VBA: reading part of CSV Line

As always, your assistance in gr8ly appreci8d:
I am trying to parse part of a CSV file for to populate a comobo box:


DATA.csv contains:
bob,NY,123 Main Street

Carol,London,1313 Mockingbird Lane
Alice,Paris, 345 Rue Morgue

Code:
Open "DATA.csv" For Input As #1

Line Input #1, lne$ 'discard header/first row of csv file
Do While Not EOF(1)
Line Input #1, lne$
ComboOffice.AddItem lne$
Loop
Close #1

Although I can use this to populate the Combobox it captures the entire line.

How would I capture just the 2nd field (ie LONDON, NY, PARIS)??

thanks in advance

Reply With Quote
  #2  
Old January 14th, 2005, 01:30 PM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
Hi,

try using this code:
Code:
  Line Input #1, lne$
 
 strTemp = lne$
 
 strPlace = Split(strTemp,",")
 
  ComboOffice.AddItem strPlace(1)
 


That should give you the second value ie, Paris,NT etc.

hope this helps

Reply With Quote
  #3  
Old January 14th, 2005, 02:00 PM
QHjr QHjr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 3 QHjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanx nofriends, that sounded like 'mana', but

when I applied that code I keep getting a
Runtime error: 9; Subscript out of range
What am I missing?


Quote:
Originally Posted by nofriends
Hi,

try using this code:
Code:
Line Input #1, lne$
 
strTemp = lne$
 
strPlace = Split(strTemp,",")
 
ComboOffice.AddItem strPlace(1)


That should give you the second value ie, Paris,NT etc.

hope this helps

Reply With Quote
  #4  
Old January 14th, 2005, 03:13 PM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1Folding Points: 106940 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
Hi,
that means that there is nothing in the array which means there is nothing in lne$?

Or that there are no commas in lne$.

what happens when u reponse.write lne$?

It should work if there are values in lne$ with commas, quite strange.

Our webserver is unpredictable at the moment so if I don't post again for a while, don't take it personally

Hope you get it sorted.

--Try using a Dim statement with strPlace and strTemp,
and try putting something like "test,test1," into strTemp and see what happens.

Reply With Quote
  #5  
Old January 15th, 2005, 09:38 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
What do you see when you step through your code with the debugger?
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #6  
Old January 20th, 2005, 09:21 PM
QHjr QHjr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 3 QHjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That did it!

Still not sure why this didnt work initially but it's working now. I was running the code on word2000 system initially, but am now running it on XP...Is strTemp version specific?
Anyways, thanks to you both for the help!

Quote:
Originally Posted by nofriends
Hi,
that means that there is nothing in the array which means there is nothing in lne$?

Or that there are no commas in lne$.

what happens when u reponse.write lne$?

It should work if there are values in lne$ with commas, quite strange.

Our webserver is unpredictable at the moment so if I don't post again for a while, don't take it personally

Hope you get it sorted.

--Try using a Dim statement with strPlace and strTemp,
and try putting something like "test,test1," into strTemp and see what happens.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > VBA: reading part of CSV Line


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT