虽然 VB 已死。。但用来写写桌面小软件还是挺不错的。不过我算是还给了老师。。忘的差不多了。。~~~~~~~~~~
很早以前用VB写的。。。也就几行代码。。。。没有一点技术含量
下载 无需 安装。。直接运行即可。。
截图:
下载地址:
http://www.blogjava.net/Files/wujun/mysoft.rar关键代码:
链接数据库:
Public Function contoserver()Function contoserver() As Boolean '连接数据库函数
On Error GoTo Conerror
con.CursorLocation = adUseClient
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\db.mdb;" & "Persist Security Info=False"
'con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password=wujunainiyiwn;Data Source=E:\数据\vars.mdb;Persist Security Info=True"
con.CommandTimeout = 20
con.Open
contoserver = True
Exit Function
Conerror:
MsgBox "问题,!", vbExclamation + vbOKOnly, "严重问题"
contoserver = False
End Function
Public Function closecon()Function closecon() As Boolean '关闭连接的函数
On Error Resume Next
If (Not con Is Nothing) Then con.Close
Set con = Nothing
End Function
Public Function runSQL()Function runSQL(ByVal strsql As String) As Boolean '执行查询语句的函数
On Error GoTo runerror
Set rst = Nothing
Set rst = New ADODB.Recordset
rst.Open strsql, con, adOpenDynamic, adLockOptimistic, -1
runSQL = True
Exit Function
runerror:
MsgBox "运行这句出错了", vbExclamation + vbOKOnly, "提示"
' MsgBox "错误编号:" & Err.Number & vbCrLf _
& "错误描述:" & Err.Description, vbCritical + vbOKOnly, "连接错误"
runSQL = False
End Function
小技巧:
VB 引入超链接按钮
1.定义
Private Declare Function ShellExecute()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
2.使用
ShellExecute Me.hWnd, "open", "http://www.blogjava.net/wujun", vbNullString, vbNullString, vbNormalFocus textBox 只能输入数字:
Private Sub Text2_KeyPress()Sub Text2_KeyPress(KeyAscii As Integer)
Dim a As Boolean
a = Chr(KeyAscii) Like "[0-9]" Or KeyAscii = 8
If a = False Then
KeyAscii = 0
MsgBox "这里输入的可是要数字的哦!", vbInformation + vbOKOnly, "提示"
End If
End Sub