Seven Segment Counter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Skisy
    New Member
    • Dec 2007
    • 1

    Seven Segment Counter

    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:

    [CODE=vb]Sub ConvertDigitToL CD(NumberToDisp lay As Integer, DigitToChange As Variant)

    For n = 0 To 6
    DigitToChange(n ).Visible = False
    Next n

    Select Case NumberToDisplay

    Case 0
    DigitToChange(0 ).Visible = True
    DigitToChange(1 ).Visible = True
    DigitToChange(2 ).Visible = True
    DigitToChange(4 ).Visible = True
    DigitToChange(5 ).Visible = True
    DigitToChange(6 ).Visible = True

    Case 1
    DigitToChange(2 ).Visible = True
    DigitToChange(5 ).Visible = True

    Case 2
    DigitToChange(1 ).Visible = True
    DigitToChange(2 ).Visible = True
    DigitToChange(3 ).Visible = True
    DigitToChange(4 ).Visible = True
    DigitToChange(6 ).Visible = True

    Case 3
    DigitToChange(1 ).Visible = True
    DigitToChange(2 ).Visible = True
    DigitToChange(3 ).Visible = True
    DigitToChange(5 ).Visible = True
    DigitToChange(6 ).Visible = True

    Case 4
    DigitToChange(0 ).Visible = True
    DigitToChange(3 ).Visible = True
    DigitToChange(2 ).Visible = True
    DigitToChange(5 ).Visible = True

    Case 5
    DigitToChange(0 ).Visible = True
    DigitToChange(1 ).Visible = True
    DigitToChange(3 ).Visible = True
    DigitToChange(5 ).Visible = True
    DigitToChange(6 ).Visible = True

    Case 6
    DigitToChange(0 ).Visible = True
    DigitToChange(1 ).Visible = True
    DigitToChange(3 ).Visible = True
    DigitToChange(4 ).Visible = True
    DigitToChange(5 ).Visible = True
    DigitToChange(6 ).Visible = True

    Case 7
    DigitToChange(1 ).Visible = True
    DigitToChange(2 ).Visible = True
    DigitToChange(5 ).Visible = True

    Case 8
    DigitToChange(0 ).Visible = True
    DigitToChange(1 ).Visible = True
    DigitToChange(2 ).Visible = True
    DigitToChange(3 ).Visible = True
    DigitToChange(4 ).Visible = True
    DigitToChange(5 ).Visible = True
    DigitToChange(6 ).Visible = True

    Case 9
    DigitToChange(0 ).Visible = True
    DigitToChange(1 ).Visible = True
    DigitToChange(2 ).Visible = True
    DigitToChange(3 ).Visible = True
    DigitToChange(5 ).Visible = True
    DigitToChange(6 ).Visible = True

    End Select

    End Sub[/CODE]

    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:


    [CODE=vb]Private Sub Form_Load()

    Dim txtToDisplay As String

    'txtToDisplay = "000.00"

    'txtToDisplay = Format(HScroll1 .Value / 10, "000.00")
    ConvertDigitToL CD Mid(txtToDispla y, 1, 1), Digit1
    ConvertDigitToL CD Mid(txtToDispla y, 2, 1), Digit2
    ConvertDigitToL CD Mid(txtToDispla y, 3, 1), Digit3
    '(txtToDisplay, 4, 1) is the decimal point
    ConvertDigitToL CD Mid(txtToDispla y, 5, 1), Digit4
    ConvertDigitToL CD Mid(txtToDispla y, 6, 1), Digit5

    End Sub

    [/CODE]
    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.
    Last edited by debasisdas; Dec 22 '07, 12:01 PM. Reason: Formatted using code tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    From your code I am not at all clear what exactly is your requirement. Can you explain it bit more clearly?
    Last edited by Killer42; Dec 29 '07, 01:19 PM.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by Skisy
      ... 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 ConvertDigitToL CD, passing Counter as the NumberToDisplay parameter.

      This should work for a small demo, at least.

      Comment

      Working...