Example 6 - test if computer is connected to Internet

<< Click to Display Table of Contents >>

Navigation:  Introducing ThinBASIC >

Example 6 - test if computer is connected to Internet

 

Test if computer is connected to Internet, in which way and report IPs.

       

Uses "inet", "ras"

 

'------------------------------------------------------------------------

' Main program - does not need to be in TBMain function, like in example 3

'------------------------------------------------------------------------

Dim Msg     As String

Dim IPCount As Long

 

If RunConnectToInternet() = True Then

   Msg = "You are connected to Internet." + $crlf + ' Notice how can you span strings across multiple lines

        "Your current connection mode is: " + INET_GetConnectionMode + $crlf

Else

   Msg = "You are NOT connected to Internet." + $crlf

End If

 

 Msg = Msg + "You have " + INET_GetIP(0) + " IPs on your box." + $crlf

 

If INET_GetIP(0) > 1 Then

   Msg += "They are:" + $crlf ' Msg += ... is equivalent of Msg = Msg + ...

Else

   Msg += "It is:" + $crlf

End If

 

For IPCount = 1 To INET_GetIP(0)

   Msg += INET_GetIP(IPCount) + $crlf

Next

 

MsgBox 0, Msg

 

'--------------------------------------------------------------------------

'Check if connection to internet is active

'If not active standard connection dialog box is started

'--------------------------------------------------------------------------

Function RunConnectToInternet() As Long

'--------------------------------------------------------------------------

 

  '--- Check current connection status

  Long IConnected = INET_GetState

 

  '---                                      

  'If already connected then use current connection

  'otherwise try to make a connection

  '---

  If not IConnected Then  

    '-If not connected, try to run AutoDialing windows functionality

    Ras_OpenDialUpDialog

 

    '-Check again connection

     IConnected = INET_GetState

 

    '-If not connect again, error message

    If not IConnected Then

      String Message = "It was not possible to connect to Internet."

      MsgBox 0, Message, %MB_OK OR %MB_ICONEXCLAMATION, "Error During Internet Connection."

    End If

  End If

 

  Return IConnected

 

End Function