Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > Visual Basic

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-17-2008, 11:39 AM
Per Juul Larsen
 
Posts: n/a
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


Reply With Quote
  #2 (permalink)  
Old 08-17-2008, 02:37 PM
Reverend Fuzzy
 
Posts: n/a
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.dk> wrote in message
news:8244c$48a7fff0$57486c0a$3591@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
>
>



Reply With Quote
  #3 (permalink)  
Old 08-17-2008, 04:40 PM
Per Juul Larsen
 
Posts: n/a
Re: read and write variables from textfile

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
Reply With Quote
  #4 (permalink)  
Old 08-17-2008, 11:30 PM
Reverend Fuzzy
 
Posts: n/a
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.dk> wrote in message
news:e2e7e$48a84654$57486c0a$31366@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



Reply With Quote
  #5 (permalink)  
Old 08-18-2008, 02:03 AM
Raoul Watson
 
Posts: n/a
Re: read and write variables from textfile

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

Reply With Quote
  #6 (permalink)  
Old 08-18-2008, 10:00 AM
Per Juul Larsen
 
Posts: n/a
Re: read and write variables from textfile

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
Reply With Quote
  #7 (permalink)  
Old 08-18-2008, 10:08 AM
Per Juul Larsen
 
Posts: n/a
Re: read and write variables from textfile

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 juul@larsen.dk

kind regards pjl
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > Visual Basic


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:00 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Mobile Phones | Electricity Suppliers | Mortgage Calculator | Credit Cards | Debt Consolidation



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114