Check Internet Connection

By KuTsuM on Sep 26, 2007

This snippet will check if your computer is currently logged onto the internet in VB.NET. This is especially useful if you are using winsock

Module CheckNetwork
    Sub main()
        If My.Computer.Network.IsAvailable = True Then
            System.Console.WriteLine("Computer is connected.")
        Else
            System.Console.WriteLine("Computer is not connected.")
        End If
        System.Console.ReadLine()
    End Sub
End Module

Comments

Sign in to comment.
Jonesy44   -  Dec 04, 2009

VisualBasic is my current AS level course language, which i get on with quite well, unlike my rather stupidsounding comments on here! i have somewhat a reluctance to try things out for myself -- mainly because Visual Studio takes such a dam long time too load! haha

Thanks :)

 Respond  
Sockreg   -  Dec 02, 2009

If you're into scripting I would suggest F# .. It basically gives you all the benefits of a compiled language and the agile/cool features of a scripting language.. It's pretty much the next big thing in Microsoft and considered to be the language of the future :)

 Respond  
Jonesy44   -  Dec 02, 2009

Okay, i sort of see. I'm fairly new to this -- although been using various computer languages they've been scripts rather than compiled programs.

 Respond  
Sockreg   -  Dec 02, 2009

The imports keyword is only used to create a shorthand notation for ease of use of the underlying namespace classes. When converted to MSIL the hardcoded IL written is actually System.Console.WriteLine ...

You are actually "importing" the functionality of an assembly when you add it to your project reference's file. P.S you can only use Imports when an external assembly is referenced.

 Respond  
Jonesy44   -  Dec 01, 2009

so by using system.console, or another cmd like that you are "temporarily" importing those class libraries?

 Respond  
^Neptune   -  Dec 01, 2009

Yeah, System.Console is unneeded. To go even further you can use "Imports System.Console" and simply use "WriteLine" and "ReadLine".

 Respond  
Sockreg   -  Dec 01, 2009

This snippet does not detect if your computer is connected to the internet. It actually determines if your computer is connected to a network (like LAN etc) :)

 Respond  
Jonesy44   -  Sep 28, 2009

Why System.Console.etc, why not just Console.WriteLine? I'm fairly new to .net :)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.