this is a code to input a file and display it in a datagrid
CODE
Private Sub cmdLoad_Click()
Wrap$ = Chr$(13) + Chr$(10)
cdlCommon.Filter = "Text files (*.TXT)|*.TXT"
cdlCommon.ShowOpen
If cdlCommon.FileName <> "" Then
Open cdlCommon.FileName For Input As #1
Do Until EOF(1)
Line Input #1, LineOfText$
AllText$ = AllText$ & LineOfText$ & Wrap$
Loop
txtfile.Text = AllText$
txtfile.Enabled = True
linecount% = 0
charsInFile% = Len(txtfile.Text)
For i% = 1 To charsInFile%
letter$ = Mid(txtfile.Text, i%, 1)
If letter$ = Chr$(13) Then
linecount% = linecount% + 1
i% = i% + 1
End If
Next i%
size = linecount% - 1
Call initialize
CleanUp:
Close #1
End If
Exit Sub
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
'column title
grid.TextArray(0) = "Job ID"
grid.TextArray(1) = "Arrival Time"
grid.TextArray(2) = "Job Type"
grid.TextArray(3) = "Memory Size"
grid.TextArray(4) = "CPU Burst"
grid.TextArray(5) = "Waiting Time"
grid.TextArray(6) = "Turn Around Time"
End Sub
Sub initialize()
Dim i%, temp(100)
For i = 1 To size
grid.Rows = grid.Rows + 1
Next i
charsInFile% = Len(txtfile.Text)
x = 0
charsInFile% = Len(txtfile.Text)
For i% = 1 To charsInFile%
letter$ = Mid(txtfile.Text, i%, 1)
If letter$ = Chr$(60) Then
temp(x) = Mid(txtfile.Text, i% + 1, 2)
x = x + 1
End If
Next i%
y = 1
For x = 1 To size
grid.TextMatrix(x, 0) = temp(y)
grid.TextMatrix(x, 4) = temp(y + 1)
grid.TextMatrix(x, 5) = temp(y + 2)
grid.TextMatrix(x, 1) = temp(y + 3)
y = y + 4
Next x
End Sub
my input is a textfile:
CODE
<20>
<01><01><04><05>
<02><02><04><06>
<03><03><08><02>
<04><04><16><10>
<05><05><16><10>
<06><01><04><05>
<07><02><04><06>
<08><03><08><02>
<09><04><16><10>
<10><05><16><10>
<11><01><04><05>
<12><02><04><06>
<13><03><08><02>
<14><04><16><10>
<15><05><16><10>
<16><01><04><05>
<17><02><04><06>
<18><03><08><02>
<19><04><16><10>
<20><05><16><10>
the numbers in the textfile should display in my grid when loaded but i get an error with the
CODE
txtfile.text
line...
need help....
EDIT: modified title ~ jayman9