雖然 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