![]() |
|
|
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. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
|
|||
|
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 > > |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|