此按钮调用彼按钮

hjinhua 2006-09-27 02:38:40
请问各位过路的朋友,为什么在此按钮中调用彼按钮时例如
我想在"保存(command5)"按钮中调用"显示(command1)"按钮,目的是为了在保存时在MSHFLexgrid中刷新内容,为什么只有写了两次后才能显示正确的内容
command5_click()事件中写 '1:对新数据则同一按钮单击两次就直接推出VB,再次进如则不会出现该问题
...
command1_click '2:这样写才有效,很是不明白
command1_click
...

...全文
273 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
清晨曦月 2006-10-12
  • 打赏
  • 举报
回复
d
还想懒够 2006-10-11
  • 打赏
  • 举报
回复
呵呵,能不能不使用ADODC而使用ADODB?看着累得慌
shuchangyun 2006-10-11
  • 打赏
  • 举报
回复
我的妈呀,一个也看不懂,看来我要好好看书,努力学好才是呀???
hjinhua 2006-10-10
  • 打赏
  • 举报
回复
各位,问题我搞定了,谢谢各位的踊跃参与,原来是刷新啊
这刷新可得好好琢磨琢磨!!
呵呵
hjinhua 2006-09-29
  • 打赏
  • 举报
回复
WallesCai(沧海明月一度,西风残阳无悔.)
大哥,你没看到吗?
就在第一帖里啊
需要在command5_click事件里写两次command1_click 数据显示时才正确,WHY?
按道理一次就可以了是.
happy_sea 2006-09-29
  • 打赏
  • 举报
回复
偶不懂数据库,大家帮忙看看吧
pigsanddogs 2006-09-29
  • 打赏
  • 举报
回复
hehe .
guyehanxinlei 2006-09-29
  • 打赏
  • 举报
回复
太LI PU了吧
熊孩子开学喽 2006-09-29
  • 打赏
  • 举报
回复
问题慢慢抓:
1:
If Trim(Combo1.Text) = "" Then
MsgBox "请选择学院!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If

If Trim(Combo2.Text) = "" Then
MsgBox "请选择专业!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If

If Trim(Combo3.Text) = "" Then
MsgBox "请选择班级!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If

改成:
IF TRIM(COMBO1.TEXT & COMBO2.TEXT & COMBO3.TEXT)="" THEN...

2:
使用控件数组,不要用单个的控件,这么多控件名字很容易搞错,要是想写一个统一的事件代码还要用FOR EACH,太麻烦。
控件数组很简单,选中一个控件,按“CTRL + C" 再点窗体,按”CTRL + V"就会问你是否哟昂创建控件数组了。
然后你就可以用型如:
FOR I =0 TO LABEL1.COUNT -1
LABEL1(I).ENABLE = TRUE
NEXT
这样简洁的代码了
并且触发事件也变成了:
SUB COMMAMD1_CLICK(INDEX AS INTEGER)
SELECT CASE INDEX
CASE 0: '写第一个按钮按下后要做的动作
CASE 1: '写第二个按钮按下后要做的动作END SELECT
...
END SELECT
END SUB
又简单了很多

3:
根本就没有找到楼主在第一贴中说到的地方在哪里,有没有贴错啊
hjinhua 2006-09-29
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
If Trim(Combo1.Text) = "" Then
MsgBox "请选择学院!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If

If Trim(Combo2.Text) = "" Then
MsgBox "请选择专业!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If

If Trim(Combo3.Text) = "" Then
MsgBox "请选择班级!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If

'绑定学生信息

Dim i As Integer
Dim SqlStr As String
SqlStr = "select * from pdfzsz where 学号 in(select distinct 学号 from xsdjb where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"

'品德发展素质
Adodc5.ConnectionString = connectstring()
Adodc5.CommandType = adCmdText
Adodc5.RecordSource = SqlStr
Adodc5.Refresh


If Adodc5.Recordset.RecordCount = 0 Then
'添加pdfzsz中的记录
SqlStr = "select * from xsdjb where 学号 in(select distinct 学号 from xsdjb where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"

Adodc6.ConnectionString = connectstring()
Adodc6.CommandType = adCmdText
Adodc6.RecordSource = SqlStr
Adodc6.Refresh

If Adodc6.Recordset.RecordCount = 0 Then
MsgBox "没有查找到满足条件的记录!", vbInformation + vbOKOnly
MSHFlexGrid1.Clear
Call BTop
Exit Sub
End If
Adodc6.Recordset.MoveFirst
For i = 1 To Adodc6.Recordset.RecordCount
Adodc5.Recordset.AddNew
Adodc5.Recordset.Fields("学号") = Adodc6.Recordset.Fields("学号")
Adodc5.Recordset.Fields("姓名") = Adodc6.Recordset.Fields("姓名")
Adodc5.Recordset.Fields("学院") = Adodc6.Recordset.Fields("学院")
Adodc5.Recordset.Fields("专业") = Adodc6.Recordset.Fields("专业")
Adodc5.Recordset.Fields("班级") = Adodc6.Recordset.Fields("班级")
Adodc5.Recordset.Update
Adodc6.Recordset.MoveNext
Next i
SqlStr = "select * from pdfzsz where 学号 in(select distinct 学号 from xsdjb where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"

Adodc5.RecordSource = SqlStr
Adodc5.Refresh
Else
'修改xsdjb中的记录
SqlStr = "select * from xsdjb where 学号 in(select distinct 学号 from xsdjb where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"

Adodc7.ConnectionString = connectstring()
Adodc7.CommandType = adCmdText
Adodc7.RecordSource = SqlStr
Adodc7.Refresh

Adodc5.Recordset.MoveFirst
Adodc7.Recordset.MoveFirst
For i = 1 To Adodc7.Recordset.RecordCount
If Adodc5.Recordset.EOF = False Then
If Adodc5.Recordset.Fields("学号") = Adodc7.Recordset.Fields("学号") Then
Adodc5.Recordset.MoveNext
Adodc7.Recordset.MoveNext
Else
Adodc5.Recordset.AddNew
Adodc5.Recordset.Fields("学号") = Adodc7.Recordset.Fields("学号")
Adodc5.Recordset.Fields("姓名") = Adodc7.Recordset.Fields("姓名")
Adodc5.Recordset.Fields("学院") = Adodc7.Recordset.Fields("学院")
Adodc5.Recordset.Fields("专业") = Adodc7.Recordset.Fields("专业")
Adodc5.Recordset.Fields("班级") = Adodc7.Recordset.Fields("班级")
Adodc5.Recordset.Update
Adodc7.Recordset.MoveNext
End If
Else
Adodc5.Recordset.AddNew
Adodc5.Recordset.Fields("学号") = Adodc7.Recordset.Fields("学号")
Adodc5.Recordset.Fields("姓名") = Adodc7.Recordset.Fields("姓名")
Adodc5.Recordset.Fields("学院") = Adodc7.Recordset.Fields("学院")
Adodc5.Recordset.Fields("专业") = Adodc7.Recordset.Fields("专业")
Adodc5.Recordset.Fields("班级") = Adodc7.Recordset.Fields("班级")
Adodc5.Recordset.Update
Adodc7.Recordset.MoveNext
End If
Next
Adodc5.Refresh
End If

'定性_学生干部
SqlStr = "select * from S_dingxing where 学号 in(select distinct 学号 from pdfzsz where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"
Adodc9.ConnectionString = connectstring()
Adodc9.CommandType = adCmdText
Adodc9.RecordSource = SqlStr
Adodc9.Refresh

MSHFlexGrid1.Rows = 2
If Adodc5.Recordset.RecordCount <> 0 Then
For i = 1 To Adodc5.Recordset.RecordCount
MSHFlexGrid1.RowHeight(i) = 300
MSHFlexGrid1.TextMatrix(i, 0) = i
MSHFlexGrid1.TextMatrix(i, 1) = Adodc5.Recordset.Fields("学号")
MSHFlexGrid1.TextMatrix(i, 2) = Adodc5.Recordset.Fields("姓名")
If Adodc9.Recordset.RecordCount = Adodc5.Recordset.RecordCount Then
If Adodc9.Recordset.Fields("学生干部") <> "" Then
MSHFlexGrid1.TextMatrix(i, 3) = Adodc9.Recordset.Fields("学生干部")
Adodc9.Recordset.MoveNext
End If
End If
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
Adodc5.Recordset.MoveNext

Next i
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.FixedCols = 3
End If


'加载数据

Dim j As Integer
Dim l(12) As String
l(3) = "学生干部"
l(4) = "增减分"
l(5) = "先进个人"
l(6) = "先进个人得分事由"
l(7) = "先进集体"
l(8) = "先进集体得分事由"
l(9) = "精神文明"
l(10) = "精神文明得分事由"
l(11) = "总分"
l(12) = "排名"

Adodc5.Recordset.MoveFirst
For i = 1 To Adodc5.Recordset.RecordCount
For j = 4 To 12
If Adodc5.Recordset.Fields(l(j)) <> "" Then MSHFlexGrid1.TextMatrix(i, j) = Adodc5.Recordset.Fields(l(j))
Next j
Adodc5.Recordset.MoveNext
Next i
InputText.Text = MSHFlexGrid1.Text

MSHFlexGrid1.Enabled = True
Frame1.Enabled = False
Label2.Enabled = False
Label3.Enabled = False
Label4.Enabled = False
Combo1.Enabled = False
Combo2.Enabled = False
Combo3.Enabled = False

Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
End Sub
happy_sea 2006-09-27
  • 打赏
  • 举报
回复
把command1_click()中的代码发上来看看

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧