Populating Text Boxes with a file 
Author Message
 Populating Text Boxes with a file

Hello,

Is there anyone who could explain how I would go about populating Text Boxes
on a form with data from a .txt file?

TIA
LJ



Mon, 25 Apr 2005 05:04:56 GMT  
 Populating Text Boxes with a file
This is the easiest way for me:

Set fso = CreateObject("Scripting.filesystemobject")
Set txtstream = fso.OpenTextFile("C:\temp.txt", 1, False, -2)
Textbox1.Text = txtstream.readall

Close txtstream
Set txtstream = nothing

Set fso = nothing


Quote:
> Hello,

> Is there anyone who could explain how I would go about populating Text
Boxes
> on a form with data from a .txt file?

> TIA
> LJ



Mon, 25 Apr 2005 08:24:20 GMT  
 Populating Text Boxes with a file
Il cervello cattivo di Richard T. Edwards produceva il seguente:

Quote:

> This is the easiest way for me:

> Set fso = CreateObject("Scripting.filesystemobject")
> Set txtstream = fso.OpenTextFile("C:\temp.txt", 1, False, -2)
> Textbox1.Text = txtstream.readall

> Close txtstream
> Set txtstream = nothing

> Set fso = nothing

That's VB6 code you have there. The FSO is still the best way to do it in
VB.net, but it works somewhat different:

First, add a reference to the COM-component "Microsoft Scripting Runtime"
to your project. Then, the code looks like this:

'beginning of file, outside of class declaration
Imports Scripting

...

'inside your class, best declared as global class variable
Dim fs As New FileSystemObject

...

'inside the Sub
Dim textboxtext As TextStream = fs.OpenTextFile(Application.StartupPath & _
                                "\version.txt", IOMode.ForReading, False)

'now, let's say each line in the text file contains the text for a textbox
txtInput.Text = textboxtext.ReadLine()
txtOutput.Text = textboxtext.ReadLine()
txtWhatever.Text = textboxtext.ReadLine()
...
'all done
textboxtext.Close()

--
Tenchi (remove 'spam.be.gone' for emails)

My VB.net Download Manager (Version 1.24.1000.0)
Homepage: http://mitglied.lycos.de/downloadwunder/
Mailing list: http://de.groups.yahoo.com/group/dw-net/



Tue, 26 Apr 2005 03:19:11 GMT  
 Populating Text Boxes with a file
I was wonedering why I was having problems. I should have noticed that!!
Thank you both for the help!
LJ


Quote:
> Il cervello cattivo di Richard T. Edwards produceva il seguente:

> > This is the easiest way for me:

> > Set fso = CreateObject("Scripting.filesystemobject")
> > Set txtstream = fso.OpenTextFile("C:\temp.txt", 1, False, -2)
> > Textbox1.Text = txtstream.readall

> > Close txtstream
> > Set txtstream = nothing

> > Set fso = nothing

> That's VB6 code you have there. The FSO is still the best way to do it in
> VB.net, but it works somewhat different:

> First, add a reference to the COM-component "Microsoft Scripting Runtime"
> to your project. Then, the code looks like this:

> 'beginning of file, outside of class declaration
> Imports Scripting

> ...

> 'inside your class, best declared as global class variable
> Dim fs As New FileSystemObject

> ...

> 'inside the Sub
> Dim textboxtext As TextStream = fs.OpenTextFile(Application.StartupPath &
_
>                                 "\version.txt", IOMode.ForReading, False)

> 'now, let's say each line in the text file contains the text for a textbox
> txtInput.Text = textboxtext.ReadLine()
> txtOutput.Text = textboxtext.ReadLine()
> txtWhatever.Text = textboxtext.ReadLine()
> ...
> 'all done
> textboxtext.Close()

> --
> Tenchi (remove 'spam.be.gone' for emails)

> My VB.net Download Manager (Version 1.24.1000.0)
> Homepage: http://mitglied.lycos.de/downloadwunder/
> Mailing list: http://de.groups.yahoo.com/group/dw-net/



Tue, 26 Apr 2005 21:53:55 GMT  
 Populating Text Boxes with a file
I assume you guys are joking! The FileSystemObject was not a very good
solution for VB6 but it is idiotic to use it with VB.Net, anybody who uses
it with .Net should be fired on the spot.

Take a look at the System.IO namespace for accessing files.


Quote:
> Il cervello cattivo di Richard T. Edwards produceva il seguente:

> > This is the easiest way for me:

> > Set fso = CreateObject("Scripting.filesystemobject")
> > Set txtstream = fso.OpenTextFile("C:\temp.txt", 1, False, -2)
> > Textbox1.Text = txtstream.readall

> > Close txtstream
> > Set txtstream = nothing

> > Set fso = nothing

> That's VB6 code you have there. The FSO is still the best way to do it in
> VB.net, but it works somewhat different:

> First, add a reference to the COM-component "Microsoft Scripting Runtime"
> to your project. Then, the code looks like this:

> 'beginning of file, outside of class declaration
> Imports Scripting

> ...

> 'inside your class, best declared as global class variable
> Dim fs As New FileSystemObject

> ...

> 'inside the Sub
> Dim textboxtext As TextStream = fs.OpenTextFile(Application.StartupPath &
_
>                                 "\version.txt", IOMode.ForReading, False)

> 'now, let's say each line in the text file contains the text for a textbox
> txtInput.Text = textboxtext.ReadLine()
> txtOutput.Text = textboxtext.ReadLine()
> txtWhatever.Text = textboxtext.ReadLine()
> ...
> 'all done
> textboxtext.Close()

> --
> Tenchi (remove 'spam.be.gone' for emails)

> My VB.net Download Manager (Version 1.24.1000.0)
> Homepage: http://mitglied.lycos.de/downloadwunder/
> Mailing list: http://de.groups.yahoo.com/group/dw-net/



Wed, 27 Apr 2005 00:05:49 GMT  
 Populating Text Boxes with a file
Thanks for the advice I will look at that as well. but don't tell my boss
about the fso thing I need to pay the bills!!!!


Quote:
> I assume you guys are joking! The FileSystemObject was not a very good
> solution for VB6 but it is idiotic to use it with VB.Net, anybody who uses
> it with .Net should be fired on the spot.

> Take a look at the System.IO namespace for accessing files.



> > Il cervello cattivo di Richard T. Edwards produceva il seguente:

> > > This is the easiest way for me:

> > > Set fso = CreateObject("Scripting.filesystemobject")
> > > Set txtstream = fso.OpenTextFile("C:\temp.txt", 1, False, -2)
> > > Textbox1.Text = txtstream.readall

> > > Close txtstream
> > > Set txtstream = nothing

> > > Set fso = nothing

> > That's VB6 code you have there. The FSO is still the best way to do it
in
> > VB.net, but it works somewhat different:

> > First, add a reference to the COM-component "Microsoft Scripting
Runtime"
> > to your project. Then, the code looks like this:

> > 'beginning of file, outside of class declaration
> > Imports Scripting

> > ...

> > 'inside your class, best declared as global class variable
> > Dim fs As New FileSystemObject

> > ...

> > 'inside the Sub
> > Dim textboxtext As TextStream = fs.OpenTextFile(Application.StartupPath
&
> _
> >                                 "\version.txt", IOMode.ForReading,
False)

> > 'now, let's say each line in the text file contains the text for a
textbox
> > txtInput.Text = textboxtext.ReadLine()
> > txtOutput.Text = textboxtext.ReadLine()
> > txtWhatever.Text = textboxtext.ReadLine()
> > ...
> > 'all done
> > textboxtext.Close()

> > --
> > Tenchi (remove 'spam.be.gone' for emails)

> > My VB.net Download Manager (Version 1.24.1000.0)
> > Homepage: http://mitglied.lycos.de/downloadwunder/
> > Mailing list: http://de.groups.yahoo.com/group/dw-net/



Wed, 27 Apr 2005 01:51:39 GMT  
 Populating Text Boxes with a file

Quote:
> I assume you guys are joking! The FileSystemObject was not a
> very good solution for VB6 but it is idiotic to use it with
> VB.Net, anybody who uses it with .Net should be fired on the spot.

> Take a look at the System.IO namespace for accessing files.

ACK (although I wouldn't use "idiotic" ;)


Wed, 27 Apr 2005 01:05:52 GMT  
 Populating Text Boxes with a file
It is nice to see that a question I had has provoked a pretty good debate. I
hope that it also induces thought and a better more efficient way to
accomplish this.

I appreciate everybody's input!


Quote:

> > I assume you guys are joking! The FileSystemObject was not a
> > very good solution for VB6 but it is idiotic to use it with
> > VB.Net, anybody who uses it with .Net should be fired on the spot.

> > Take a look at the System.IO namespace for accessing files.

> ACK (although I wouldn't use "idiotic" ;)



Wed, 27 Apr 2005 03:53:15 GMT  
 Populating Text Boxes with a file
OK, a little more in depth.

I have a Text file that I want to use to populate objects on a form (most
are Text Boxes). The way I need to pull the data from the file is by
position.

For example
The first 3 characters in the file would be in TextBox1
The characters from position 4-11 would be in TextBox2
and so on.

The file is 500 characters in length and is 1 long string.

Do any of you have any examples or ideas on how I can accomplish this.

Thanks again for all your help!!
LJ


Quote:

> > I assume you guys are joking! The FileSystemObject was not a
> > very good solution for VB6 but it is idiotic to use it with
> > VB.Net, anybody who uses it with .Net should be fired on the spot.

> > Take a look at the System.IO namespace for accessing files.

> ACK (although I wouldn't use "idiotic" ;)



Mon, 02 May 2005 00:30:40 GMT  
 Populating Text Boxes with a file
Il cervello cattivo di LJ produceva il seguente:

Quote:

> OK, a little more in depth.

> I have a Text file that I want to use to populate objects on a form (most
> are Text Boxes). The way I need to pull the data from the file is by
> position.

> For example
> The first 3 characters in the file would be in TextBox1
> The characters from position 4-11 would be in TextBox2
> and so on.

> The file is 500 characters in length and is 1 long string.

> Do any of you have any examples or ideas on how I can accomplish this.

As I said, use the FSO :) Don't listen to these wienies. You're *far*
better off with the FSO that with this System.IO {*filter*}which has many
absurdities and shortcomings, like demanding paths with '\\', reading only
byte arrays and not strings, and other ugly stuff :(
With the FSO, you don't get any of this bullsit, plus it's much easier to
use. I really wished they'd expanded the FSO a little bit so it could also
handle also binary files and I could avoid this insane System.Io {*filter*}
altogether, but no... :(((
Here's still hoping that they put it into the new 1.1 release, shouldn't
really be too difficult (hint, hint! ARe you listening, MS?)

<assuming you have added the Scripting Runtime and declared a FSO object
named 'fs' as detailed in my previous post>

' if 'Textbox.txt' is in the program's directory
Dim myText as TextStream = fs.OpenTextFile(Application.StartupPath & _
                           "\Textbox.txt", IOMode.ForReading, False)
txtBox1.Text = mytext.Read(3)
txtBox2.Text = myText.Read(8) '4-11
txtBox3.Text = myText.Read(6) '12-17
...
txtBox123.Text = myText.Read(7) '494-500
myText.Close()

That's it already!

--
Tenchi (remove 'spam.be.gone' for emails)

My VB.net Download Manager (Version 1.24.1400.0)
Homepage: http://www.*-*-*.com/
Mailing list: http://www.*-*-*.com/



Fri, 06 May 2005 03:11:29 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Another ? about populating Text Boxes with a File

2. populate list box with text file

3. populating a combo box with an external text file

4. Populating a list box with a text file

5. Populating a combo box from a text file

6. Write contents of listbox to text file/populate listbox from text file

7. Unable to populate text box from combo box

8. populate text box from combo box (same form)

9. Beginner: Populating text box by selecting from list box

10. Populate Recipient filed with contents of text file

11. Reading file name from text box and/or File List Box

12. Populating a text box with the results of a select query

 

 
Powered by phpBB® Forum Software