Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Please help explain this code...

Please help explain this code...

Scheduled Pinned Locked Moved Visual Basic
tutorialquestionhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JackIsMe777
    wrote on last edited by
    #1

    :confused: I was given this code when I asked if anyone knew how to check if a user of my Visual Basic program is connected to the internet so that I can handle "Page cannot be displayed" errors, however I am a newbe to visual basic and this code does not make any sence to me, nor do I know how to use it... Can someone explain what steps I would follow to impliment this code? For example, where do I put this code? How do I call the function? Thanks.

    Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef _
    lpSFlags As Long, ByVal dwReserved As Long) As Long
    Const INTERNET_CONNECTION_MODEM = 1
    Const INTERNET_CONNECTION_LAN = 2
    Const INTERNET_CONNECTION_PROXY = 4
    Const INTERNET_CONNECTION_MODEM_BUSY = 8

    ' return True if there is an active Internect connection
    '
    ' optionally returns the connection mode through
    ' its argument (see INTERNET_CONNECTION_* constants)
    ' 1=modem, 2=Lan, 4=proxy
    ' 8=modem busy with a non-internet connection

    Function IsConnectedToInternet(Optional connectMode As Integer) As Boolean
    Dim flags As Long
    ' this ASPI function does it all
    IsConnectedToInternet = InternetGetConnectedState(flags, 0)
    ' return the flag through the optional argument
    connectMode = flags
    End Function

    S 1 Reply Last reply
    0
    • J JackIsMe777

      :confused: I was given this code when I asked if anyone knew how to check if a user of my Visual Basic program is connected to the internet so that I can handle "Page cannot be displayed" errors, however I am a newbe to visual basic and this code does not make any sence to me, nor do I know how to use it... Can someone explain what steps I would follow to impliment this code? For example, where do I put this code? How do I call the function? Thanks.

      Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef _
      lpSFlags As Long, ByVal dwReserved As Long) As Long
      Const INTERNET_CONNECTION_MODEM = 1
      Const INTERNET_CONNECTION_LAN = 2
      Const INTERNET_CONNECTION_PROXY = 4
      Const INTERNET_CONNECTION_MODEM_BUSY = 8

      ' return True if there is an active Internect connection
      '
      ' optionally returns the connection mode through
      ' its argument (see INTERNET_CONNECTION_* constants)
      ' 1=modem, 2=Lan, 4=proxy
      ' 8=modem busy with a non-internet connection

      Function IsConnectedToInternet(Optional connectMode As Integer) As Boolean
      Dim flags As Long
      ' this ASPI function does it all
      IsConnectedToInternet = InternetGetConnectedState(flags, 0)
      ' return the flag through the optional argument
      connectMode = flags
      End Function

      S Offline
      S Offline
      shreekar
      wrote on last edited by
      #2

      Hi What type of project are you running - exe, dll etc. Normally, you would put it in a class/module and call the function. For a better reply, you need to give more info. Regards Shreekar Joshi Shreekar http://shreekarishere.blogspot.com

      J 1 Reply Last reply
      0
      • S shreekar

        Hi What type of project are you running - exe, dll etc. Normally, you would put it in a class/module and call the function. For a better reply, you need to give more info. Regards Shreekar Joshi Shreekar http://shreekarishere.blogspot.com

        J Offline
        J Offline
        JackIsMe777
        wrote on last edited by
        #3

        I am creating a .exe file in visual basic. I have a button and a web browser (the standard one that you add from the toolbox) setup to load a webpage in a the web browser when the button is clicked. I am trying to stop the "Page cannot be displayed" page from loading if the user of my program is not connected to the internet, so I want to be able to check if the user is online that way I can route them to an offline version if necessary. My code looks like this:

        Public Class Form1

        Private Sub Button5\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            WebBrowser1.Navigate("http://www.google.com")
        End Sub
        

        End Class

        Thanks again for the help!

        S 1 Reply Last reply
        0
        • J JackIsMe777

          I am creating a .exe file in visual basic. I have a button and a web browser (the standard one that you add from the toolbox) setup to load a webpage in a the web browser when the button is clicked. I am trying to stop the "Page cannot be displayed" page from loading if the user of my program is not connected to the internet, so I want to be able to check if the user is online that way I can route them to an offline version if necessary. My code looks like this:

          Public Class Form1

          Private Sub Button5\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              WebBrowser1.Navigate("http://www.google.com")
          End Sub
          

          End Class

          Thanks again for the help!

          S Offline
          S Offline
          shreekar
          wrote on last edited by
          #4

          Hi In the button click procedure, just call the CheckInternetConnection function. If it is true, then navigate to the internet site, otherwise, show the user offline version. However, you will need to put the declaration and definition of the function in a public module and make the function public as well. HTH Shreekar http://shreekarishere.blogspot.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups