Anthony's VBA Forum Index Anthony's VBA Forum
Where the knowledge is shared
Menu
 Anthony's VBA Forum IndexHome Page
 Anthony's VBA Forum IndexForum Index
FAQFAQ
MemberlistMemberlist
UsergroupsUsergroups
RegisterRegister
ProfileProfile
Log in to check your private messagesMessages
Log inLogin/Out

Quick Search

Advanced Search

Links
Consulting
Products

Who's Online
[ Administrator ]
[ Moderator ]


how can vb recogrite how many col we need to display??

 
Post new topic   Reply to topic     Anthony's VBA Forum Index -> Portfoilio Optimization
View previous topic :: View next topic  
Author Message
bshaen



Joined: 10 Jan 2005
Posts: 9
Location: malaysia

PostPosted: Fri Jan 14, 2005 5:51 am    Post subject: how can vb recogrite how many col we need to display?? Reply with quote

test.txt
1 A A Flute 1.00 1.00 1.00
2 A1 A1 FLUTE 1.00 0.00 1.00
3 AB AB Flute /Double Wall 1.00 2.50 1.00
4 ABC ABC Flute /Triple Wall 1.00 2.50 1.00
5 ABF ABF 0.00 0.00 1.00

test1.txt
1 A A Flute 1.00 1.00
2 A1 A1 FLUTE 1.00 0.00
3 AB AB Flute /Double Wall 1.00 2.50
4 ABC ABC Flute /Triple Wall 1.00 2.50
5 ABF ABF 0.00 0.00

i have write a program which is about vba-excel, read the text file and display the data into excel format.
that have successful to run the program, but the problem is whether that is possible to use the single program that able to know how many column of particular taxt file i want to import, and width of each col? the program is not read 2 text file concurrently, that is depend on user what text file they want to execute.

With xlsheet.QueryTables.Add(Connection:="TEXT;\\Admin1\C\test.txt", _
Destination:=Range("A1"))
.TextFileParseType = xlFixedWidth
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(5, 16, 34, 5)
.Refresh
End With
**that is the coding i done for the text file, we already know how many col that we need.

the problem now is we should assume we don't know how many column need for each text file's data to display on excel.
_________________
bshaen
Back to top
View user's profile Send private message
Data
Moderator
Moderator


Joined: 06 Oct 2004
Posts: 33
Location: NY

PostPosted: Fri Jan 14, 2005 11:31 am    Post subject: Reply with quote

Don't think too complicated. If your text file in delimited (ex: by space), you can that your program count how many spaces you have in the line of string. The number of space + 1 is your columns number.
_________________
Data
Knowledge is Power


Last edited by Data on Mon Jan 17, 2005 12:19 am; edited 1 time in total
Back to top
View user's profile Send private message
bshaen



Joined: 10 Jan 2005
Posts: 9
Location: malaysia

PostPosted: Sun Jan 16, 2005 9:32 pm    Post subject: Reply with quote

how the coding i can apply???
casue i know
.TextFileConsecutiveDelimiter = True
but i don't know how to specific to 2 space??? can u give me some idea of it? thank
_________________
bshaen
Back to top
View user's profile Send private message
Data
Moderator
Moderator


Joined: 06 Oct 2004
Posts: 33
Location: NY

PostPosted: Mon Jan 17, 2005 12:21 am    Post subject: Reply with quote

You can use the [b]instring[/b] function in VB that break the string into array. By counting how many arrays in generated in the string, you get the columns.
_________________
Data
Knowledge is Power
Back to top
View user's profile Send private message
bshaen



Joined: 10 Jan 2005
Posts: 9
Location: malaysia

PostPosted: Mon Jan 17, 2005 12:52 am    Post subject: Reply with quote

sorry, can u futher explain of the instring function with example???
_________________
bshaen
Back to top
View user's profile Send private message
Djamanbe
Guest





PostPosted: Wed Mar 29, 2006 5:58 pm    Post subject: Excel Parser Reply with quote

Thanks a lot Anthony for your clean parser example.

Jean-Marc Wink
Back to top
Display posts from previous:   
Post new topic   Reply to topic     Anthony's VBA Forum Index -> Portfoilio Optimization All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group