1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Simple VB code in Excel - not working, seeking advice

Discussion in 'Business Applications' started by iacchus, May 2, 2005.

Thread Status:
Not open for further replies.
Advertisement
  1. iacchus

    iacchus Thread Starter

    Joined:
    May 2, 2005
    Messages:
    5
    I've created an excel worksheet and added some vb code behind it, but I'm having a problem getting the two functions to work at the same time - if someone would be willing to take a look at it I'd greatly appreciate it (about 50 - 60 lines of code). In the layout I have, it may be easier to see the worksheet rather than try to explain what I'm trying to accomplish.

    Thank you,
    Dave
     

    Attached Files:

  2. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    Before I look can you tell me briefly what the code is supposed to do please?
     
  3. iacchus

    iacchus Thread Starter

    Joined:
    May 2, 2005
    Messages:
    5
    OBP,

    In the [email protected] worksheet there are two timers: one a user set countdown timer (set in the data worksheet; data1 isnt being used at this time), the other a simple stopwatch - independently each work perfectly. However, if I start one, the other stops, if I stop one, the other stops. I am trying to make both work at the same time.

    Columns A B C, Row 8 should be identical. You will notice that Row 10 has the same format as the time remaining, it was a test to see if it would work; it didnt. In addition, if I could figure out how to make each row work independantly from one another as well, the worksheet would be finished and I'd be able to distribute it out to the 22 users. I'm just being held up by what looks like simple VB code though.

    Thank you in advance,
    Dave
     
  4. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    Dave, you should notice that the main stop watch does not stop when the individual's stop watch is started. It is the displayed time that is not working. When you stop the individual stopwatch the Main stop watch then displays the correct time.
     
  5. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    I think you might need a sub that you can call from both the StartGameClock routine and
    the StartClock which will update the display cells of both at the same time if either of them is runing.
     
  6. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    I think you might need a sub that you can call from both the StartGameClock routine and
    the StartClock which will update the display cells of both at the same time if either of them is running.

    p.s. I like the style of the sheet. If you don't want people to "play" with True/False/difference cells why not protect them?
     
  7. iacchus

    iacchus Thread Starter

    Joined:
    May 2, 2005
    Messages:
    5
    OBP,

    Yes you are correct, I apologize for leaving out that the clock pauses visually but keeps running in the background.


    I am going to protect the entire workbook once its complete.
     
  8. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    Have you tried adding a sub to update both clocks at the same time?
     
  9. iacchus

    iacchus Thread Starter

    Joined:
    May 2, 2005
    Messages:
    5
    OBP,

    I would if I knew how, but I found that code in a book I'm using. I also noticed that while the clock is working, my pc (4.0Ghz 512RAM) slows down considerably and when the screen saver kicks in (starfield) it wont work.

    I do appreciate your looking at this, and if you can help me, or guide me in the right direction I'd greatly appreciate it.

    Thank you,
    Dave
     
  10. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    Screensavers are a pain when you use VBA, it is best to either switch them off or make the duration before they come on greater than the length of time it takes fro your code to run. I will have a look at a subprocedure and post it back on here, do I take it by the time you posted that you are in the USA?
     
  11. iacchus

    iacchus Thread Starter

    Joined:
    May 2, 2005
    Messages:
    5
    Yes, I'm in Kansas City, MO - but due to a disability I rarely sleep.
     
  12. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    So I see, I am in the UK. Talk to you later.
     
  13. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    iacchus, this code works the way I think you want. You have to click the Game Clock first.
    If you want each player to have a set of clock buttons then you will have to declare and use a Start and stopped for each one and have an if/then in the subroutine for each one as well.

    ************************************************************
    ' [email protected] Hold'em Tournement Score Sheet
    '
    ' Purpose: To allow HTD/TD's and Admin, to better keep track
    ' of players scores, game time, and player timer when
    ' a player is lagging, times out or is disconnected due
    ' to a bad Internet connection.
    '
    '
    '
    '
    '
    '
    'Written by: Dave Smith
    'For: Yahoo Games / Poker Heaven league
    'Date: 4/12/2005
    '*************************************************************



    'Game Clock Variables
    Public timelimit
    Public start
    Public start1
    Public remaining
    Public stopped
    Public stopped1
    Public StartTimer

    'Dim Countdown As timelimit


    'Player Counter Variables
    'Dim StopTimer
    'Dim PlayerTimer
    'Dim start

    '*************************************************************
    ' Initiate the game clock
    ' Written by: Dave Smith
    ' Modified: 4/29/2005
    '*************************************************************
    Public Sub StartGameClock()
    stopped = False
    stopped1 = False
    timelimit = Worksheets("data").Range("C3").Value * 60
    start = Timer ' Set start time.
    start1 = 0

    Call updatebothclocks


    End Sub

    Private Sub CmdStartTimer_Click()

    StartGameClock

    End Sub

    Private Sub CmdTimerStop_Click()

    stopped = True

    End Sub

    Private Sub CmdTimerReset_Click()

    stopped = False
    Worksheets("[email protected]").Range("L2").Value = Int((Worksheets("data").Range("C3").Value * 60) / 60)
    Worksheets("[email protected]").Range("N2").Value = (Worksheets("data").Range("C3").Value * 60) Mod 60

    End Sub

    '*************************** Player Stopwatch ************************

    Public Sub startClock()

    start1 = Timer ' Set start time.

    Call updatebothclocks


    End Sub

    Private Sub cmdStart1_Click()
    startClock
    End Sub

    Private Sub cmdStop1_Click()

    stopped1 = True

    End Sub

    Private Sub cmdReset1_Click()

    stopped = False
    Worksheets("[email protected]").Range("F8").Value = 0
    Worksheets("[email protected]").Range("H8").Value = 0
    Worksheets("[email protected]").Range("I8").Value = 0

    End Sub
    Private Sub updatebothclocks()
    Do While stopped1 = False Or stopped = False
    DoEvents

    If stopped = False And start > 0 Then
    Worksheets("[email protected]").Range("L2").Value = Int((timelimit - (Timer - start)) / 60)
    Worksheets("[email protected]").Range("N2").Value = (timelimit - (Timer - start)) Mod 60
    End If
    If stopped1 = False And start1 > 0 Then
    Worksheets("[email protected]").Range("F8").Value = Int((Timer - start1 + 0.5) / 60)
    Worksheets("[email protected]").Range("H8").Value = (Timer - start1) Mod 60
    Worksheets("[email protected]").Range("I8").Value = (Timer - start1 + 0.5) - (Int(Timer - start1 + 0.5))
    End If
    Loop

    End Sub
     
  14. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/358429

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice