Quantcast

Maximum PC

It is currently Sat Aug 30, 2014 8:24 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Some VB6 or VB.NET Help Counting
PostPosted: Tue Apr 15, 2008 3:16 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8722
Location: Cleveland, Ohio
First, I am not a programmer. Most of what I have written has been very simple little routines to aquire data (Test Results) and dump them into a spread sheet.

What I am looking to do is use a simple counter much like the following:

Code:
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()

If Text1.Text < 2047 Then
    Text1.Text = Text1.Text + 1
Else
   Text1.Text = 0
                 
End If



If Text2.Text < 2047 Then
    Text2.Text = Text2.Text + 1
Else
    Text2.Text = 0
   
End If


End Sub


Two command buttons and two text boxes. Once timer 1 is enabled they count up to 2047 and recycle starting with 0. However, what I am looking to do is count up to 2047 then begin counting down from 2047. Meaning count from 0 to 2047 then down to 0 from 2047 and repeat over and over again till timer 1 enable is false.

There is a method to all this and it is part of a larger scheme but for now I am just wondering how to set up the timer?

Why VB? Because I have it and use it for my simple task. Any suggestions would be greatly appreciated.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Tue Apr 15, 2008 3:13 pm 
Million Club - 5 Plus*
Million Club - 5 Plus*
User avatar

Joined: Sun Sep 12, 2004 6:37 pm
Posts: 4745
Location: In the monkey's litterbox
I'd just add a variable that indicates the direction that you're heading.

Then it's just a nested if statement.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 1:27 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8722
Location: Cleveland, Ohio
Thanks smartcat, I'll give that a try this evening after work. Much appreciate the pointer.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 7:42 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
smartcat99s wrote:
I'd just add a variable that indicates the direction that you're heading.

Then it's just a nested if statement.


Note: I'm not familiar with VB. The code provided below is generic and will almost certainly need to be corrected to produce proper VB code. I'll keep it as simple as possible so you can plug it in as quickly as possible.

Smarcat: Great idea.

If you make the variable + or -1, then the variable holds the 'direction' that you are counting (-1, obviously, means you are 'counting' down). You could just add the 'direction' variable to your count and it will either increment or decrement depending on whether the value is positive or negative.

So, rather than having a series of if .. then conditionals, your counter would be simply:

Code:
Counter = Counter + Direction



Somewhere, you'll need to check to see whether the direction needs to change (ie., whether Text1.Text is < 0 or > 2047). This code will set the Direction variable accordingly:

Code:
If Counter = 0 Then Direction = 1
Else if Counter = 2047 Then Direction = -1
End if


This would best be implemented as a function whose parameters are the integer (Counter) being tested and the Direction that may change.

I hope that that helps, Ron.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 8:42 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8722
Location: Cleveland, Ohio
Thanks Jip, I will mess with it when I get home from work today. I really appreciate your samples.

Eventually this will figure into a larger scheme for a project. Nothing great just something I am looking for a better way to get done.

Again, the help is much appreciated.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 9:09 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
Glad to help, my friend ... any time. :)


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group