Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 19th, 2006, 10:17 AM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simple Program Help

So i'm a newbie to VB and i need some help doing something that is so simple i cant work it out.

I have a form that has a button, on clicking the button it pings a computer.

Code:
Private Sub btnPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPing.Click

        Dim Count As Integer


        If My.Computer.Network.Ping("10.50.50.217") Then
            lblDisplay.Text = "Server pinged successfully."
            Count = 0
            lblcount.Text = Count

        Else
            lblDisplay.Text = "Ping request timed out."
            Count = Count + 1
            lblcount.Text = Count
        End If

    End Sub


So i'm thinking people are already calling me stupid :). What i want to happen is when the button is clicked and the ping is ok it sets the counter (lblcount) to 0. Which works.

But if the ping fails i want the counter to count how many in a row. So if i click the button 4 times and ping fails 4 times the lblcount should display 4. Then if i click it and ping is ok the lblcount goes back to 0.

I've got it displaying 1 after the first fail but then stays. Should i have made this a global variable or a class??

Please Help
I do learn from my mistakes.

Thanks

Reply With Quote
  #2 (permalink)  
Old December 19th, 2006, 10:34 AM
Authorized User
 
Join Date: Nov 2006
Location: , , USA.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

Each time you click your button you are resetting the value of COUNT to zero.
Move your variable declaration for COUNT to the form level and your code will work.

Public Class Form1

    Dim Count As Integer

    Private Sub btnPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPing.Click

        If My.Computer.Network.Ping("10.50.50.217") Then
            lblDisplay.Text = "Server pinged successfully."
            Count = 0
            lblcount.Text = Count

        Else
            lblDisplay.Text = "Ping request timed out."
            Count = Count + 1
            lblcount.Text = Count
        End If

    End Sub

End Class



Best Regards,
Earl Francis
Reply With Quote
  #3 (permalink)  
Old December 19th, 2006, 10:51 AM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much that works a treat.

Now to add a clock, telnet and more code :)

Reply With Quote
Reply


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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple assembly program runtime error vraifreud Visual C++ 2005 0 September 21st, 2007 01:20 AM
Simple Q Apocolypse2005 Beginning VB 6 5 August 8th, 2007 08:04 AM
Simple Java Program WargeMaster Java GUI 1 September 9th, 2005 12:25 PM
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 05:40 AM
Start a program inside another program Silje Classic ASP Professional 1 November 16th, 2004 01:08 AM



All times are GMT -4. The time now is 03:39 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.