| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1111 人关注过本帖
标题:[求助]如何在模块里定义一个按钮数组的的子程序!
取消只看楼主 加入收藏
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
结帖率:78.95%
收藏
 问题点数:0 回复次数:3 
[求助]如何在模块里定义一个按钮数组的的子程序!

我的意思是这样的
在form窗体里有:
command控件数组index=0 to 3
它的单击是件
select case index
case 0
.
.
.
end select


然而红色这部分我想在模块里作一个公共的功能...请问要怎么做...谢谢!

[此贴子已经被作者于2007-1-10 11:40:48编辑过]

搜索更多相关主题的帖子: 子程序 模块 定义 按钮 
2007-01-10 11:40
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
收藏
得分:0 

Public Function Command11(Command1 As CommandButton, ind As Integer, datPrimaryRS As Adodc, frmMain As Form)

Select Case ind
Case 0 '移到第一条
On Error GoTo err3021
Command1(0).Enabled = False
Command1(3).Enabled = True
Command1(2).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveFirst
err3021:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 1 '移到上一条
On Error GoTo err30211
If frmMain.datPrimaryRS.Recordset.AbsolutePosition = adPosBOF Then
Command1(1).Enabled = False

Else
Command1(2).Enabled = True
Command1(0).Enabled = True
Command1(3).Enabled = True
frmMain.datPrimaryRS.Recordset.MovePrevious
End If
err30211:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 2 '移到下一条
On Error GoTo err30212
If frmMain.datPrimaryRS.Recordset.AbsolutePosition = adPosEOF Then
Command1(2).Enabled = False

Else
Command1(1).Enabled = True
Command1(0).Enabled = True
Command1(3).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveNext

End If
err30212:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 3 '移到最未条
On Error GoTo err30213
Command1(0).Enabled = True
Command1(3).Enabled = False
Command1(1).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveLast
err30213:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If

End Select

End Function

Private Sub Command1_Click(index As Integer)
ind = index
Call Command11(Command1, index, frmMain.datPrimaryRS, frmMain)

End Sub
红色的是模块里的...蓝色的是事件调用模块的功能
但这样不行...显示出错...类型不合
要怎么样才可以解决这个问题?
谢谢


/images/2011/147787/2011051411021524.jpg" border="0" />
2007-01-10 13:04
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
收藏
得分:0 
frmMain是一个窗体datPrimaryRS是一个adodc控件

/images/2011/147787/2011051411021524.jpg" border="0" />
2007-01-10 16:40
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
收藏
得分:0 

这是我窗体的代码:
Private Sub cmdAdd_Click()

Call cmdAdd1(frmMain.datPrimaryRS, frmMain)
End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdDelete_Click()
Call cmdDelete1(cmdDelete, frmMain.datPrimaryRS, frmMain)

End Sub

Private Sub cmdRefresh_Click()
Call cmdRefresh1(frmMain.datPrimaryRS, frmMain)
End Sub

Private Sub cmdUpdate_Click()
Call cmdUpdate1(frmMain.datPrimaryRS, cmdDelete, frmMain)

End Sub

Private Sub Command1_Click(index As Integer)
Call Command11(Command1, index, frmMain.datPrimaryRS, frmMain)

End Sub

Private Sub Form_GotFocus()
frmMain.datPrimaryRS.Recordset.Open
End Sub

Private Sub Form_Load()

frmMain.datPrimaryRS.RecordSource = "select * from 部门信息"
Dim i As Integer
For i = 0 To 5
Set frm部门信息0.txtFields(i).DataSource = frmMain.datPrimaryRS
frm部门信息0.txtFields(i).DataField = Trim(frm部门信息0.lblLabels(i).Caption)
Next

End Sub


下面是我模块的代码

Public Sub cmdAdd1(datPrimaryRS As Adodc, frmMain As Form)
On Error GoTo err2147467259
frmMain.datPrimaryRS.Recordset.AddNew
err2147467259:
If Err.Number = -2147467259 Then
MsgBox "不能有重复的字段,请仔细检查后再输入", vbInformation, "输入错误"
End If
End Sub

Public Sub cmdDelete1(cmdDelete As CommandButton, datPrimaryRS As Adodc, frmMain As Form)
If frmMain.datPrimaryRS.Recordset.AbsolutePosition <> adPosEOF Then
Dim msgFlag As String
msgFlag = MsgBox("真的要删除记录吗?将不可恢复..", vbYesNo + vbInformation, "确定删除...")
If msgFlag = vbYes Then
frmMain.datPrimaryRS.Recordset.Delete
frmMain.datPrimaryRS.Recordset.MoveNext
Else
Exit Sub
End If

Else
cmdDelete.Enabled = False
End If
End Sub

Public Sub cmdRefresh1(datPrimaryRS As Adodc, frmMain As Form)
frmMain.datPrimaryRS.Refresh
End Sub

Public Sub cmdUpdate1(datPrimaryRS As Adodc, cmdDelete As CommandButton, frmMain As Form)
On Error GoTo err3021

frmMain.datPrimaryRS.Recordset.Update
cmdDelete.Enabled = True

err3021:
If Err.Number = 3021 Then
MsgBox "没有添加数据,不能保存", vbInformation, "保存出错..."
End If

End Sub


Public Sub Command11(Command1 As CommandButton, ByVal index As Integer, datPrimaryRS As Adodc, frmMain As Form)

Select Case index
Case 0 '移到第一条
On Error GoTo err3021
Command1(0).Enabled = False
Command1(3).Enabled = True
Command1(2).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveFirst
err3021:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 1 '移到上一条
On Error GoTo err30211
If frmMain.datPrimaryRS.Recordset.AbsolutePosition = adPosBOF Then
Command1(1).Enabled = False

Else
Command1(2).Enabled = True
Command1(0).Enabled = True
Command1(3).Enabled = True
frmMain.datPrimaryRS.Recordset.MovePrevious
End If
err30211:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 2 '移到下一条
On Error GoTo err30212
If frmMain.datPrimaryRS.Recordset.AbsolutePosition = adPosEOF Then
Command1(2).Enabled = False

Else
Command1(1).Enabled = True
Command1(0).Enabled = True
Command1(3).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveNext

End If
err30212:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If
Case 3 '移到最未条
On Error GoTo err30213
Command1(0).Enabled = True
Command1(3).Enabled = False
Command1(1).Enabled = True
frmMain.datPrimaryRS.Recordset.MoveLast
err30213:
If Err.Number = 3021 Then
MsgBox "数据库没有数据", vbInformation, "移动出错..."
End If

End Select

End Sub



/images/2011/147787/2011051411021524.jpg" border="0" />
2007-01-10 16:45
快速回复:[求助]如何在模块里定义一个按钮数组的的子程序!
数据加载中...
 
   



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

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