reading from a file

gdspeare

Board Regular
Joined
Oct 8, 2002
Messages
198
I'm trying to read from a simple text file and then print a calculation to a label. Does anyone have a link for a question similar to this that has been asked?

Thanks,
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
For some obvious reason that I can't figure out the below code is only displaying the last record from my .txt file in the label1 object.

Private Sub CommandButton1_Click()

Dim name As String
Dim wage As Single
Dim hours As Single
Dim pay As Single

lable1 = ""

Open "C:\Documents and Settings\speared\Desktop\staff.txt" For Input As #1

For i = 1 To EOF(1)
Input #1, name, wage, hours
pay = wage * hours
Next i
Label1 = name & pay
Close #1
End Sub
 
Upvote 0
gdspeare

What is it you are actually trying to do?

That code loops through the text file extracting it line by line to name, wage and hours.

It then does the calculation, but nothing else.

So the last calculation will be based on the last line from the text file.
 
Upvote 0
exactly, it is only displaying the last record in the label box. I want to have every record displayed, but my code is replacing one line with the very next line.
 
Upvote 0
You want to display all the data in 1 label?
 
Upvote 0

Forum statistics

Threads
1,203,189
Messages
6,054,014
Members
444,696
Latest member
VASUCH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top