By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,058 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,058 IT Pros & Developers. It's quick & easy.

Seven Segment Counter

P: 1
Using VB6:

Hi I'm having a bit of trouble with this, I know what I've got to do (or rather one way of doing it) but I'm struggling with the actual implementation of my thoughts into code.

I've got a seven segment display, and the actual display is sorted more or less (i.e. If I were to create a text box and code, type in a number then it would appear correctly in a seven segment format.) But now I want to make this display act like a timer, where it just counts up on a button click event and stops on a button click event? How would I make it do this?

This is my select case code (in a module) for the display of the seven segment numbers:

Expand|Select|Wrap|Line Numbers
  1. Sub ConvertDigitToLCD(NumberToDisplay As Integer, DigitToChange As Variant)
  2.  
  3. For n = 0 To 6
  4.     DigitToChange(n).Visible = False
  5. Next n
  6.  
  7. Select Case NumberToDisplay
  8.  
  9.       Case 0
  10.         DigitToChange(0).Visible = True
  11.         DigitToChange(1).Visible = True
  12.         DigitToChange(2).Visible = True
  13.         DigitToChange(4).Visible = True
  14.         DigitToChange(5).Visible = True
  15.         DigitToChange(6).Visible = True
  16.  
  17.     Case 1
  18.         DigitToChange(2).Visible = True
  19.         DigitToChange(5).Visible = True
  20.  
  21.     Case 2
  22.         DigitToChange(1).Visible = True
  23.         DigitToChange(2).Visible = True
  24.         DigitToChange(3).Visible = True
  25.         DigitToChange(4).Visible = True
  26.         DigitToChange(6).Visible = True
  27.  
  28.     Case 3
  29.         DigitToChange(1).Visible = True
  30.         DigitToChange(2).Visible = True
  31.         DigitToChange(3).Visible = True
  32.         DigitToChange(5).Visible = True
  33.         DigitToChange(6).Visible = True
  34.  
  35.     Case 4
  36.         DigitToChange(0).Visible = True
  37.         DigitToChange(3).Visible = True
  38.         DigitToChange(2).Visible = True
  39.         DigitToChange(5).Visible = True
  40.  
  41.     Case 5
  42.         DigitToChange(0).Visible = True
  43.         DigitToChange(1).Visible = True
  44.         DigitToChange(3).Visible = True
  45.         DigitToChange(5).Visible = True
  46.         DigitToChange(6).Visible = True
  47.  
  48.     Case 6
  49.         DigitToChange(0).Visible = True
  50.         DigitToChange(1).Visible = True
  51.         DigitToChange(3).Visible = True
  52.         DigitToChange(4).Visible = True
  53.         DigitToChange(5).Visible = True
  54.         DigitToChange(6).Visible = True
  55.  
  56.     Case 7
  57.         DigitToChange(1).Visible = True
  58.         DigitToChange(2).Visible = True
  59.         DigitToChange(5).Visible = True
  60.  
  61.     Case 8
  62.         DigitToChange(0).Visible = True
  63.         DigitToChange(1).Visible = True
  64.         DigitToChange(2).Visible = True
  65.         DigitToChange(3).Visible = True
  66.         DigitToChange(4).Visible = True
  67.         DigitToChange(5).Visible = True
  68.         DigitToChange(6).Visible = True
  69.  
  70.     Case 9
  71.         DigitToChange(0).Visible = True
  72.         DigitToChange(1).Visible = True
  73.         DigitToChange(2).Visible = True
  74.         DigitToChange(3).Visible = True
  75.         DigitToChange(5).Visible = True
  76.         DigitToChange(6).Visible = True
  77.  
  78. End Select
  79.  
  80. End Sub
I've tested the display a number of ways including using a scroll bar, and this is the code (I've commented out the bits only relevant to the scroll bar) which I've used:


Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim txtToDisplay As String
  4.  
  5. 'txtToDisplay = "000.00"
  6.  
  7. 'txtToDisplay = Format(HScroll1.Value / 10, "000.00")
  8. ConvertDigitToLCD Mid(txtToDisplay, 1, 1), Digit1
  9. ConvertDigitToLCD Mid(txtToDisplay, 2, 1), Digit2
  10. ConvertDigitToLCD Mid(txtToDisplay, 3, 1), Digit3
  11. '(txtToDisplay, 4, 1) is the decimal point
  12. ConvertDigitToLCD Mid(txtToDisplay, 5, 1), Digit4
  13. ConvertDigitToLCD Mid(txtToDisplay, 6, 1), Digit5
  14.  
  15. End Sub
  16.  
  17.  
I know it's a bit of a lengthy one, but could anyone help me out, or give me more direction? So I can get the code I need and put it in a button click event...I've been thinking I'll need to use a timer, there may be other ways around it though...

Thanks

Skisy.
Dec 22 '07 #1
Share this Question
Share on Google+
2 Replies


debasisdas
Expert 5K+
P: 8,127
From your code I am not at all clear what exactly is your requirement. Can you explain it bit more clearly?
Dec 22 '07 #2

Expert 5K+
P: 8,434
... now I want to make this display act like a timer, where it just counts up on a button click event and stops on a button click event? How would I make it do this?
It sounds pretty straightforward. Here's how I would handle it. Or at least what initially comes to mind...

I would just create a form-level variable. Let's call it Counter, and assign it the data type of Integer. (I would generally recommend the use of Long anywhere you might consider using Integer - but that's another story).

Create a timer, and set its Interval property to match how quickly you want the numbers to tick over. In the click event for your first button, simply set the timer's Enabled property to True. In the second one, set it to False.

In the timer's Timer event, simply increment the value of Counter. (When it hits ten, reset it to zero). Then invoke your ConvertDigitToLCD, passing Counter as the NumberToDisplay parameter.

This should work for a small demo, at least.
Dec 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.