![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2007
Posts: 24
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4
![]() |
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 SubIt 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?" |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Aug 2007
Posts: 24
Rep Power: 0
![]() |
To complete your code, where you were "too lazy", would I simply have to put the data from the text file into the label?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |