Please help explain this code...
-
: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 connectionFunction 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 -
: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 connectionFunction 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 FunctionHi 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
-
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
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!
-
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!
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