Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual 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 Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old October 25th, 2003, 07:28 PM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Question How to plit a textfile and save in database?

Hello!
I'm working with a dimensioning program which writes output as textfiles. The program is made with Basic and later a user interface has been made with VB. I'm trying to make a DataReport and I have to split the textfiles, convert the strings to numbers and find the data I need. The ouputfile looks like this:

COMBINATION 1
1 0.00 0.0000E+00
2 600.00 1.9440E+04
2 600.00 1.9439E+04
3 1200.00 3.4560E+04
3 1200.00 3.4560E+04
4 1800.00 4.5360E+04
4 1800.00 4.5360E+04
5 2400.00 5.1840E+04
5 2400.00 5.1840E+04
6 3000.00 5.3999E+04
6 3000.00 5.3999E+04
7 3600.00 5.1840E+04
7 3600.00 5.1840E+04
8 4200.00 4.5360E+04
8 4200.00 4.5360E+04
9 4800.00 3.4561E+04
9 4800.00 3.4560E+04
10 5400.00 1.9441E+04
10 5400.00 1.9440E+04
11 6000.00 2.5000E-01

COMBINATION 2
1 0.00 0.0000E+00
2 600.00 1.9441E+04
2 600.00 1.9437E+04
3 1200.00 3.4559E+04
3 1200.00 3.4558E+04
4 1800.00 4.5357E+04
4 1800.00 4.5360E+04
5 2400.00 5.1841E+04
5 2400.00 5.1838E+04
6 3000.00 5.3998E+04
6 3000.00 5.3999E+04
7 3600.00 5.1840E+04
7 3600.00 5.1840E+04
8 4200.00 4.5361E+04
8 4200.00 4.5362E+04
9 4800.00 3.4563E+04
9 4800.00 3.4562E+04
10 5400.00 1.9444E+04
10 5400.00 1.9439E+04
11 6000.00 0.0000E+00

COMBINATION 3
1 0.00 2.5000E-01
2 600.00 1.1664E+06
2 600.00 1.1664E+06
3 1200.00 2.0736E+06
3 1200.00 2.0736E+06
4 1800.00 2.7216E+06
4 1800.00 2.7216E+06
5 2400.00 3.1104E+06
5 2400.00 3.1104E+06
6 3000.00 3.2400E+06
6 3000.00 3.2400E+06
7 3600.00 3.1104E+06
7 3600.00 3.1104E+06
8 4200.00 2.7216E+06
8 4200.00 2.7216E+06
9 4800.00 2.0736E+06
9 4800.00 2.0736E+06
10 5400.00 1.1664E+06
10 5400.00 1.1664E+06
11 6000.00 0.0000E+00

This is just a small part of the file, there can be up to 28 differnet combinations depending on the case. There is a empty line between every combination. The number of rows are also varying depending on the case, but are the same in every combination.
As you can see, all the other rows than the first and the last are written twice. I attached the hole file.

I'm wondering if I have to convert/save this data to a Access-file to solve my task. (Excel would be a nice option thanks to the graphing tools.) (And how to do it?) I have to find the combinations with the max. and min. values and make a graph that shows them both. Now I'm talking about the third column. The columns are delimited with spaces. How can I find these values and then select the whole combination? I also need the values in the second column to use on the x-axis. I don't need the numbers in the first column. What comes to the rows that are written twice, I only need to use every value one time.

You never know on which rows the max. and min. values are in the combinations. In the example I wrote the max values where in the middle. Its depending on the structure that is being analyzed. In my example the min. values where 0 in all combinations. It was the first and the last values. If there are no negative values I don't have to look for the min. value because it's always 0 in the end of the structure. In some cases there will be negative values.


I have tried to make the graph by manually copying (copy+paste) the values to a database and then "connecting" the graph to the database. After making the database manually I got VB to make the graph. At least I know it's possible to make the graph in VB. I need the graph in my DataReport. I was thinking of saving the graph as a picture and then adding it to the report. I also found a code to save the graph as a picture... This is how I have planned this. I know that Excel has better graphing tools than VB. Is this possible to do in Excel?

What I need now is a "operation" that splits the strings and gives the two combinations with max and min values. I guess it wood be best to save only the two combinations I need into database.

How should I get started? I'm not so good with the code.

Sorry for this long message, it's not easy to give a brief overview when your english as bad as mine. I hope someone understood what I ment....

This is quite a problem to solve and I'm just a beginner, so please make your explanations as simple as possible. (Or examples with explanations)

Thank You!

Reply With Quote
  #2  
Old October 26th, 2003, 12:26 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
I recommend u to use filesystem object in the MS vbscript object for your task which spliting the string into some string segments..

'define the filesystem object & string variable
dim fso as new filesytem
dim texto as textstream
dim strline as string
dim arrline() as string

'open your text file
set texto=fso.opentextfile("your file path")
'read the content of the text file
while not texto.EOF
'read each line
strlin=texto.readline
'split the string of the line into string array
arrline=spilt(strline," ")
'display the message to U
msgbox arrline(1) & " " & arrline(2)
'do your work(like add it to the db)
.....
loop

'close the text file
texto.close

'release the filesystem object
set texto=nothing
set fso=nothing

Reply With Quote
  #3  
Old October 26th, 2003, 07:05 AM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Thanks for your help!
I get a Compile error: "User-defined type not defined" when I try to test your code. It doesn't like this line: "dim fso as new filesytem " Should I add a reference and in that case which one is it? Do you know what's wrong?

Reply With Quote
  #4  
Old October 26th, 2003, 08:21 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Plz Add ms script runtime reference to the project's ..Do it:click project menu->open reference->find ms scripting runtime->add it!!

Reply With Quote
  #5  
Old October 26th, 2003, 08:37 AM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I added it but I still got the same error. What now?

Reply With Quote
  #6  
Old October 26th, 2003, 09:58 AM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Ok, now i fixed that problem. I had just typed something wrong.

But I'm still not getting right. What's the difference with FileSystem and FileSystemObject?

Dim fso As New FileSystem didn't work so I had to change it to Dim fso As New FileSystemObject, and no there's something wrong with this: While Not texto.EOF
I get a Compile error: Method or data member not found.

I really don't know what to do

Reply With Quote
  #7  
Old October 26th, 2003, 11:38 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Sorry!I have a mistake for spell..I will modify the statement:While Not texto.EOF-->While Not texto.AtEndOfStream...U can find this property in the vb help or msdn...

Reply With Quote
  #8  
Old October 27th, 2003, 11:37 AM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
No more errors but still need help

Thanks!
Now I got the errors fixed, but I don't know how to create the db and get the right data into the right fields. Can you please help me? The first field should be the second column in my example, the one that starts with 0.00. The rest 28 fields should contain the combinations, the values from the third column in my example. I need every row only once, not like in the example. I will attach the textfile for you to see.

Thanks for all the help!

Regards, Knappe

Reply With Quote
  #9  
Old October 27th, 2003, 06:54 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Sorry,I have a lot of work just now.If u is a vb&DB beginner,u can visit some tutorials on the network.like it:http://www.functionx.com/vbaccess/index.htm
If u have any question,u can give me private message or communicate me with msn(My msn:Great_liudan@hotmail.com)..Best regard to u!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How to plit a textfile and save in database?


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 2 hosted by Hostway