Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple newbie question about " Input # "

Status
Not open for further replies.

johnkub

Programmer
Jun 21, 2001
2
CA
hello, im quite new to programming and need to know how the input# function works

i have saved data in a text file using visual basic 6 from a text box called txtBox.Text and i want the program to see what the value in the text file sum.txt is

then i want it to use it to add up stuff

can somebody help me with a small piece of code, thanks soo much for any replies
 
Hi,

I would recommend avoiding the input# and print# approach to writing text files, and start using the FileSystemObject included in the Microsoft Scripting runtime

You can add a reference to the runtime by going to Project > References and checking Microsoft Scripting Runtime.

You the need to declare the new FileSystemObject in your code. The object provides many methods and properties for manipulating the file system and any files in it.

Here's some example code you can take:

Code:
Dim FSO As New FileSystemObject
Dim TStream As New TextStream

Set TStream = FSO.CreateTextFile("C:\TEMP\FILE.TXT", True, False)

TStream.Write Text1.Text
Then.....
Code:
Dim FSO As New FileSystemObject
Dim TStream As New TextStream

Set TStream = FSO.OpenTextFile("C:\TEMP\FILE.TXT", ForReading, TristateFalse)

Text1.Text = TStream.ReadAll

Hope this helps....

Quros s-)
 
If you are outputting only the value of a single textbox to the text file then it will contain a single line with the contents of the text box.

In this case:

Dim tempstring As String
Open "sum.txt" For Input As #1
Line Input #1, tempstring
Close #1


will read the value into a variable

However if you are storing many different values in the file then you can retrieve each line sequentially like so:

Dim tempstring As String
Open "sum.txt" For Input As #1
Do Until EOF(1)
Line Input #1, tempstring
'do something with the value
Loop
Close #1


In this case you will have to devise some way of working out which line in the text file you want to look at. If this is the case then you should think about using ini files instead.
 
ok thanks a lot guys, got it working with line input
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top