473,786 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read and display specific data from text file into listbox using VB 6

Mas Juliza Alias
67 New Member
Hi,

I am building a program on Information System for Reservoir Operation for my Masters research. Now I have a text file which is an output file from a processing software (Terramodel) that lists out Elevation Range and Volume in columns and rows. The text file looks like this;

-------------------------------------------------
-software's distributor address-
-project description-

Depth range Volume
(m) (m3)
0.000 > 0.001 10.0
0.001 > 0.002 12.0
. .
. .
. .

cummulative volume
(m3)
500
-------------------------------------------------

now i've written the code to display the data in listbox using AddItem, but the whole lines are displayed in one single line in the listbox. I want to display only the Depth Range and Volume data, starting from '0.000 > 0.001'. So, how to skip reading the file header (software's distributor address & project description) and the data column's header (Depth range (m) & Volume (m3))?

Thank You for your time.
Sep 24 '10 #1
21 10144
Guido Geurs
767 Recognized Expert Contributor
I hope this will help.
(see also attachment)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim FILEIN As Integer
  3. Dim INPUTTEXT As String
  4. Dim COUNTER As Integer
  5.    FILEIN = FreeFile()
  6.    On Error GoTo Error_Open_File
  7.    Open App.Path & "\test.txt" For Input As #FILEIN
  8.       Do Until EOF(FILEIN)
  9.          Line Input #FILEIN, INPUTTEXT
  10.          If InStr(INPUTTEXT, ">") Then List1.AddItem (INPUTTEXT)
  11.       Loop
  12.    Close #FILEIN
  13. Exit Sub
  14. Error_Open_File:
  15.    Close #FILEIN
  16.    MsgBox "There is an error opening the file"
  17. End Sub
Sep 24 '10 #2
Mas Juliza Alias
67 New Member
hi ggeu,

tq, that works nicely. but still, there is a problem in that. it reads only the depth range, not the volume (value 10.00, next to 0.000 > 0.001). 1 more thing, how can i separate the values before and after the symbol ">" in different columns? the final display should be in 3 columns, 1) initial depth, before ">", 2) end depth, after symbol ">", and 3) volume. all three columns need to be declared into three variables perhaps in arrays, because it will be used in later process. how can i do this?

your help is most appreciated, TQ.
Sep 27 '10 #3
Guido Geurs
767 Recognized Expert Contributor
I hope this will help:
If You want a table with Columns, than You have to use a Grid. (see attachment).
You can use a array to split the inputtext and use "AddItem" to place the different parts from the array in the grid.
Sep 28 '10 #4
Mas Juliza Alias
67 New Member
it works on your test.txt file.but it failed on my text file. i've attached my file here.i think the problem is the data in this file is not saparated by a fixed space.

thanx for ur help,
Mas Juliza
Attached Files
File Type: txt VOL.txt (71.3 KB, 650 views)
Oct 1 '10 #5
Guido Geurs
767 Recognized Expert Contributor
The code "Split" can be used if there is only 1 space between the data.
Here we have to use the "Mid" code but then the data must always be on the same place !!!

Is this the case in all the documents You have to Analise ??

If not, we have to find an other way to isolate the data in the TXT file.

Attached is a program with "Mid" code.
Oct 1 '10 #6
Mas Juliza Alias
67 New Member
that works great to saparate the data in columns. but that's not a standard case. they are not fixed. here's the code with another data file (attached) that cannot be read correctly.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim InputText As String
  3.     Dim FileNum As Integer
  4.     Dim Depth1 As Double
  5.     Dim Depth2 As Double
  6.     Dim FillVol As Double
  7.     Dim CutVol As Double
  8.     With MSFlexGrid1
  9.     'Set grid
  10.     .FixedCols = 0
  11.     .Cols = 4
  12.     .FixedRows = 1
  13.     .Rows = 1
  14.     .TextMatrix(0, 0) = "Initial Depth"
  15.     .TextMatrix(0, 1) = "End Depth"
  16.     .TextMatrix(0, 2) = "Cut Volume"
  17.     .TextMatrix(0, 3) = "Fill Volume"
  18.     'Fill Grid
  19.     FileNum = FreeFile()
  20.     On Error GoTo Error_Open_File
  21.     Open App.Path & "\cubic.txt" For Input As #FileNum
  22.     Do Until EOF(FileNum)
  23.         Line Input #FileNum, InputText
  24.         InputText = Trim(InputText)
  25.         If InStr(InputText, ">") Then
  26.             MSFlexGrid1.AddItem Mid(InputText, 1, 6) & vbTab & _
  27.             Mid(InputText, 10, 6) & vbTab & Mid(InputText, 32, 4) & _
  28.             vbTab & Mid(InputText, 50, 4)
  29.         End If
  30.     Loop
  31.     Close #FileNum
  32.     End With
  33. Exit Sub
  34. Error_Open_File:
  35.     Close #FileNum
  36.     MsgBox "There is an error opening the file"
  37. End Sub

how can i isolate the data and asign them into variables in arrays? these data will be used in later operation to generate graph, so i need to have them in variables as Double.

your helps are most appreciated.
Attached Files
File Type: txt cubic.txt (2.0 KB, 482 views)
Oct 4 '10 #7
Guido Geurs
767 Recognized Expert Contributor
is it always the "Cut volume" OR "Fill Volume" ?
Not the 2 in the same line ??

I have modified the code so it can read any file, if there is a value or not or when the columns are on an other place.
The data is also placed in an array (as double).

How it works:

The data lines of the textfile are read in a textbox.
On the textbox You have to place the column separators by typing the value or clicking on the arrows (left= down, right= up)(default I have set it to 40 and 60 but You can change it if the most of Your documents have an other layout)

The separators must be placed in the spaces between 2 data for each line.

If there is a line in which the separator is in the data, You can modify the line in the textbox by adding or deleting spaces (we use this data from the textbox and not from the file for filling the array and the grid)

click on "Fill Grid" to see the data (and also in the array because it's captured from it)
Oct 4 '10 #8
Mas Juliza Alias
67 New Member
WOW! you're such an expert! you creatively solve the problem. the code works very well. it seems complicated and takes time for me to understand line by line. however there is 1 problem here, the same values in both TextBox (TextEdit) and MSFlexGrid1 are not the same. for example, value 5.000 in TextEdit becomes 5000 in the grid. i don't know how to edit your code because it is beyond my basic VB knowledge.

tq for your time.
Nov 2 '10 #9
Guido Geurs
767 Recognized Expert Contributor
Now You are highly pleased with the concept, we can go on with the tuning-up of the program.

I have attached the next step:
- with some more explanation on each step in the code.
- the cells in the grid are now Strings, any objection?

Still to do:
- We don't want to edit the VB code if we want to open an other Datafile! therefor we have to implement the CommonDialog so the user can browse and select a Datafile.
- The default value of the ColSeparator must be saved.

Do You agree with this? §;o)>
Nov 2 '10 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3161
by: sachin10 | last post by:
hi i m sachin, i m new to VB programming.i face some problem regarding the sorting of text file contents using arrays.text file have data in the format as below seq |consumerid|status1|status2|meter no1|meter no2|nameof consumer|routeno 234133210003040002222222222000003333333123098sasdcscasdsadsd9041 231433104000267232222278222000003333333123098shskdfkscasdsade9012 this is the format of text file.there are thosands of records in this...
1
2200
by: christine0207 | last post by:
Hi, how to generate a fixed length data text file using Scripting.TextStream / filesystemobject.
2
1354
by: JMG | last post by:
Hi All, I have no idea if this is the correct place to post this question, but I'm hoping so :). My problem is that I have a text file containing 5 sets of passwords on a single line space delimited line, which is used to change passwords on a daily basis via DOS batch files (don't get me started on why we have to do it this way, we just do...>:) ) ie Monpassword Tuepassword Wedpassword Thurpassword Fripassword in passwords.txt
2
5519
by: RyanS09 | last post by:
Hi- I have read many posts with specific applications of reading in text files into arrays, however I have not been able to successfully modify any for my application. I want to take a text file filled with a tab delimited list of 10 columns (floats) and read it into a 2D array. The length of the columns are all the same, however this will be variable from text file to text file. Any help (starter code or where to read) would be much...
2
3380
by: JB | last post by:
I'm trying to read a text file, and store the position of a specified line, and then later seek back to that line and start reading again. I'm using simple code like the following: StreaReader sr = new StreamReader("test.txt"); String s = ""; while (S != null) { S = sr.ReadLine()
1
1728
by: Paul Lemelle | last post by:
I am trying to read in a text file then use the data in the file. I know how to read a file wiht the System.IO namespace: FileRead fr = new StreamReader("data.txt"); Console.Writeline(fr.Readline()); or StreamReader fr = File.OpenText("Data.txt");
3
7405
by: printline | last post by:
Hello All I need a little help with a phph script to display some specific data from a mysql table. I have a mysql table with 4 columns and 10 rows. I want to display fx. data from row 4, 6, 8 and 10. I can display either the first row or all the rows using the below code: $row = mysql_fetch_array($result) or die(mysql_error()); echo $row. " - ". $row. " <img src=images/arlon.jpg /> ". $row. " - ". $row;
1
1680
by: MiziaQ | last post by:
How can I delete a row of data from a data/text file in vb6 ? I am using an MSFlexGrid, so the user can select which row is to be deleted. Thanks in advance, MiziaQ
13
10454
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another set of integers stored in an array.It would be a great help if you could provide some code for it.I tried the function fscanf but by that I am able to read only the first integer of the text file.Please help me.
0
1999
by: rahulsapra | last post by:
hello everyone m new to j2me plzz help I have a text file that contains data line by line.. format is : response:<some text><space>Pin:<some text><space>time:<hh:mm:ss> eg response:invalid pin Pin:1111 time:04:04:16
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.