vb 如何编写控制程序

有一个记事本文件,帮助.txt。要求编写一个VB程序,只有点击command1,才能打开这个记事本文件编辑修改,而无法直接打开这个记事本文件。... 有一个记事本文件,帮助.txt。要求编写一个VB程序,只有点击 command1,才能打开这个记事本文件 编辑修改, 而无法直接打开 这个记事本文件。 展开
 我来答
iiv58197
2011-01-20 · TA获得超过2625个赞
知道小有建树答主
回答量:713
采纳率:0%
帮助的人:658万
展开全部
1
Private reUser As Recordset

Private Sub cmbUser_Click()
Dim re2 As Recordset
Set re2 = dbYY.OpenRecordset("SELECT * FROM user WHERE 操作员='" & cmbUser.Text & "'")
txtQx.Text = re2(2)
re2.Close
Czy = cmbUser.Text
End Sub

Private Sub Form_Load()
On Error Resume Next
Set reUser = dbYY.OpenRecordset("SELECT * FROM user")
Do While Not reUser.EOF
cmbUser.AddItem reUser(0)
reUser.MoveNext
Loop
cmbUser.ListIndex = 0

End Sub

Private Sub cmdOk_Click()
reUser.MoveFirst
'判断密码
Do While Not reUser.EOF
If reUser.Fields("操作员") = cmbUser.Text Then
Let mm = Trim(reUser.Fields("密码"))
End If
reUser.MoveNext
Loop

If Trim(txtMm.Text) = mm Then
Unload Me
MDIForm1.Show
Else
MsgBox "操作员密码错误!", vbExclamation, "提示信息"
txtMm.Text = ""
txtMm.SetFocus
Exit Sub
End If
MDIForm1.SBar1.Panels(1).Text = "当前操作员:" & Czy

End Sub

Private Sub cmdNo_Click()
dbYY.Close
Set dbYY = Nothing
End
End Sub

Private Sub txtMm_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then cmdOk_Click
End Sub

2
Private reUser As Recordset
Private sql As String
Private blnEdit As Boolean

Private Sub Form_Load()
CenterForm Me

txtUser.Enabled = False
txtMm.Enabled = False
CmbQx.Enabled = False
blnEdit = False

sql = "SELECT * FROM user ORDER BY ID"
Set reUser = dbYY.OpenRecordset(sql)
Dt1.DatabaseName = DBName
Dt1.RecordSource = sql
Dt1.Refresh

If reUser.RecordCount = 0 Then Exit Sub

Grid1.ColWidth(0) = 0
Grid1.ColWidth(2) = 0
Grid1.ColWidth(4) = 0
Tlbar.Buttons(3).Enabled = False
Tlbar.Buttons(4).Enabled = False
Tlbar.Buttons(5).Enabled = False
End Sub

Private Sub Add()
Tlbar.Buttons(3).Enabled = False
Tlbar.Buttons(4).Enabled = False
Tlbar.Buttons(5).Enabled = True
txtUser.Enabled = True
txtMm.Enabled = True
txtUser.Text = ""
txtMm.Text = ""
CmbQx = "普通用户"
txtUser.SetFocus
End Sub

Private Sub Save() '保存
On Error GoTo errSave
If txtUser = "" Then Exit Sub

If blnEdit = False Then
Dim re1 As Recordset
Dim i
Set re1 = dbYY.OpenRecordset("SELECT ID FROM user ORDER BY id")
re1.MoveLast
i = re1(0)
re1.Close
reUser.AddNew
reUser.Fields(0) = txtUser.Text
reUser.Fields(1) = txtMm.Text
reUser.Fields(2) = CmbQx
reUser.Fields(3) = i + 1
reUser.Update
Else
dbYY.Execute "UPDATE user SET 操作员='" & txtUser & "',密码='" & txtMm & "' WHERE ID=" & txtBh & ";"
blnEdit = False
End If

txtUser.Text = ""
txtMm.Text = ""
CmbQx.Text = "选择权限"
txtUser.Enabled = False
txtMm.Enabled = False
Dt1.Refresh
Grid1.SetFocus

Exit Sub
errSave:
MsgBox Err.Description, vbInformation + vbOKOnly, "提示信息"
End Sub

Private Sub Grid1_Click()
txtUser = Grid1.TextMatrix(Grid1.Row, 1)
txtMm = Grid1.TextMatrix(Grid1.Row, 2)
CmbQx = Grid1.TextMatrix(Grid1.Row, 3)
txtBh = Grid1.TextMatrix(Grid1.Row, 4)
Tlbar.Buttons(3).Enabled = True
Tlbar.Buttons(4).Enabled = True
End Sub

Private Sub Tlbar_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "Add" '添加
Add
Case "Edit" '修改
blnEdit = True

Tlbar.Buttons(5).Enabled = True
txtMm.Enabled = True
txtMm.SetFocus
If CmbQx = "超级用户" Then txtUser.Enabled = True

Case "Save" '保存
Tlbar.Buttons(3).Enabled = False
Tlbar.Buttons(4).Enabled = False
Tlbar.Buttons(5).Enabled = False
Save
Case "Del" '删除
If CmbQx = "超级用户" Then
MsgBox "不能删除超级用户!但可以修改操作员名。", vbOKOnly + vbInformation, "提示信息"
Exit Sub
End If

r = MsgBox("是否确认删除操作员?", vbInformation + vbYesNo + vbDefaultButton2, "提示信息")
If r = vbYes Then
dbYY.Execute "DELETE * FROM user WHERE ID=" & txtBh & ";"
Dt1.Refresh
Grid1.SetFocus

txtUser.Text = ""
txtMm.Text = ""
CmbQx.Text = "选择权限"
Tlbar.Buttons(3).Enabled = False
Tlbar.Buttons(4).Enabled = False
Tlbar.Buttons(5).Enabled = False
End If
Case "Exit" '关闭
reUser.Close
Unload Me
End Select
End Sub

Private Sub txtMm_KeyDown(KeyCode As Integer, Shift As Integer)
If txtMm <> "" And KeyCode = vbKeyReturn Then
Save
End If
End Sub

Private Sub txtMm_KeyPress(KeyAscii As Integer)
If KeyAscii = 34 Or KeyAscii = 39 Or KeyAscii = 44 Then
MsgBox "不能输入单引号、双引号或者逗号做密码," & Chr(10) _
& "请输入字母或者数字,防止系统出错!", vbCritical + vbOKOnly, "系统提示"
txtMm.SetFocus
txtMm.Text = ""
End If
End Sub

Private Sub txtUser_KeyDown(KeyCode As Integer, Shift As Integer)
If txtUser <> "" And KeyCode = vbKeyReturn Then
txtMm.SetFocus
End If
End Sub

下面是模块代码
Option Explicit
Public dbYY As Database '全局系统数据库
Public DBName As String '全局数据库文件路径
Public Czy As String '全局操作员
Public Const rowClr = &HE0E0E0 'MSFLexgrid表格行灰颜色

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Sub Main()
On Error GoTo noDB
DBName = App.Path & "\yygl.mdb"

'打开系统数据库
Set dbYY = OpenDatabase(DBName, False, False)

'启动封面
frmCover.Show
Exit Sub
noDB: '出错处理
MsgBox Err.Description & " 请与系统管理员联系!", vbCritical, "技术支持"
End '出错后,退出系统
Exit Sub
End Sub

Public Function CenterForm(FormName As Form) As Long
FormName.Top = (Screen.Height - FormName.ScaleHeight) / 2 - 1000
FormName.Left = (Screen.Width - FormName.ScaleWidth) / 2 - 100
End Function

然后窗口中的控件你就看着代码自己添吧……
数据库自己建一个,数据库名称在模块代码里写着有
注意其中有些代码你可根据你自己的情况修改或者删除,比如模块里有一个启动封面的代码,你如果不要封面,可以更改或删除
WindowsCleane
2011-01-19 · 超过11用户采纳过TA的回答
知道答主
回答量:24
采纳率:0%
帮助的人:0
展开全部
这样做的话会很麻烦 建议向文件夹方向想
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
江江0522
2011-01-19
知道答主
回答量:20
采纳率:0%
帮助的人:7.9万
展开全部
有点难,在下不会。Sorry .
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式