473,793 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

read and write variables from textfile

Hi.
My Textfile looks like this

Variable 1
Variable 2
Variable 3
Variable 4

On opening the application it will read the textfile, and assign each
line of variable to at textfield in VB and then close the file.
How can I do this
Aug 17 '08 #1
6 7072
There's a trick to it... just in case you're a student
trying to get us to do his homework for him, I'll not
give you actual code... but I'll tell you the secret....

Read it in the same way you wrote it, same variable
types and all. open, read1,read2,rea d3,read4,close.

Now assuming you're not a cheating student, you
should now have all the information you need.

If you're NOT a cheating student, e-mail me a
copy of your ID, to prove it, and I'll send you some
actual code. :)

--
Reverend Fuzzy
Panama City, FL
re************@ msbdatasystems. com
http://www.msbministries.org
"Per Juul Larsen" <ju**@larsen.dk wrote in message
news:82******** *************** ***@news.comxne t.dk...
Hi.
My Textfile looks like this

Variable 1
Variable 2
Variable 3
Variable 4

On opening the application it will read the textfile, and assign each
line of variable to at textfield in VB and then close the file.
How can I do this


Aug 17 '08 #2
Reverend Fuzzy skrev:
There's a trick to it... just in case you're a student
trying to get us to do his homework for him, I'll not
give you actual code... but I'll tell you the secret....

Read it in the same way you wrote it, same variable
types and all. open, read1,read2,rea d3,read4,close.

Now assuming you're not a cheating student, you
should now have all the information you need.

If you're NOT a cheating student, e-mail me a
copy of your ID, to prove it, and I'll send you some
actual code. :)
Thank You for a kind answer. No I am not a student. I am retired long
ago.(65) Just try to keep up what I have lost long ago. I used to open
file for input to a textbox or array etc... but wondering if there is an
easier way to do it.
thanks
regards pjl
Aug 17 '08 #3
You may want to consider using a data structure.
There's a tiny bit more setup, but it will allow you
to read/write all your variables in one shot, as
opposed to multiple reads/writes.

As an example, I had written an appliance parts
database a long time ago, in regular BASIC, in
which I DIMmed my variables, as such....

DIM A As String * 32
DIM B As String * 32
(originally longer list)

then did a PRINT# x, A : print# x, A to write
and/or a LINEINPUT #x, A : LINEINPUT #x, B
to read it back.

When I found my original source code, and started
converting it to VB6, I changed to a structure, so I
started with setting up a record variable...

Public Type Record
PartNumber As String * 32
PartDescription As String * 32
End Type

and ...
Dim r As Record

Then, I was able to open the database file at the start
of the program via an Open App.Path + "\db.pdb" For Random As #dBase Len =
Len(r)
which would allow me to SEEK directly to a specified
record number, and do a PUT #x, ,r or GET #x, r to
read or write the data, which was then accessed
as r.PartNumber or r.PartDescripti on

Am I going too fast for you? If you'd like a copy of the final code
to disassemble, and learn from, send me an e-mail, and I'll
reply with a .zip of it in an attachment.

--
Reverend Fuzzy
Panama City, FL
re************@ msbdatasystems. com
http://www.msbministries.org
"Per Juul Larsen" <ju**@larsen.dk wrote in message
news:e2******** *************** ****@news.comxn et.dk...
Reverend Fuzzy skrev:
>There's a trick to it... just in case you're a student
trying to get us to do his homework for him, I'll not
give you actual code... but I'll tell you the secret....

Read it in the same way you wrote it, same variable
types and all. open, read1,read2,rea d3,read4,close.

Now assuming you're not a cheating student, you
should now have all the information you need.

If you're NOT a cheating student, e-mail me a
copy of your ID, to prove it, and I'll send you some
actual code. :)
Thank You for a kind answer. No I am not a student. I am retired long
ago.(65) Just try to keep up what I have lost long ago. I used to open
file for input to a textbox or array etc... but wondering if there is an
easier way to do it.
thanks
regards pjl

Aug 17 '08 #4
Per Juul Larsen wrote:
Hi.
My Textfile looks like this

Variable 1
Variable 2
Variable 3
Variable 4

On opening the application it will read the textfile, and assign each
line of variable to at textfield in VB and then close the file.
How can I do this
I may be missing something but would this work?
Open "yourfile.t xt" for input as #3

input #1, text1.text
input #2, text2.text
input #3, text3.text
input #3, text4.text

close #3

Aug 18 '08 #5
Raoul Watson skrev:
Per Juul Larsen wrote:
>Hi.
My Textfile looks like this

Variable 1
Variable 2
Variable 3
Variable 4

On opening the application it will read the textfile, and assign each
line of variable to at textfield in VB and then close the file.
How can I do this

I may be missing something but would this work?
Open "yourfile.t xt" for input as #3

input #1, text1.text
input #2, text2.text
input #3, text3.text
input #3, text4.text

close #3
Thank You

I saw the light...

I read line by line until it comes to end of the file like this
Dim a, b, c, d
Open "C:\users\publi c\temp\ok.txt" For Input As #1

While Not EOF(1)
Line Input #1, a
Text1.Text = a
Line Input #1, b
Text2.Text = b
Line Input #1, c
Text3.Text = c
Line Input #1, d
Text4.Text = d

Wend
Close #1

regards pjl
Aug 18 '08 #6
Reverend Fuzzy skrev:
You may want to consider using a data structure.
There's a tiny bit more setup, but it will allow you
to read/write all your variables in one shot, as
opposed to multiple reads/writes.

As an example, I had written an appliance parts
database a long time ago, in regular BASIC, in
which I DIMmed my variables, as such....

DIM A As String * 32
DIM B As String * 32
(originally longer list)

then did a PRINT# x, A : print# x, A to write
and/or a LINEINPUT #x, A : LINEINPUT #x, B
to read it back.

When I found my original source code, and started
converting it to VB6, I changed to a structure, so I
started with setting up a record variable...

Public Type Record
PartNumber As String * 32
PartDescription As String * 32
End Type

and ...
Dim r As Record

Then, I was able to open the database file at the start
of the program via an Open App.Path + "\db.pdb" For Random As #dBase Len =
Len(r)
which would allow me to SEEK directly to a specified
record number, and do a PUT #x, ,r or GET #x, r to
read or write the data, which was then accessed
as r.PartNumber or r.PartDescripti on

Am I going too fast for you? If you'd like a copy of the final code
to disassemble, and learn from, send me an e-mail, and I'll
reply with a .zip of it in an attachment.
hi

Sometimes the answer is right in front of you and you can not see it!!!!.
Thank you for your reply ... I have solved the task by reading the text
file and then line by line store the line to variables and then insert
them in the application.
my email is ju**@larsen.dk

kind regards pjl
Aug 18 '08 #7

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

Similar topics

19
1809
by: Arthur | last post by:
Did I hallucinate something about __name__ becoming read-write? Not in alpha2. Can't find the reference to this I thought I read - that it was concluded to be necessary in connection with PEP318. Better get my facts straight first.... But if true that would seem to solve the main objection to:
18
4894
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
8
31014
by: Patrik Malmström | last post by:
How do I read, write a file binary? I want to open, say, file.exe read it in to the program, then write it out to file2.exe. Like file copy, anyone have a code sample?
2
1105
by: Sam | last post by:
Hi guys If I have to read/write a text file which has the following format, what would be the best way to read it? Should I readline method of the streamreader to a string variable and parse it to the format below? 1 0.000016 7.999882 0.000000 2 1.000013 7.999875 0.000000 Many thanks
2
1614
by: dumbo | last post by:
Hello, who gives one more shining solution to me? My application load form "A". The form "A" by means of a push-button load form "B" that in its turn by means of a push-button load form "C". Form "B" contains one variable "Private" "VarB". How I can read the value of "VarB" from form "C"? All the form come loaded with the following brace of instructions: Sub Button2_Click(ByVal sender As System.Object, ByVal and As System.EventArgs)...
0
1008
by: jwtulp | last post by:
Hello, I have a question about XmlSerialization. I have a class with a private field called createDate of the type DateTime. In the constructor of my class I use DateTime. Now to create a timestamp that is assigned to the field createDate. Because I want to encapsulate as much as possible of my class data and don't want clients of my class to change the createDate but only read it, I encapsulate the createDate field with a get Property....
0
3871
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the string. write method should take a string. seek should take a number and return nuthing. use three member variables a buffer itself as a string, read_position, write_position. use >>, << methods. I have tried this code but i need full...
6
7282
by: Ryan Liu | last post by:
Hi, I have some basic question about NetworkStream, can someone explain to me? Thanks a lot in advance! TcpClient has a GetStream() method return a NetworkStream for read and write. I remember there are 2 streams in Java, one for read, one for write. If I just use synchronous Read() and Write() method:
0
1827
by: Brian Pinto | last post by:
Im facing a problem with file stream read/write for a usb device. The code works fine on XP (32 bit). but fails to work on Windows 7 (64 bit). I'm successfully past problem of getting the device to enumarate and getting the file handle However the fileStream Read/Write doesn't work I used the managed file stream method i.e first create a handle via native call in overlapped mode. Then use the handle to get a FileStream object and perform...
0
9518
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,...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.