vsflexgrid 控件使用时出现了问题
代码如下:
Private Sub Combo1_Click()
If combo1.Text = "△型连接" Then
Combo2.Visible = True
Else: Combo2.Visible = False
End If
End Sub
If combo1.Text = "△型连接" Then
Combo2.Visible = True
Else: Combo2.Visible = False
End If
End Sub
Private Sub Command1_Click()
If combo1.Text = "Y型连接" Then
For i = 1 To VSFlexGrid1.Cols - 1
a = Val(VSFlexGrid1.TextMatrix(1, i))
b = Val(VSFlexGrid1.TextMatrix(2, i))
c = Val(VSFlexGrid1.TextMatrix(3, i))
VSFlexGrid1.TextMatrix(4, i) = (a + b - c) / 2
VSFlexGrid1.TextMatrix(5, i) = (a + c - b) / 2
VSFlexGrid1.TextMatrix(6, i) = (b + c - a) / 2
Next i
For i = 1 To VSFlexGrid1.Rows - 1
For j = 0 To VSFlexGrid1.Cols - 1
If Val(VSFlexGrid1.TextMatrix(i, j)) = 0 Then VSFlexGrid1.TextMatrix(i, j) = ""
Next j
Next i
End If
If combo1.Text = "△型连接" And Combo2.Text = "a连y、b连z、c连x" Then
Dim p As Single
For i = 1 To VSFlexGrid1.Cols - 1
a = Val(VSFlexGrid1.TextMatrix(1, i))
b = Val(VSFlexGrid1.TextMatrix(2, i))
c = Val(VSFlexGrid1.TextMatrix(3, i))
p = (a + b + c) / 3
VSFlexGrid1.TextMatrix(4, i) = CStr((b - p) - a * c / (b - p))
VSFlexGrid1.TextMatrix(5, i) = CStr((a - p) - b * c / (a - p))
VSFlexGrid1.TextMatrix(6, i) = CStr((c - p) - a * b / (c - p))
Next i
For i = 1 To VSFlexGrid1.Rows - 1
For j = 0 To VSFlexGrid1.Cols - 1
If Val(VSFlexGrid1.TextMatrix(i, j)) = 0 Then VSFlexGrid1.TextMatrix(i, j) = ""
Next j
Next i
End If
For i = 1 To VSFlexGrid1.Cols - 1
a = Val(VSFlexGrid1.TextMatrix(1, i))
b = Val(VSFlexGrid1.TextMatrix(2, i))
c = Val(VSFlexGrid1.TextMatrix(3, i))
VSFlexGrid1.TextMatrix(4, i) = (a + b - c) / 2
VSFlexGrid1.TextMatrix(5, i) = (a + c - b) / 2
VSFlexGrid1.TextMatrix(6, i) = (b + c - a) / 2
Next i
For i = 1 To VSFlexGrid1.Rows - 1
For j = 0 To VSFlexGrid1.Cols - 1
If Val(VSFlexGrid1.TextMatrix(i, j)) = 0 Then VSFlexGrid1.TextMatrix(i, j) = ""
Next j
Next i
End If
If combo1.Text = "△型连接" And Combo2.Text = "a连y、b连z、c连x" Then
Dim p As Single
For i = 1 To VSFlexGrid1.Cols - 1
a = Val(VSFlexGrid1.TextMatrix(1, i))
b = Val(VSFlexGrid1.TextMatrix(2, i))
c = Val(VSFlexGrid1.TextMatrix(3, i))
p = (a + b + c) / 3
VSFlexGrid1.TextMatrix(4, i) = CStr((b - p) - a * c / (b - p))
VSFlexGrid1.TextMatrix(5, i) = CStr((a - p) - b * c / (a - p))
VSFlexGrid1.TextMatrix(6, i) = CStr((c - p) - a * b / (c - p))
Next i
For i = 1 To VSFlexGrid1.Rows - 1
For j = 0 To VSFlexGrid1.Cols - 1
If Val(VSFlexGrid1.TextMatrix(i, j)) = 0 Then VSFlexGrid1.TextMatrix(i, j) = ""
Next j
Next i
End If
End Sub
Private Sub Form_Load()
VSFlexGrid1.TextMatrix(0, 0) = "档位"
VSFlexGrid1.TextMatrix(0, 1) = "Ⅰ"
VSFlexGrid1.TextMatrix(0, 2) = "Ⅱ"
VSFlexGrid1.TextMatrix(0, 3) = "Ⅲ"
VSFlexGrid1.TextMatrix(0, 4) = "Ⅳ"
VSFlexGrid1.TextMatrix(0, 5) = "Ⅴ"
VSFlexGrid1.TextMatrix(0, 5) = "Ⅵ"
VSFlexGrid1.TextMatrix(0, 6) = "Ⅶ"
VSFlexGrid1.TextMatrix(0, 7) = "Ⅷ"
VSFlexGrid1.TextMatrix(0, 8) = "Ⅸ"
VSFlexGrid1.TextMatrix(1, 0) = "AB"
VSFlexGrid1.TextMatrix(2, 0) = "AC"
VSFlexGrid1.TextMatrix(3, 0) = "BC"
VSFlexGrid1.TextMatrix(4, 0) = "A"
VSFlexGrid1.TextMatrix(5, 0) = "B"
VSFlexGrid1.TextMatrix(6, 0) = "C"
VSFlexGrid1.TextMatrix(0, 0) = "档位"
VSFlexGrid1.TextMatrix(0, 1) = "Ⅰ"
VSFlexGrid1.TextMatrix(0, 2) = "Ⅱ"
VSFlexGrid1.TextMatrix(0, 3) = "Ⅲ"
VSFlexGrid1.TextMatrix(0, 4) = "Ⅳ"
VSFlexGrid1.TextMatrix(0, 5) = "Ⅴ"
VSFlexGrid1.TextMatrix(0, 5) = "Ⅵ"
VSFlexGrid1.TextMatrix(0, 6) = "Ⅶ"
VSFlexGrid1.TextMatrix(0, 7) = "Ⅷ"
VSFlexGrid1.TextMatrix(0, 8) = "Ⅸ"
VSFlexGrid1.TextMatrix(1, 0) = "AB"
VSFlexGrid1.TextMatrix(2, 0) = "AC"
VSFlexGrid1.TextMatrix(3, 0) = "BC"
VSFlexGrid1.TextMatrix(4, 0) = "A"
VSFlexGrid1.TextMatrix(5, 0) = "B"
VSFlexGrid1.TextMatrix(6, 0) = "C"
combo1.AddItem "Y型连接"
combo1.AddItem "△型连接"
Combo2.AddItem "a连y、b连z、c连x"
Combo2.AddItem "a连z、b连x、c连y"
End Sub
Private Sub VSFlexGrid1_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
'限定不可编辑列,如有5列
If Row = 4 Then Cancel = True
If Row = 5 Then Cancel = True
If Row = 6 Then Cancel = True
End Sub
combo1.AddItem "△型连接"
Combo2.AddItem "a连y、b连z、c连x"
Combo2.AddItem "a连z、b连x、c连y"
End Sub
Private Sub VSFlexGrid1_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
'限定不可编辑列,如有5列
If Row = 4 Then Cancel = True
If Row = 5 Then Cancel = True
If Row = 6 Then Cancel = True
End Sub
代码想实现的功能是在表格的前三行随机输入数值,在后三行根据计算公式计算,在运行的时候,第一个“if”(Y型连接)是能正常的,就第二个“if” 通过不了
现在遇到的问题是:
问题1:我运行调试的时候在 VSFlexGrid1.TextMatrix(4, i) = CStr((b - p) - a * c / (b - p))这行显示黄色,提示是“实时错误6 ,溢出”
问题2:在表里输入数字后点“Command1”运行时,列方向的 “AB”“AC”“BC”等都不显示了。(没点“Command1”前是会显示的)
问题2:在表里输入数字后点“Command1”运行时,列方向的 “AB”“AC”“BC”等都不显示了。(没点“Command1”前是会显示的)
问题3:怎么让输入只允许是数字,不然就提示用户要输入数字
问题4:在运行的时候,我如果前面那三行没输全,他就会用0去代替,这种情况怎么避免?比如数字没输全就不让运行