Home > Software engineering >  VB program is running in the Run - time error 340, control array element "3" doesn 't
VB program is running in the Run - time error 340, control array element "3" doesn 't

Time:09-23

 Option Explicit 
Dim the Data () As Single
Private Sub Command1_Click ()
Dim VBExcel As Object
Dim xlbook As Object
Dim xlssheet As Object
Dim I As an Integer, j As Integer

The Set VBExcel=CreateObject (" Excel. Application ")
CommonDialog1. FileName=""
CommonDialog1. Filter="EXCEL file (*. XLSX) | *. XLSX"
CommonDialog1. ShowOpen
If CommonDialog1. FileName="" Then
The Exit Sub
The Else
The Set xlbook=VBExcel. Workbooks. Open (CommonDialog1. FileName)
The Set xlssheet=xlbook. Worksheets (1)
VBExcel. Visible=False

ReDim Data (3, 11) As Single
For j=1 To 11
Data (I, j)=xlssheet. Cells (I, j)
Next j
Next I
End the If

For I=1 To 3
For j=1 To 9
V (I, j)=Data (I, j)
Next j
Next I

The Set xlssheet=Nothing
The Set xlbook=Nothing
The Set VBExcel=Nothing

Dim WL As Double
Dim As Double L
Dim FH As Double
Dim the DW As Double
Dim As Double F
Dim TW As Double
Dim VZ As Double
Dim As Double P
For I=1 To 3
WL=V (I, 1)
L=V (I, 2)
FH=V (I, 3)
DW=V (I, 4)
F=V (I, 5)
TW=V (I, 6)
VZ=V (I, 7)
P=V (I, 9)


V (I, 1)=V (I, 3)/V (I, 1)
V (I, 2)=V (I, 4)/V (I, 2)
V (I, 3)=V (I, 5)/V (I, 4)
V (I, 4)=0.5 * ((P * 3.206 * 0.75 * 240)/(V (I, 4) * V (I, 4) * V (I, 5)/V (I, 1))) + 0.5 * ((P * 3.206 * 0.8 * 240)/(V (I, 6) * V (I, 7)))
V (I, 5)=0.7355 * ((V (I, 6) ^ (2/3) * V (I, 7) ^ 3)/P)
Next I

For j=0 To 28
If j & lt; 9 Then
Text1 (j) Text=V (1, j + 1)
ElseIf j & lt; 19 Then
Text1 (j) Text=V (2, j - 9)
The Else
Text1 (j) Text=V (3, j - 19)
End the If
Next j

Cmd_Sure. Enabled=True
End Sub

CodePudding user response:

Which code also don't say that to complain!!!!!! Is it the "post" a messy code...


Another:
This code, you won't run!
In Private Sub Command1_Click (), only to see behind (middle), there was a:
ReDim Data (3, 11) As Single
For j=1 To 11
Data (I, j)=xlssheet. Cells (I, j)
Next j
Next I

Here is the Next I, but I can't see the front "For I=... "Ah!

CodePudding user response:

This, you are also to compile, eliminate the basic grammar, sentence errors...

CodePudding user response:

Is probably forgot to press the Ctrl key when copying, removed the:

ReDim Data (3, 11) As Single
For I=1 To 3
For j=1 To 11
Data (I, j)=xlssheet. Cells (I, j)
Next j
Next I

Check your Text1 (I) control array and the index number is continuous, enough to reach a maximum of loop variable,
  • Related