Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 17th, 2008, 11:45 AM
Per Juul Larsen
Guest
 
Posts: n/a
Default 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


  #2  
Old August 17th, 2008, 02:45 PM
Reverend Fuzzy
Guest
 
Posts: n/a
Default Re: read and write variables from textfile

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
reverend.fuzzy@msbdatasystems.com
http://www.msbministries.org


"Per Juul Larsen" <juul@larsen.dkwrote in message
news:8244c$48a7fff0$57486c0a$3591@news.comxnet.dk. ..
Quote:
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
>
>

  #3  
Old August 17th, 2008, 04:45 PM
Per Juul Larsen
Guest
 
Posts: n/a
Default Re: read and write variables from textfile

Reverend Fuzzy skrev:
Quote:
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
  #4  
Old August 17th, 2008, 11:35 PM
Reverend Fuzzy
Guest
 
Posts: n/a
Default Re: read and write variables from textfile

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
reverend.fuzzy@msbdatasystems.com
http://www.msbministries.org


"Per Juul Larsen" <juul@larsen.dkwrote in message
news:e2e7e$48a84654$57486c0a$31366@news.comxnet.dk ...
Quote:
Reverend Fuzzy skrev:
Quote:
>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

  #5  
Old August 18th, 2008, 02:05 AM
Raoul Watson
Guest
 
Posts: n/a
Default Re: read and write variables from textfile

Per Juul Larsen wrote:
Quote:
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

  #6  
Old August 18th, 2008, 10:05 AM
Per Juul Larsen
Guest
 
Posts: n/a
Default Re: read and write variables from textfile

Raoul Watson skrev:
Quote:
Per Juul Larsen wrote:
Quote:
>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
  #7  
Old August 18th, 2008, 10:15 AM
Per Juul Larsen
Guest
 
Posts: n/a
Default Re: read and write variables from textfile

Reverend Fuzzy skrev:
Quote:
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 juul@larsen.dk

kind regards pjl
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles