登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

面包会有的

... ...

 
 
 

日志

 
 

我的第一个VB程序  

2007-08-28 12:19:32|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

 

        今天是2007-8-28日,今天,我要为我的第一个VB程序搜集资料,准备做一个功能齐全的通讯录,想想要不了多久就能看到效果,不免有一点点期待,现在做asp已经没有什么意思了,这次学VB也是一个偶然的决定,经过这几天的学习,还是有一些效果的,现在,对数据库的连接、编辑、显示、删除都没有问题了,只需对效果性的内容搜集些资料。

        功能预计有:常规的添加、编辑、删除、查找,热度定义(根据重要程度,对久未联系的提示回访),日程安排,闹铃,导出TXT,数据库备份、恢复、压缩。 

         分类功能:交叉、无限级分类,同一单位查看,同一地区查看,拼音搜索,语音阅读。

         输入“赵”时,会把通讯录中所有姓赵的人的通讯信息全部显示出来以供选择

 ------------------------------------------------------------------------------------------------

 VB6.0中数据库连接示例:

------------------------------------------------------------------------------------------------

Private Sub Command1_Click()
    Adodc1.Refresh
End Sub

Private Sub Command2_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    '窗体定义时,查询日志表
    Dim Sc As String
    Sc = "driver={Microsoft Access Driver (*.mdb)};dbq=" & App.Path & "\tradeunion.mdb"
    Set cn = New ADODB.Connection
    cn.Open Sc
    Dim OneQuerySql As String
    OneQuerySql = "select * from 日志表 order by 操作时间 desc"
    Dim AdoRsTradeMem As New ADODB.Recordset
    If AdoRsTradeMem.State = adStateOpen Then
        AdoRsTradeMem.Close
    End If
    AdoRsTradeMem.Open OneQuerySql, cn, adOpenKeyset, adLockOptimistic
    Set Adodc1.Recordset = AdoRsTradeMem
End Sub


'备忘与说明:连接ACCESS2000数据库,并显示日志
'先在DataEnvironment1窗口设置Connect1,在右键菜单“提供程序”里设置Jet 4.0 Ole Db那一项,再设置“连接”,选择ACCESS2000数据库
'点“测试连接”按钮,如果提示“连接正确”,说明数据库成功连接。

'建一ADODC1控件
'建一DATA Grid 控件,DataSourse 属性设置为ADODC1

---------------------------------------------------------------------------------------------

  数据库记录编辑

---------------------------------------------------------------------------------------------

Private Sub cancelCommand_Click()
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = True
        Command1.Enabled = True
        Adodc1.Refresh
End Sub

Private Sub Command1_Click()
    '点击“添加新会员”
    txtAddress.Enabled = True
    txtBirthdate.Enabled = True
    txtComment.Enabled = True
    txtDept.Enabled = True
    txtDuty.Enabled = True
    txtEducation.Enabled = True
    txtJobtime.Enabled = True
    txtJointime.Enabled = True
    txtName.Enabled = True
    txtNation.Enabled = True
    txtPersona.Enabled = True
    txtPolitical.Enabled = True
    txtPopulation.Enabled = True
    txtWife.Enabled = True
    comboSex.Enabled = True
    firstCommand.Enabled = False
    previousCommand.Enabled = False
    nextCommand.Enabled = False
    lastCommand.Enabled = False
    editCommand.Enabled = False
    updateCommand.Enabled = False
    cancelCommand.Enabled = False
    deleteCommand.Enabled = False
    Command2.Enabled = False
    Command3.Enabled = True
    Command1.Enabled = False
    Adodc1.Recordset.AddNew
End Sub

Private Sub Command2_Click()
    If Not (Testtxt(txtAddress.Text) And Testtxt(txtBirthdate.Text) And Testtxt(txtComment.Text) And Testtxt(txtDept.Text) And Testtxt(txtDuty.Text) And Testtxt(txtEducation.Text) And Testtxt(txtJobtime.Text) And Testtxt(txtJointime.Text) And Testtxt(txtName.Text) And Testtxt(txtNation.Text) And Testtxt(txtPersona.Text) And Testtxt(txtPolitical.Text) And Testtxt(txtPopulation.Text) And Testtxt(txtWife.Text)) Then
        MsgBox "信息输入不完整,请检查并确认信息!", vbOKOnly + vbExclamation, "请注意"
        txtName.SetFocus
        Exit Sub
    End If
    If Not IsNumeric(Trim(txtPopulation)) Then
        MsgBox "家庭人口,请输入数字!", vbOKOnly + vbExclamation, "请注意"
        txtPopulation.SetFocus
        Exit Sub
    End If
    If Not (IsDate(txtBirthdate.Text) And IsDate(txtJobtime.Text) And IsDate(txtJointime.Text)) Then
        MsgBox "日期时间格式应为:YYYY-MM-DD,请确认输入无误!", vbOKOnly + vbExclamation, "请注意"
        txtBirthdate.SetFocus
    Else
        Adodc1.Recordset.Update
        Call LogPlug("会员信息", "添加新会员:" & Trim(txtName.Text))
        MsgBox "添加会员信息成功!", vbOKOnly + vbExclamation, "恭喜"
        Adodc1.Recordset.MoveLast
    End If
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = False
        Command1.Enabled = True
End Sub

Private Sub Command3_Click()
    Unload Me
End Sub

Private Sub deleteCommand_Click()
    str2 = MsgBox("你确定删除当前记录吗?!", vbOKCancel, "删除当前记录")
    If str2 = vbOK Then
        Call LogPlug("会员信息", "删除会员:" & Trim(txtName.Text) & "的信息。")
        If Adodc1.Recordset.RecordCount = 1 Then
            Adodc1.Recordset.Delete
            Unload Me
            Me.Show
        Else
            Adodc1.Recordset.MoveNext
            If Adodc1.Recordset.EOF Then
                Adodc1.Recordset.MoveLast
                Adodc1.Recordset.Delete
                Adodc1.Recordset.MoveFirst
            Else
                Adodc1.Recordset.MovePrevious
                Adodc1.Recordset.Delete
                Adodc1.Recordset.MoveNext
            End If
        End If
    End If
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = False
        Command1.Enabled = True
End Sub

Private Sub editCommand_Click()
    txtAddress.Enabled = True
    txtBirthdate.Enabled = True
    txtComment.Enabled = True
    txtDept.Enabled = True
    txtDuty.Enabled = True
    txtEducation.Enabled = True
    txtJobtime.Enabled = True
    txtJointime.Enabled = True
    txtName.Enabled = True
    txtNation.Enabled = True
    txtPersona.Enabled = True
    txtPolitical.Enabled = True
    txtPopulation.Enabled = True
    txtWife.Enabled = True
    comboSex.Enabled = True
    firstCommand.Enabled = False
    previousCommand.Enabled = False
    nextCommand.Enabled = False
    lastCommand.Enabled = False
    editCommand.Enabled = False
    updateCommand.Enabled = True
    cancelCommand.Enabled = True
    deleteCommand.Enabled = True
    Command2.Enabled = False
    Command3.Enabled = False
    Command1.Enabled = False
End Sub

Private Sub firstCommand_Click()
    Adodc1.Recordset.MoveFirst
End Sub

Private Sub Form_Load()
    '当窗体载入时,首先查询“会员基本信息表”
    Dim Sc As String
    Sc = "driver={Microsoft Access Driver (*.mdb)};dbq=" & App.Path & "\tradeunion.mdb"
    Set cn = New ADODB.Connection
    cn.Open Sc
    Dim OneQuerySql As String
    OneQuerySql = "select* from 会员基本信息表"
    Dim AdoRsTradeMem As New ADODB.Recordset
    If AdoRsTradeMem.State = adStateOpen Then
        AdoRsTradeMem.Close
    End If
    AdoRsTradeMem.Open OneQuerySql, cn, adOpenKeyset, adLockOptimistic
    Set Adodc1.Recordset = AdoRsTradeMem
    If Adodc1.Recordset.EOF Then
        MsgBox "系统内不存在任何会员基本信息,请先添加会员信息", vbOKOnly + vbExclamation, "警告"
        txtAddress.Enabled = True
        txtBirthdate.Enabled = True
        txtComment.Enabled = True
        txtDept.Enabled = True
        txtDuty.Enabled = True
        txtEducation.Enabled = True
        txtJobtime.Enabled = True
        txtJointime.Enabled = True
        txtName.Enabled = True
        txtNation.Enabled = True
        txtPersona.Enabled = True
        txtPolitical.Enabled = True
        txtPopulation.Enabled = True
        txtWife.Enabled = True
        comboSex.Enabled = True
        firstCommand.Enabled = False
        previousCommand.Enabled = False
        nextCommand.Enabled = False
        lastCommand.Enabled = False
        editCommand.Enabled = False
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = False
        Command2.Enabled = False
        Command3.Enabled = True
        Command1.Enabled = False
        Adodc1.Recordset.AddNew
        Exit Sub
    Else
        Adodc1.Recordset.MoveFirst
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = True
        Command1.Enabled = True

    End If
End Sub

 

'在窗口建一ADODC1控件,
Private Sub Label12_Click()

End Sub

Private Sub lastCommand_Click()
    Adodc1.Recordset.MoveLast
End Sub

Private Sub nextCommand_Click()
    If Adodc1.Recordset.EOF Then
        Adodc1.Recordset.MoveFirst
    Else
        Adodc1.Recordset.MoveNext
    End If
End Sub

Private Sub previousCommand_Click()
    If Adodc1.Recordset.BOF Then
        Adodc1.Recordset.MoveLast
    Else
        Adodc1.Recordset.MovePrevious
    End If
End Sub

Private Sub updateCommand_Click()
    If Not (Testtxt(txtAddress.Text) And Testtxt(txtBirthdate.Text) And Testtxt(txtComment.Text) And Testtxt(txtDept.Text) And Testtxt(txtDuty.Text) And Testtxt(txtEducation.Text) And Testtxt(txtJobtime.Text) And Testtxt(txtJointime.Text) And Testtxt(txtName.Text) And Testtxt(txtNation.Text) And Testtxt(txtPersona.Text) And Testtxt(txtPolitical.Text) And Testtxt(txtPopulation.Text) And Testtxt(txtWife.Text)) Then
        MsgBox "信息输入不完整,请检查并确认信息!", vbOKOnly + vbExclamation, "请注意"
        txtName.SetFocus
        Exit Sub
    End If
    If Not IsNumeric(Trim(txtPopulation)) Then
        MsgBox "家庭人口,请输入数字!", vbOKOnly + vbExclamation, "请注意"
        txtPopulation.SetFocus
        Exit Sub
    End If
    If Not (IsDate(txtBirthdate.Text) And IsDate(txtJobtime.Text) And IsDate(txtJointime.Text)) Then
        MsgBox "日期时间格式应为:YYYY-MM-DD,请确认输入无误!", vbOKOnly + vbExclamation, "请注意"
        txtBirthdate.SetFocus
    Else
        Adodc1.Recordset.Update
        Call LogPlug("会员信息", "修改会员:" & Trim(txtName.Text) & "的信息。")
        MsgBox "修改会员信息成功!", vbOKOnly + vbExclamation, "恭喜"
    End If
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = True
        Command1.Enabled = True
End Sub

 

 

 

  评论这张
 
阅读(573)| 评论(0)

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018