View Single Post
Old Jan 3rd, 2008, 8:39 AM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: Pinger suggestions?

You want comments of course.

With reference to functionality, I couldn't say; I've never written a pinger before. If you wanted to get nifty and write very little code, just use the ping system command:
ping -n 1 -w 2000 google.ca

Which could be used in Visual Basic like so:
VB Syntax (Toggle Plain Text)
  1. Dim PingTimeOut as String
  2. Dim PingIPAddr as String
  3.  
  4. PingTimeOut = "2000"
  5. PingIPAddr = "google.ca"
  6.  
  7. Shell "ping -n 1 -w " & PingTimeOut & " " & PingIPAddr

This way's a lot simpler because it handles all exceptions for you. If the ping doesn't work, ping.exe handles that for you.



And if you want to get nit-picky, I'd turn Chr(13) & Chr(10) into a constant, CRLF (if the constant does not already exist), and reference that, instead of having that annoying code repeating 3-4 times. Especially since CRLF is often something you want to change.

Then turn your PadRight 30's and 20's into some sort of constant MarginRight variable, and base your calculations off that.

Finally, your ping timeout of 2000ms could be user defined as a textCtrl or slider in the Graphical Interface, or referenced as another constant, PingTimeout.

Last edited by Sane; Jan 3rd, 2008 at 8:58 AM.
Sane is offline   Reply With Quote