Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 5th, 2007, 6:43 PM   #1
PaCkEtPiRaTe
Newbie
 
Join Date: Aug 2007
Posts: 24
Rep Power: 0 PaCkEtPiRaTe is on a distinguished road
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?
PaCkEtPiRaTe is offline   Reply With Quote
Old Sep 6th, 2007, 5:09 PM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
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.
__________________
"I'm not a genius. Why do I have to suffer?"
mackenga is offline   Reply With Quote
Old Sep 6th, 2007, 5:20 PM   #3
PaCkEtPiRaTe
Newbie
 
Join Date: Aug 2007
Posts: 24
Rep Power: 0 PaCkEtPiRaTe is on a distinguished road
To complete your code, where you were "too lazy", would I simply have to put the data from the text file into the label?
PaCkEtPiRaTe is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do you put a caption into a label when clicked? 13EN Visual Basic 2 Jun 8th, 2006 3:26 PM
Problem Associated with Vector Source code buggytoast Java 3 Apr 2nd, 2006 5:41 AM
outputting to a file to create a image funkymp C 0 Jan 16th, 2006 2:00 PM
Problem moving Label value to TextBox Bman C# 3 Nov 29th, 2005 6:28 PM
OOT Program Examples Sane Other Scripting Languages 4 Nov 25th, 2005 12:06 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:00 AM.

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