Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 3:40 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ]  Bookmark and Share
Author Message
 Post subject: What function do I use to link data from a .txt file to Exce
PostPosted: Mon Oct 06, 2008 10:51 am 
Offline

Joined: Mon Oct 06, 2008 10:48 am
Posts: 6
I have a large amount of data to manipulate in .txt format.

i want to be able to specify sections of data from the text file and import chunks of it into excel for further manipulation.

What VB function can i use to do this??

Many thanks for nay help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 11:19 am 
Offline

Joined: Tue Sep 09, 2008 2:07 pm
Posts: 16
Hi,

I assume you have a specific format to your .txt file. If it has then you need to

1. read the file line by line using Line Input function

2. split each line to columns, store it temp into variables or array (functions needed : instr, mid etc.)

3. Use microsoft excel object library to create workbook and sheets

4. add rows and columns to excel sheet.

You can find lot of code to handle excel sheets through vb on http://www.planetsourcecode.com.

Cheers

_________________
Manoj Shinde
My Command Button ActiveX | My Frame Panel ActiveX | My Screen Capture ActiveX


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 11:48 am 
Offline

Joined: Mon Oct 06, 2008 10:48 am
Posts: 6
thanks alot for that,

another quick query, am i right in thinking i can use this to add a new connection to a .txt file?:

.Add(Connection:="TEXT;C:\My Documents\19980331.txt", _
Destination:=shFirstQtr.Cells(1, 1))

and once i have done this i can use the Line Input fucntion to read the data in the .txt file?

how can i then specify the parts of the .txt file i need to manipulate in excel?

as you can tell im not very experienced with VB so any help is much appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 12:04 pm 
Offline

Joined: Tue Sep 09, 2008 2:07 pm
Posts: 16
Can you show me sample of your text file?

_________________
Manoj Shinde
My Command Button ActiveX | My Frame Panel ActiveX | My Screen Capture ActiveX


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 12:30 pm 
Offline

Joined: Mon Oct 06, 2008 10:48 am
Posts: 6
yeah sure:

TIME COMP TYPE COMP ID VOLT(kV) CURNT(kA) PWR(MW) MVAR MVA
08:00:00 Elec Sect -ES60 0.7789 0.0000 0.000000 0.000000 0.000000
08:00:00 Elec Sect +ES61 0.7810 0.0000 0.000000 0.000000 0.000000
08:00:00 Elec Sect -ES13 0.7768 0.0000 0.000000 0.000000 0.000000
08:00:00 Elec Sect -ES52 0.7760 0.0000 0.000000 0.000000 0.000000
08:00:00 Elec Sect -ES56 0.7785 0.0694 0.054019 0.000000 0.054019

its about 40KB of data like this. Although the only data i need to transfer to Excel are the Volt(Kv) column and the Time column. Can i set some parameters in VB to do this??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 12:37 pm 
Offline

Joined: Tue Sep 09, 2008 2:07 pm
Posts: 16
I can see that space is the only thing seperating them so use Split function with delimiter as space to split the liine into an array

arrayvar = split(stringline," ")

this will give you a row of data and you can then read a column like

x = arrayvar(0) and so on

_________________
Manoj Shinde
My Command Button ActiveX | My Frame Panel ActiveX | My Screen Capture ActiveX


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 2:23 pm 
Offline

Joined: Mon Oct 06, 2008 10:48 am
Posts: 6
superb, so i can go across the columns and choose which one si want like so:

x = arrayvar(1,3)

so ultimately i need to be able to specify which rows i need to transfer as well, eg, i need to transfer all the data that ocurred at time 08:00:00.

do i have to write two statements to seperate the data in the vertical (columns) and horizontal (rows)??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 3:59 pm 
Offline

Joined: Tue Sep 09, 2008 2:07 pm
Posts: 16
no,

pseudo code would be like

while eof(1)
strline = line input(#1)

strarray = split(strline," ")

print strarray(0)
end loop

the array will be a row at a time and not matrix.

_________________
Manoj Shinde
My Command Button ActiveX | My Frame Panel ActiveX | My Screen Capture ActiveX


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 5:04 pm 
Offline

Joined: Mon Oct 06, 2008 10:48 am
Posts: 6
Many thnaks, i think i'm on the right track now.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 5:23 pm 
Offline

Joined: Tue Sep 09, 2008 2:07 pm
Posts: 16
Most welcome

All the forum members will always help you.

_________________
Manoj Shinde
My Command Button ActiveX | My Frame Panel ActiveX | My Screen Capture ActiveX


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley