473,503 Members | 3,171 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 7055
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,read3,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.dkwrote in message
news:82**************************@news.comxnet.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,read3,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.PartDescription

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.dkwrote in message
news:e2***************************@news.comxnet.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,read3,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.txt" 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.txt" 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\public\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.PartDescription

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
1781
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...
18
4855
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)...
8
30981
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
1090
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...
2
1602
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...
0
970
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...
0
3838
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...
6
7249
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...
0
1808
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...
0
7063
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...
0
7313
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...
1
6970
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...
0
7441
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...
0
5558
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,...
1
4987
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...
0
1489
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 ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
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...

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.