|
-
Dec 28th, 2007, 09:41 AM
#1
Thread Starter
Frenzied Member
[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
-
Dec 28th, 2007, 10:23 AM
#2
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.
-
Dec 28th, 2007, 10:38 AM
#3
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
-
Dec 28th, 2007, 12:31 PM
#4
Thread Starter
Frenzied Member
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?
-
Dec 28th, 2007, 12:44 PM
#5
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
-
Dec 28th, 2007, 02:21 PM
#6
Thread Starter
Frenzied Member
Re: Link Label and Internet connection
Since I have never used an API, how would I implement this?
-
Dec 28th, 2007, 04:34 PM
#7
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
-
Dec 28th, 2007, 06:17 PM
#8
Thread Starter
Frenzied Member
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
-
Dec 28th, 2007, 10:54 PM
#9
Frenzied Member
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
-
Dec 29th, 2007, 08:20 PM
#10
Re: [RESOLVED] Link Label and Internet connection
 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.
Last edited by Atheist; Dec 29th, 2007 at 09:16 PM.
-
Dec 29th, 2007, 09:14 PM
#11
Thread Starter
Frenzied Member
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.
-
Dec 29th, 2007, 11:22 PM
#12
Frenzied Member
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
Last edited by steve_rm; Dec 29th, 2007 at 11:42 PM.
steve
-
Dec 30th, 2007, 12:48 AM
#13
Re: [RESOLVED] Link Label and Internet connection
 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
-
Dec 30th, 2007, 03:58 AM
#14
Frenzied Member
Re: [RESOLVED] Link Label and Internet connection
Thanks,
Just have discovered that in my typing.
Steve
-
Dec 30th, 2007, 09:17 AM
#15
Re: [RESOLVED] Link Label and Internet connection
i looked it up on MSDN
dwReserved must be 0
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|