Private Declare Function InternetHangUp Lib "wininet.dll" _
(ByVal dwConnection As Long, _
ByVal dwReserved As Long) As Long
Private Declare Function InternetAutodial Lib "wininet.dll" _
(ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetAutodialHangup Lib "wininet.dll" _
(ByVal dwReserved As Long) As Long
Private Sub Check1_Click()
判斷用戶的選擇
If Check1.Value = 0 Then
Text2.Enabled = False
Check2.Value = 0
Else
Text2.Enabled = True
End If
End Sub
Private Sub Check2_Click()
判斷用戶的選擇
If Check2.Value = 0 Then
Text3.Enabled = False
Else
Text3.Enabled = True
End If
End Sub
Private Sub Command1_Click()
使設置生效并顯示設置信息
Dim alert1, alert2
If Check1.Value = 1 And Check2.Value = 1 Then
If Not IsDate(Text2.Text) Or Not IsDate(Text3.Text) Then
MsgBox ("你輸入的不是時間格式,請重試!")
Else
alert1 = Text2.Text
alert2 = Text3.Text
Label2.Caption = "注意:計算機將在" + Text2.Text + "登陸網絡"
Label3.Caption = "注意:計算機將在" + Text3.Text + "斷開網絡"
Timer1.Enabled = True
End If
Else
If Check1.Value = 1 Then
If Not IsDate(Text2.Text) Then
MsgBox ("你輸入的不是時間格式,請重試!")
Else
alert1 = Text2.Text
Label2.Caption = "注意:計算機將在" + Text2.Text + "登陸網絡"
Timer1.Enabled = True
End If
End If
End If
End Sub
Private Sub Command2_Click()
取消設置并顯示取消信息
If Check1.Value = 1 And Check2.Value = 1 Then
Text2.Text = "00:00:00"
Text3.Text = "00:00:00"
Timer1.Enabled = False
Label2.Caption = "注意:你已取消了定時登陸網絡"
Label3.Caption = "注意:你已取消了定時斷開網絡"
Else
If Check1.Value = 1 Then
Text2.Text = "00:00:00"
Timer1.Enabled = False
Label2.Caption = "注意:你已取消了定時登陸網絡"
End If
End If
End Sub
Private Sub Command3_Click()
這里默認以163撥號方式實現登陸,其它撥號方式只需修改一下參數就可以了。
InternetDial Me.hWnd, "163", INTERNET_AUTODIAL_FORCE_UNATTENDED, iHandle, 0
End Sub
Private Sub Form_Load()
初始化上網和下網的時間格式
Text2.Text = "00:00:00"
Text3.Text = "00:00:00"
End Sub
Private Sub Timer1_Timer()
根據用戶的選擇來判斷實現定時上下網
Dim A
If Check1.Value = 1 And Check2.Value = 1 Then
Text1.Text = Time
A = TimeValue(Text1.Text)
If Text2.Text = A Then
InternetDial Me.hWnd, "163", INTERNET_AUTODIAL_FORCE_UNATTENDED, iHandle, 0
Else
If Text3.Text = A Then
If iHandle <> 0 Then
InternetHangUp iHandle, 0
iHandle = 0
End If
End If
End If
Else
If Check1.Value = 1 Then
Text1.Text = Time
A = TimeValue(Text1.Text)
If Text2.Text = A Then
InternetDial Me.hWnd, "163", INTERNET_AUTODIAL_FORCE_UNATTENDED, iHandle, 0
End If
End If
End If
End Sub
Private Sub Timer2_Timer()
顯示當前時間
Text1.Text = Time
End Sub
|