Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Outputting command data to a label? (http://www.programmingforums.org/showthread.php?t=13923)

PaCkEtPiRaTe Sep 5th, 2007 7:43 PM

Outputting command data to a label?
 
Well, I'm just screwing around a bit and want to make a program to ping the website I input into the text box when I click a button. I want it to output the data of the ping to a label. Here's the code I used... Note I haven't coded in VB for about a year and a half and I'm rusty...

Private Sub cmdPing_Click()
Shell ("ping " + txtPing.Text > lblPing.Caption)
End Sub

I got a Runtime Error 53 saying file not found... Anyone know what's wrong?

mackenga Sep 6th, 2007 6:09 PM

Ack, first up, string concatenation should be &, not +. The code above shouldn't say file not found - something more like type mismatch (txtPing.Text > lblPing.Caption is True if txtPing.Text is greater than lblPing.Caption, which I doubt makes any sense).

Sorry, but I'm not aware of a 'nice' way to make this work in VB6. Off the top of my head, I'd suggest the dirty hack of redirecting ping into a file then reading that file;

:

Private Sub cmdPing_Click()
  Dim intFile As Integer
  Shell ("ping " & txtPing.Text & " > pingoutput.txt")
  intFile = FreeFile
  Open "pingoutput.txt" For Input As #intFile
  ' ... read and update lblPing here; I'm too lazy
  Close #intFile
End Sub


It would be nicer to use a FileSystemObject rather than old-school BASIC file I/O.

Of course using a hardcoded filename like that would be appalling! Also bear in mind ping will give you more than one line of output, so make your Label tall enough.

There are nicer ways to do networking from VB using WinSock and other add-on controls. If I remember correctly WinSock doesn't ping (some of the systems I work on use a third party control, whose name I can't remember, to handle this) but you could try to connect to port 80, which is a good test of a webserver anyway. You could even send an HTTP request and check that the webserver responded as expected.

PaCkEtPiRaTe Sep 6th, 2007 6:20 PM

To complete your code, where you were "too lazy", would I simply have to put the data from the text file into the label?


All times are GMT -5. The time now is 3:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC