Private Sub Command1_Click() For i = 1 To 10 List1.AddItem Int(100 * Rnd) '随机产生10个数 Next i End Sub
Private Sub Command2_Click() j = List1.ListCount If j 0 Then Min = Val(List1.List(0)) Max = Min
For i = 0 To j - 1 vali = Val(List1.List(i)) If Min vali Then '找最小值 Min = vali imin = i End If If Max vali Then '找最大值 Max = vali imax = i End If Next Print Min, Max List1.RemoveItem (imax) List1.RemoveItem (imin) End If End Sub
Private Sub Form_Load() recs = Adodc1.Recordset.RecordCount '求出当前记录数,recs是模块变量 Text4.Text = recs If recs 0 Then '已有教师时 Adodc1.Recordset.MoveLast '移到最后一个记录 Adodc1.Recordset.MoveFirst '移到开头记录 End If End Sub
Private Sub Form_Activate() DataGrid1.SetFocus '焦点移向DataGrid1控件 Call encomm '调用本窗体自定义的encomm过程 End Sub
Private Sub command3_Click() '添加教师记录 flag = 1 'flag=1表示添加操作 Form4.Show vbModal '调用edt1窗体 End Sub
Private Sub command4_Click() '修改教师记录 flag = 2 'flag=2表示修改操作 Form4.Show vbModal '调用edt1窗体修改当前教师记录 End Sub
Private Sub Command5_Click() If MsgBox(确认要删除吗?, vbOKCancel + vbQuestion, 信息提示) = vbOK Then Adodc1.Recordset.Delete If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast End If End If End Sub Private Sub command6_Click() Unload Me End Sub
Private Sub command1_Click() condstr = '条件表达式,以下代码根据设置条件框架建立condstr If Trim(Text1.Text) Then If condstr = Then condstr = wno like ' + Trim(Text1.Text) + %' End If End If
If Trim(Text2.Text) Then If condstr = Then condstr = wname like ' + Trim(Text2.Text) + %' Else condstr = condstr + and wname like ' + Trim(Text2.Text) + %' End If End If
If Trim(Text3.Text) Then If condstr = Then condstr = wyears like ' + Trim(Text3.Text) + %' Else condstr = condstr + and wyears like ' + Trim(Text3.Text) + %' End If End If
If Option1.Value = True Then If condstr = Then condstr = wsex='男' Else condstr = condstr + and wsex='男' End If ElseIf Option2.Value = True Then If condstr = Then condstr = wsex='女' Else condstr = condstr + and wsex='女' End If End If If condstr Then '有条件,根据 condstr返回相应的记录集 Adodc1.RecordSource = select * from worker1 where + condstr Adodc1.Refresh Else Adodc1.RecordSource = select * from worker1 Adodc1.Refresh End If recs = Adodc1.Recordset.RecordCount Text4.Text = recs If recs = 0 Then MsgBox 没有任何满足条件的记录, obokonly, 信息提示 End If Call encomm '调用本窗体自定义的encomm过程 End Sub
Private Sub command2_Click() '重置,将设置条件框架中的所有输入清空 Text1.Text = : Text2.Text = Text3.Text = Option1.Value = False Option2.Value = False End Sub
Private Sub encomm() '自定义子过程:判断Adodc1中是否存在记录,使相应命令按钮无效或有效 If recs = 0 Then Command4.Enabled = False: Command5.Enabled = False Else Command4.Enabled = True: Command5.Enabled = True End If End Sub
Private Sub Form_Activate() If flag = 2 Then '修改操作 Text1.Text = Trim(Form3.Adodc1.Recordset.Fields(wno)) & Text2.Text = Trim(Form3.Adodc1.Recordset.Fields(wname)) & If Form3.Adodc1.Recordset.Fields(wsex) = 男 Then Option1.Value = True ElseIf Form3.Adodc1.Recordset.Fields(wsex) = 女 Then Option2.Value = True Text3.Text = Trim(Form3.Adodc1.Recordset.Fields(wyears)) &
End If Else Text1 = : Text2 = : Text3 = Option1.Value = False: Option2.Value = False End If End Sub Private Sub command2_Click() '取消操作 Unload Me End Sub
Private Sub command1_Click() If Trim(Text1.Text) = Then MsgBox 加*数据项不能为空,请重新设置, vbOKOnly, 信息提示 Text1.SetFocus Exit Sub End If
If flag = 1 Then '添加操作 recs = recs + 1 Form3.Adodc1.Recordset.AddNew '添加一个记录 End If
If Option1.Value = True Then Form3.Adodc1.Recordset.Fields(wsex) = 男 ElseIf Option2.Value = True Then Form3.Adodc1.Recordset.Fields(wsex) = 女
Else Form3.Adodc1.Recordset.Fields(wsex) = End If 'End If ' If Trim(Text1(2)).Text Then ' edt.Adodc1.Recordset.Fields(tbirthday) = Format(Trim(Text1(2).Text), yy-mm-dd) ' End If
Form3.Adodc1.Recordset.Fields(wyears) = Trim(Text3.Text) Form3.Adodc1.Recordset.Update '保存记录 Unload Me '释放窗体 End Sub 这里面增加 修改 删除 查询都有了,你改下看看可以吧!!! 希望对你有用。