'''''module1.bas 里面 Public Function Connect1(ByVal c As ADODB.Connection) c.Open "driver=sql server;server=xxglserver;uid=sa;pwd=123;database=xxgl" End FunctionPublic Function Deconnect1(ByVal c As ADODB.Connection) c.Close Set c = Nothing End FunctionPublic Sub Main() Set frmMain = New frmspan '启动对象 frmMain.Show: frmMain.SetFocus End sub '''''frmspan 窗体代码 Dim objconnection As ADODB.Connection Private Sub Form_Load() Label4.Caption = "正在联接数据库服务器,请稍侯······" On Error GoTo aaa Set objconnection = New ADODB.Connection Connect1 objconnection Randomize Timer1.Interval = 5000 + 10 * Rnd Exit Sub aaa: MsgBox "不能正确联接到数据库服务器,请与系统管理员联系!", vbExclamation, "系统信息" End End SubPrivate Sub Form_Unload(Cancel As Integer) Deconnect1 objconnection End SubPrivate Sub Timer1_Timer() Label4.Caption = "正 在 加 载 登 录 界 面" Label4.left = (Me.Width - Label4.Width) / 2 Randomize Timer2.Interval = 1000 + 5 * Rnd End SubPrivate Sub Timer2_Timer() Unload Me frmlogon.Caption = "用户登录" frmlogon.Command3.Visible = False frmlogon.Command1.Visible = True frmlogon.Command4.Visible = False frmlogon.Command2.Visible = True frmlogon.Show frmlogon.SetFocus End Sub
2.数据库服务是否启动(SQLSERVER.EXE)
Public Function Connect1(ByVal c As ADODB.Connection)
c.Open "driver=sql server;server=xxglserver;uid=sa;pwd=123;database=xxgl"
End FunctionPublic Function Deconnect1(ByVal c As ADODB.Connection)
c.Close
Set c = Nothing
End FunctionPublic Sub Main()
Set frmMain = New frmspan '启动对象
frmMain.Show: frmMain.SetFocus
End sub
'''''frmspan 窗体代码
Dim objconnection As ADODB.Connection
Private Sub Form_Load()
Label4.Caption = "正在联接数据库服务器,请稍侯······"
On Error GoTo aaa
Set objconnection = New ADODB.Connection
Connect1 objconnection
Randomize
Timer1.Interval = 5000 + 10 * Rnd
Exit Sub
aaa:
MsgBox "不能正确联接到数据库服务器,请与系统管理员联系!", vbExclamation, "系统信息"
End
End SubPrivate Sub Form_Unload(Cancel As Integer)
Deconnect1 objconnection
End SubPrivate Sub Timer1_Timer()
Label4.Caption = "正 在 加 载 登 录 界 面"
Label4.left = (Me.Width - Label4.Width) / 2
Randomize
Timer2.Interval = 1000 + 5 * Rnd
End SubPrivate Sub Timer2_Timer()
Unload Me
frmlogon.Caption = "用户登录"
frmlogon.Command3.Visible = False
frmlogon.Command1.Visible = True
frmlogon.Command4.Visible = False
frmlogon.Command2.Visible = True
frmlogon.Show
frmlogon.SetFocus
End Sub