velox
Retired
u know how u can do this "Name As String * 40" which means the string can be only 40 chars long. Can u do the same for a integer?
Option Explicit ' force variable declaration
Private Sub Form_Load()
Dim x As Integer
Dim str As String
Dim num As Integer
' open file to read
Open "C:\test.txt" For Input As #1
x = 1
' read until end of file, for file 1
Do Until EOF(1)
Input #1, str ' read one line from file #1
num = CInt(str) ' convert line read into a number (so you can do arithmetic on it)
MsgBox "read the number: " + str + " on line: " + CStr(x)
x = x + 1
Loop
' finished, close file
Close #1
End Sub
If you run the code, you will find that it displays in the message box what it read on the line. So if the file had contents:velox said:"MsgBox "read the number: " + str + " on line: " + CStr(x)"
velox said:Like what is "str."?
Input #1, str ' read one line from file #1
Because it is declared an integer, and it is incremented (plus 1) each time in the loop runs, and since each time the loop runs, it reads one line, the variable x will keep track on which line we are currently on.velox said:So X is the line number? If so, how do we know that?
U know for th input of the integer u could set the limit of the text box to the number of characters you what. and to make sure you only get numbers u could use VAL which gets rid of all characters that arent numbers that is if you integer is to be int and ur text box is to be Text1 then in VB6.0velox said:u know how u can do this "Name As String * 40" which means the string can be only 40 chars long. Can u do the same for a integer?