[RESOLVED] Link Label and Internet connection
When using a link label, if connecting to a website or anything else on the internet, you obviously need to check to make sure you have a connection before the link can connect. Is there a simple way to do this, maybe something in a module?
Thanks
CoachBarker
Re: Link Label and Internet connection
I think that the only way to see if the user is connected to the internet would be to ping a couple of large sites such as google.com and microsoft.com.
Check out the My.Computer.Network.Ping function.
Re: Link Label and Internet connection
or you could use:
vb Code:
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
'FLAGS
'Modem is busy.
Public Const ModemConnectionIsBusy As Integer = &H8S
'Internet connection is currently Offline
Public Const InternetIsOffline As Integer = &H20S
'Internet connection is currently configured
Public Const InternetConnectionIsConfigured As Integer = &H40S
'Internet connection VIA Modem.
Public Const ModemConnection As Integer = &H1S
Re: Link Label and Internet connection
Looking back through a project I did during my internship, I created an app that needed to check for an IP address to allow certain functions to work. Would this not accomplish the same thing, checking for an active IP address?
Re: Link Label and Internet connection
use the API function from my previous post
vb Code:
msgbox(InternetGetConnectedState(InternetConnectionIsConfigured, 0))
returns 0 if no internet connection, or 1 if connected to the internet
Re: Link Label and Internet connection
Since I have never used an API, how would I implement this?
Re: Link Label and Internet connection
try it this way.
vb Code:
Public Class Form1
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
'Internet connection is currently configured
Private Const InternetConnectionIsConfigured As Integer = &H40S
Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
If InternetGetConnectedState(InternetConnectionIsConfigured, 0) = 0 Then
MsgBox("internet isn't connected", MsgBoxStyle.Information, "information")
ElseIf InternetGetConnectedState(InternetConnectionIsConfigured, 0) = 1 Then
MsgBox("internet is connected", MsgBoxStyle.Information, "information")
End If
End Sub
End Class
Re: Link Label and Internet connection
Thanks, that is just what was called for. Now that school is over I spend some time each day working on different aspects of vb.net that I haven't used in school. I see an interesting post and think to myself "hmmm wonder if I can get that to work", and then play around with it.
The wife thinks I'm crazy, but if this is what I plan on doing for a living, I tell her I can't afford to get rusty and I need to expand my abilities.
Again thanks and have a Happy New Year
Re: [RESOLVED] Link Label and Internet connection
Using VB2005 Class Libraries via My namespace:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'If you want to Ping:
My.Computer.Network.Ping("Host Name")
'If you want to see if you are connected to the Internet
Dim Connected As Boolean = My.Computer.Network.IsAvailable
'e.g.
MessageBox.Show(My.Computer.Network.IsAvailable.ToString)
End Sub
Re: [RESOLVED] Link Label and Internet connection
Quote:
Originally Posted by FourBlades
Using VB2005 Class Libraries via My namespace:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'If you want to Ping:
My.Computer.Network.Ping("Host Name")
'If you want to see if you are connected to the Internet
Dim Connected As Boolean = My.Computer.Network.IsAvailable
'e.g.
MessageBox.Show(My.Computer.Network.IsAvailable.ToString)
End Sub
the Network.IsAvailable property will only tell you if the network is available, not if an internet connection is available.
Re: [RESOLVED] Link Label and Internet connection
For what I was doing the API function provided by .paul worked like a charm. It does exactly what I needed it to do. Thanks for all the advice.
Re: [RESOLVED] Link Label and Internet connection
Hello Paul,
I am new to api, just wanted to try out the example you posted. However, I got the following error.
Unable to find an entry point named 'InternetGetConnection' in DLL 'wininet.dll'.
Just a followup question. what is the second parameter used for? "dwReserved" As you are always passing it a zero.
This is my code:
vb Code:
Public Declare Function InternetGetConnection Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
Public Const modemConnectionBusy As Integer = &H85
Public Const internetIsOffline As Integer = &H205
Public Const internetConnectionIsConfigured As Integer = &H405
Public Const modemConnection As Integer = &H15
Private Sub btnTestInternet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestInternet.Click
If (InternetGetConnection(internetConnectionIsConfigured, 0) = 1) Then 'ERROR
MsgBox("Internet is correctly configured")
Else
MsgBox("Internet is not correctly configured")
End If
End Sub
Thanks for your help,
Steve
Re: [RESOLVED] Link Label and Internet connection
Quote:
Originally Posted by steve_rm
Hello Paul,
I am new to api, just wanted to try out the example you posted. However, I got the following error.
Unable to find an entry point named 'InternetGetConnection' in DLL 'wininet.dll'.
Just a followup question. what is the second parameter used for? "dwReserved" As you are always passing it a zero.
This is my code:
vb Code:
Public Declare Function InternetGetConnection Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
Public Const modemConnectionBusy As Integer = &H85
Public Const internetIsOffline As Integer = &H205
Public Const internetConnectionIsConfigured As Integer = &H405
Public Const modemConnection As Integer = &H15
Private Sub btnTestInternet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestInternet.Click
If (InternetGetConnection(internetConnectionIsConfigured, 0) = 1) Then 'ERROR
MsgBox("Internet is correctly configured")
Else
MsgBox("Internet is not correctly configured")
End If
End Sub
Thanks for your help,
Steve
Given that .paul. posted "InternetGetConnectedState" it's not really a surprise that "InternetGetConnection" can't be found. As for what a parameter means, I would think that MSDN would be the logical place to look for that.
http://msdn2.microsoft.com/en-us/library/aa384702.aspx
Re: [RESOLVED] Link Label and Internet connection
Thanks,
Just have discovered that in my typing.
Steve
Re: [RESOLVED] Link Label and Internet connection
i looked it up on MSDN
dwReserved must be 0