|
|
#1 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Hey all,
I am having trouble trying to read/write to/from a text file to/from multiple text boxes. What I would like to do is write each texbox to a seperate line in a text file like this... Text1 - line #1 Text2 - line #2 Text3 - line #3 and so on... and then I would like to read each line into a different textbox, like this... line #1 - Text1 line #2 - Text2 line #3 - Text3 Any help would be appreciated, Ron Last edited by rdcody; May 27th, 2005 at 04:58 PM. |
|
|
|
|
|
#2 |
|
Frenzied Member
Join Date: Sep 03
Location: Wales
Posts: 1,749
![]() ![]() |
Re: Reading form text file
To read try something like this:
VB Code:
And to write try the follwoing... VB Code:
Cheers, RyanJ |
|
|
|
|
|
#3 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Re: Reading form text file
Hey sciguyryan,
Thanks for the quick reply. On this line... VB Code:
I get an "Can't assign to array" error. Any Ideas? By the way I'm using VB5. Thanks, Ron |
|
|
|
|
|
#4 | |
|
Frenzied Member
Join Date: Sep 03
Location: Wales
Posts: 1,749
![]() ![]() |
Re: Reading form text file
Quote:
I'll see if I can check if it can be done that way in VB5 ![]() Cheers, RyanJ |
|
|
|
|
|
|
#5 |
|
Admodistrator
Join Date: Jan 05
Posts: 3,900
![]() ![]() |
Re: Reading form text file
check the codebank, posted by manavo like 5 days ago
|
|
|
|
|
|
#6 | |
|
Frenzied Member
Join Date: Sep 03
Location: Wales
Posts: 1,749
![]() ![]() |
Re: Reading form text file
Quote:
![]() Thanks for that - I wound have been here for hours looking otherwise ![]() Cheers, RyanJ |
|
|
|
|
|
|
#7 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Re: Reading form text file
Well...I'll be damned if I can find it...
|
|
|
|
|
|
#8 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Re: Reading form text file
Are you guys talking about the split function by manavo11? I have that,
but I still get the same error. Any ideas? |
|
|
|
|
|
#9 |
|
Member
Join Date: May 05
Posts: 56
![]() |
Hi RD Cody!
I had that kind of program as well.. why don't you give this a try.. These codes saves the text being inputted by the user in the textbox in a file (which the file extension can btw be specified by you) and the user can retrieve the file and show the same text and order back to the form where your textboxes are... Quite a long explanation eyh.. You can tweek it to suit your needs if you want.I made a class, which I named namelist. This class has properties namely: name symbol quantity My example.plp output would look like this when opened in a text editor(like notepad): [Name] x32 [Quantity] x75 [Symbol] q21 (globalvar.bas) VB Code:
(frm_field) 'This is the form where the textboxes are ![]() VB Code:
now to save the text inputted in the textbox in a file....use this (frm_dir) VB Code:
I hope this helps..
__________________
Yoroshiku, seraphicmortal ______________________________________________________ Thirst for knowledge can never be quenched...Ask for more!!. Oh! Please..Show your appreciation by clicking if you deem this post helpful. Rate this Post!
|
|
|
|
|
|
#10 |
|
Member
Join Date: May 05
Posts: 56
![]() |
The codes above btw came not only from me but with the help of our buds from vbforum.. (Baja and Joacim)
![]() You can go here to view my thread... http://www.vbforums.com/showthread.php?t=339887
__________________
Yoroshiku, seraphicmortal ______________________________________________________ Thirst for knowledge can never be quenched...Ask for more!!. Oh! Please..Show your appreciation by clicking if you deem this post helpful. Rate this Post!
|
|
|
|
|
|
#11 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Re: Reading form text file
Thanks for the reply, but I'm still having trouble with the Split function. I'm
going to have to find a different way of doing this. |
|
|
|
|
|
#12 |
|
Member
Join Date: May 05
Posts: 56
![]() |
mind expounding why you're having trouble using Split function?
__________________
Yoroshiku, seraphicmortal ______________________________________________________ Thirst for knowledge can never be quenched...Ask for more!!. Oh! Please..Show your appreciation by clicking if you deem this post helpful. Rate this Post!
|
|
|
|
|
|
#13 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Re: Reading form text file
I use VB5, and the Split function that manavo11 supplied just doesn't seem
to work. |
|
|
|
|
|
#14 |
|
Guru
Join Date: Jun 99
Location: Red Wing, MN, USA
Posts: 2,170
![]() ![]() |
Re: Reading form text file
Try:
VB Code:
- Aaron. |
|
|
|
|
|
#15 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Re: Reading form text file
Hey Aaron,
I'm still getting the same error... VB Code:
Compile error: "Can't assign to array" I don't know...I'm about to give up. |
|
|
|
|
|
#16 |
|
Hyperactive Member
Join Date: May 05
Posts: 258
![]() |
Re: Reading form text file
I run VB6 at work and had that same problem the other day. The reason you get that array error when using the split function is because split turns the variable into an array using a delimiter to make distinctions between elements. An example is:
dim fso as FileSystemObject dim myTextStream as TextStream dim myReadText() as String set fso = New FileSystemObject set myTextStream = fso.OpenTextFile("C:\File.txt") myReadText = Split(myTextStream.ReadLine, "|") 'The "pipe" symbol is the divider of the text MsgBox (myReadText(0)) MsgBox (myReadText(1)) MsgBox (myReadText(2)) This is just an example. The split function turns the variable into an array. So make sure you dim that variable accordingly. I hope this helps. |
|
|
|
|
|
#17 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Re: Reading form text file
Well...I don't know...this is above my head. Isn't everything declared properly?
|
|
|
|
|
|
#18 |
|
Hyperactive Member
Join Date: May 05
Posts: 258
![]() |
Re: Reading form text file
Try defining a delimiter like I did, instead of vbNewLine. It may be that VB 5 doesn't have that command, I think that is a .NET upgrade.
|
|
|
|
|
|
#19 |
|
Guru
Join Date: Jun 99
Location: Red Wing, MN, USA
Posts: 2,170
![]() ![]() |
Re: Reading form text file
Try changing "strTextLines" to a Variant data type instead of a String array, i.e.
VB Code:
- Aaron. |
|
|
|
|
|
#20 |
|
Fanatic Member
Join Date: Apr 05
Location: 神と歩くこと
Posts: 573
![]() |
Re: Reading form text file
I'm kinda new and don't really know too much but If you want to avoid the split, you can simply open the file a different way.
VB Code:
HTH
__________________
Using VB6 or VB.net 2008 with .net 3.5 "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad Last edited by space_monkey; May 27th, 2005 at 03:47 PM. Reason: Cause I'm a little slow late in the afternoon especially on a friday |
|
|
|
|
|
#21 |
|
Addicted Member
Join Date: Aug 00
Posts: 152
![]() |
Re: Reading form text file
OK...here are the results...
To tacoman667...I tried that, and it didn't make any difference. To Aaron...That worked...except if you enter a blank line in the file, then I get a "subscript out of range" error. In other words, there are 6 lines of text (2 blank), and when it puts them into the 6 textboxes, it uses the first four, and then I get the error. To space_monkey...it worked perfectly! I want to thank all you guys for helping to figure this out, Ron |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|