hola he estado probando apis, mas precisamente InternetGetConnectedState para detectar si existe conexion a internet...
la siguiente funcion nos dice si hay conexion a internet o no, si hay conecta, si no hay muestra un msgbox...
Public Function CheckStatusConn() As Boolean
Dim flags As Long
Dim result As Boolean
result = InternetGetConnectedState(flags, 0)
If result Then
Conectar
Else
MsgBox "lo siento"
End If
If flags And INTERNET_CONNECTION_MODEM Then Print "Connection Via Modem"
If flags And INTERNET_CONNECTION_LAN Then Print "Connecion Via LAN"
If flags And INTERNET_CONNECTION_PROXY Then Print "Connection uses a Proxy"
If flags And INTERNET_CONNECTION_MODEM_BUSY Then Print "Connection Via Modem but modem is busy"
End Function
supongamos k konectar tiene:
Public Sub Conectar()
WS.Close
WS.RemoteHost = Servidor
WS.RemotePort = Puerto
WS.Connect
End Sub
y a su vez la funcion CheckStatusConn() es ejecutada en el load del form:
Private Sub Form_Load()
CheckStatusConn
End Sub
ahora lo que quiero yo es que el programa chekee, a cada 30 segundos mas o menos si existe conexion a internet, y si existe que salte a la funcion conectar .. pk asi como lo hice lo chekea solo una vez y no conectara mas si no existe conexion de un principio, me expliko? alguna idea?
ps aki les dejo la api x si les interesa esto a alguien:
Public Declare Function InternetGetConnectedState Lib "wininet" (lpdwFlags As Long, ByVal dwReserved As Long) As Boolean
Public Const INTERNET_CONNECTION_MODEM = 1
Public Const INTERNET_CONNECTION_LAN = 2
Public Const INTERNET_CONNECTION_PROXY = 4
Public Const INTERNET_CONNECTION_MODEM_BUSY = 8
private bOnline as boolean
private sub Timer1...
dim bRet as boolean
bret = CheckStatusConn
if bret then
if not bOnline then
bOnline =true
'aca es donde te conectas
end if
else
bOnline =false
end if
end sub
Podes usar algo tan simple como esto:
Private Sub Command1_Click()
Ws.Connect "www.elhacker.net", 80
End Sub
Private Sub Command2_Click()
Ws.Close
End Sub
Private Sub Timer1_Timer()
If Ws.State = sckConnected Then
EstadoLabel.Caption = "Estado: Conectado"
ElseIf Ws.State = sckClosed Then
EstadoLabel.Caption = "Estado: Desconectado"
Else
EstadoLabel.Caption = "Estado: Desconectado"
End If
End Sub
Con el timer de intervalo 100, o lo que le queras poner.
Al intentar conectar a una pagina el winsock quedara en espera, entonces entra el timer y si no tiene el estado de conectado, supone que no tiene internet, si el winsock esta cerrado, o si no esta cerrado tambien.
Y para usar apis podes utilizar el siguiente codigo, ahi en el tuyo hay una cosa que sobra y es el CheckStatusConn de tipo boleano, no veo que lo uses en otra parte, mira el codigo que hice:
Private Const INTERNET_CONNECTION_OFFLINE = &H20
Private Const INTERNET_CONNECTION_LAN = &H2
Private Const INTERNET_CONNECTION_MODEM = &H1
Private Const INTERNET_CONNECTION_PROXY = &H4
Private Const INTERNET_RAS_INSTALLED = &H10
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()
CheckStatusConn
End Sub
Public Function CheckStatusConn()
Dim Flag As Long
InternetGetConnectedState Flag, 0
Verifica:
If Flag Then
If Flag <> INTERNET_RAS_INSTALLED Then
Conectar
Me.AutoRedraw = True
If Flag And INTERNET_CONNECTION_MODEM Then Print "Conexion Via Modem"
If Flag And INTERNET_CONNECTION_LAN Then Print "Conexion Via LAN"
If Flag And INTERNET_CONNECTION_PROXY Then Print "Conexion usando un Proxy"
If Flag And INTERNET_CONNECTION_OFFLINE Then Print "Sistema local esta fuera de linea"
Else
Flag = 0
GoTo Verifica
End If
Else
MsgBox "lo siento"
End If
End Function
Public Sub Conectar()
WS.Close
WS.RemoteHost = Servidor
WS.RemotePort = Puerto
WS.Connect
End Sub