Results 1 to 15 of 15

Thread: [RESOLVED] Link Label and Internet connection

  1. #1

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Resolved [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

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Link Label and Internet connection

    or you could use:

    vb Code:
    1. Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
    2.  
    3. 'FLAGS
    4. 'Modem is busy.
    5. Public Const ModemConnectionIsBusy As Integer = &H8S
    6.  
    7. 'Internet connection is currently Offline
    8. Public Const InternetIsOffline As Integer = &H20S
    9.  
    10. 'Internet connection is currently configured
    11. Public Const InternetConnectionIsConfigured As Integer = &H40S
    12.  
    13. 'Internet connection VIA Modem.
    14. Public Const ModemConnection As Integer = &H1S

  4. #4

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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?
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Link Label and Internet connection

    use the API function from my previous post

    vb Code:
    1. msgbox(InternetGetConnectedState(InternetConnectionIsConfigured, 0))

    returns 0 if no internet connection, or 1 if connected to the internet

  6. #6

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: Link Label and Internet connection

    Since I have never used an API, how would I implement this?
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Link Label and Internet connection

    try it this way.

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
    4.  
    5.     'Internet connection is currently configured
    6.     Private Const InternetConnectionIsConfigured As Integer = &H40S
    7.  
    8.     Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
    9.         If InternetGetConnectedState(InternetConnectionIsConfigured, 0) = 0 Then
    10.             MsgBox("internet isn't connected", MsgBoxStyle.Information, "information")
    11.         ElseIf InternetGetConnectedState(InternetConnectionIsConfigured, 0) = 1 Then
    12.             MsgBox("internet is connected", MsgBoxStyle.Information, "information")
    13.         End If
    14.     End Sub
    15.  
    16. End Class

  8. #8

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  9. #9
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    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

  10. #10
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Last edited by Atheist; Dec 29th, 2007 at 09:16 PM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  11. #11

    Thread Starter
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    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.
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  12. #12
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    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:
    1. Public Declare Function InternetGetConnection Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
    2.     Public Const modemConnectionBusy As Integer = &H85
    3.     Public Const internetIsOffline As Integer = &H205
    4.     Public Const internetConnectionIsConfigured As Integer = &H405
    5.  
    6.     Public Const modemConnection As Integer = &H15
    7.  
    8.     Private Sub btnTestInternet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestInternet.Click
    9.         If (InternetGetConnection(internetConnectionIsConfigured, 0) = 1) Then 'ERROR
    10.             MsgBox("Internet is correctly configured")
    11.         Else
    12.             MsgBox("Internet is not correctly configured")
    13.         End If
    14.  
    15.     End Sub

    Thanks for your help,

    Steve
    Last edited by steve_rm; Dec 29th, 2007 at 11:42 PM.
    steve

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. Public Declare Function InternetGetConnection Lib "wininet.dll" (ByRef lpdwFlags As Integer, ByVal dwReserved As Integer) As Integer
    2.     Public Const modemConnectionBusy As Integer = &H85
    3.     Public Const internetIsOffline As Integer = &H205
    4.     Public Const internetConnectionIsConfigured As Integer = &H405
    5.  
    6.     Public Const modemConnection As Integer = &H15
    7.  
    8.     Private Sub btnTestInternet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestInternet.Click
    9.         If (InternetGetConnection(internetConnectionIsConfigured, 0) = 1) Then 'ERROR
    10.             MsgBox("Internet is correctly configured")
    11.         Else
    12.             MsgBox("Internet is not correctly configured")
    13.         End If
    14.  
    15.     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
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: [RESOLVED] Link Label and Internet connection

    Thanks,

    Just have discovered that in my typing.

    Steve
    steve

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] Link Label and Internet connection

    i looked it up on MSDN

    dwReserved must be 0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width