| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1473 人关注过本帖
标题:vsflexgrid 控件使用时出现了问题
只看楼主 加入收藏
wuly178
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-7
收藏
 问题点数:0 回复次数:3 
vsflexgrid 控件使用时出现了问题

代码如下:

Private Sub Combo1_Click()
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
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"
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
代码想实现的功能是在表格的前三行随机输入数值,在后三行根据计算公式计算,在运行的时候,第一个“if”(Y型连接)是能正常的,就第二个“if” 通过不了
现在遇到的问题是:
问题1:我运行调试的时候在 VSFlexGrid1.TextMatrix(4, i) = CStr((b - p) - a * c / (b - p))这行显示黄色,提示是“实时错误6 ,溢出”
问题2:在表里输入数字后点“Command1”运行时,列方向的 “AB”“AC”“BC”等都不显示了。(没点“Command1”前是会显示的)
问题3:怎么让输入只允许是数字,不然就提示用户要输入数字
问题4:在运行的时候,我如果前面那三行没输全,他就会用0去代替,这种情况怎么避免?比如数字没输全就不让运行
搜索更多相关主题的帖子: DIV vsflexgrid 控件 Val Sub 
2006-09-14 15:39
qingxi
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-2-16
收藏
得分:0 
1.问题是:你没有判断 b-p=0时的情况 除数 不能为0
2.在form_load中添加一句话 VSFlexGrid1.Editable = flexEDKbd 不然 你的vs里面不能写入数字
3. 在vs的 keypress事件中写 if keyascii>=48 and keyascii<=57 then else keyascii=0 endif if keyascii=13 then sendkey "{tab}" end if
4.command中 加判断 “if .cell(flexcptext,0,0,3,.cols-1)="" then msgbox "不能为空" else 执行你下面的程序 ”
2006-09-15 10:31
wuly178
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-7
收藏
得分:0 

应该是除数等于0 出了问题
可我不知道怎么定义,有人说返回的是整型的,才会一运行就出错,是这样吗
qingxi 谢谢
可是第三和第四个问题我按你说的写进去都没成功
第三条写进去 他提示说是子程序或函数未定义,不清楚 sendkey 是什么
第四条写进去 if VSFlexGrid1.cell(flexcptext,0,0,3,VSFlexGrid1.cols-1)="" then msgbox "不能为空" else ...... end if
执行时输入为空的时候他照样执行下面的语句

2006-09-15 15:13
qingxi
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-2-16
收藏
得分:0 

Private Sub Combo1_Click()
If Combo1.Text = "△型连接" Then
Combo2.Visible = True
Else
Combo2.Visible = False
End If
End Sub
Private Sub Command1_Click()
With VSFlexGrid1
If Combo1.Text = "Y型连接" Then
For i = 1 To .Cols - 1
a = Val(.TextMatrix(1, i))
b = Val(.TextMatrix(2, i))
c = Val(.TextMatrix(3, i))
.TextMatrix(4, i) = (a + b - c) / 2
.TextMatrix(5, i) = (a + c - b) / 2
.TextMatrix(6, i) = (b + c - a) / 2
Next i
For i = 1 To .Rows - 1
For j = 0 To .Cols - 1
If Val(.TextMatrix(i, j)) = 0 Then
.TextMatrix(i, j) = ""
End If
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 .Cols - 1
a = Val(.TextMatrix(1, i))
b = Val(.TextMatrix(2, i))
c = Val(.TextMatrix(3, i))
p = (a + b + c) / 3
If b - p <> 0 Then
.TextMatrix(4, i) = CStr((b - p) - a * c / (b - p))
.TextMatrix(5, i) = CStr((a - p) - b * c / (a - p))
.TextMatrix(6, i) = CStr((c - p) - a * b / (c - p))
Else
.TextMatrix(4, i) = "输入数字有误"
.TextMatrix(5, i) = " "
.TextMatrix(6, i) = " "
End If
Next i

End If

For i = 1 To .Cols - 1
.ColWidth(i) = 1200
Next
End With
End Sub
Private Sub Form_Load()
With VSFlexGrid1
.Rows = 7
.Cols = 9
.FixedCols = 1
.FixedRows = 1
.TextMatrix(0, 0) = "档位"
.TextMatrix(0, 1) = "Ⅰ"
.TextMatrix(0, 2) = "Ⅱ"
.TextMatrix(0, 3) = "Ⅲ"
.TextMatrix(0, 4) = "Ⅳ"
.TextMatrix(0, 5) = "Ⅴ"
.TextMatrix(0, 5) = "Ⅵ"
.TextMatrix(0, 6) = "Ⅶ"
.TextMatrix(0, 7) = "Ⅷ"
.TextMatrix(0, 8) = "Ⅸ"
.TextMatrix(1, 0) = "AB"
.TextMatrix(2, 0) = "AC"
.TextMatrix(3, 0) = "BC"
.TextMatrix(4, 0) = "A"
.TextMatrix(5, 0) = "B"
.TextMatrix(6, 0) = "C"
.Editable = flexEDKbd
End With

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

Private Sub VSFlexGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If

If KeyAscii = 13 Then
SendKeys "{TAB}"
End If
End Sub

2006-09-24 14:36
快速回复:vsflexgrid 控件使用时出现了问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025456 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved