Home > Software engineering >  Vb process file error subscript crossing the line
Vb process file error subscript crossing the line

Time:10-10

VB beginner, I always quote when reading data in the table below of crossing the line, please god help
To find the problem, appreciated, and the code is as follows:

Open "test. TXT" For Input As # 1
Dim x, y, b, d, g,
The Do While Not EOF (1)
'-- -- -- -- -- -- -- -- -- -- -- -- take the file content
The Line Input # 1, d
I=I + 1
If I & gt; 2 Then
D=Replace (d, "",", ")
G=Split (d,) ", "
X=g (1)
Y=g (2)
B (x, y)=g (3)
End the If
Loop
Close # 1
The data format is as follows,
'# # # # # # # # # # # # # # # # # # # # # test. Txt# # # # # # # # # #
RawData
2 9 11 11 0
2 10 21 21 0
3 September 21 21 0

CodePudding user response:

Run in the VB IDE, error pop-up dialog box, some debug button, the cursor will automatically to the positioning error,
At this point in the immediate window, you can use the
? The variable name
Command to display the corresponding variable values at that time,

CodePudding user response:

1 subscript crossing the line is not instantiated as b can accommodate x * y array element,

2 the design of data structure is unreasonable, b must become a sparse array, efficiency is very low,

Might as well put b is designed as a structure:

 Private Type Point_Value 
X As Long
Y As Long
V As Long
End Type

Open "test. TXT" For Input As # 1
Dim (b) As Point_Value, strLine As String, strItem () As String
The Do While Not EOF (1)
'-- -- -- -- -- -- -- -- -- -- -- -- take the file content
The Line Input # 1, strLine
I=I + 1
If I & gt; 2 Then
StrItem=Split (strLine, "")
Redim Preserve b (I - 3) As Point_Value
If Ubound (strItem) & gt;=3 Then
B (I - 3) x=strItem (1)
B (I - 3) y=strItem (2)
B (I - 3) V=strItem (3)
End the If
End the If
Loop
Close # 1
  • Related