Page 1 of 2 12 LastLast
Results 1 to 40 of 44

Thread: Need Help With Using/(finding) Timer in Excel !

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Need Help With Using/(finding) Timer in Excel !

    okay here's the plan:

    I need to write a macro for excel that will display a number ("B") real-time alongside a movie (it would be preferable for the movie to also play on the form using shockwave or something could someone please instruct me as to how to do that?) Here's a hypothetical first few lines of the data in Excel (A is the time, and B is the number that needs to be displayed):

    VB Code:
    1. A           B    
    2. 1   12.00.01     55    
    3. 2   12.05.01     58
    4. 3   12.07.02     46
    5. 4   12.09.05     23
    6. 5   12.11.04     67
    7. ... (and so on for about umm several thousand lines)

    What I need to do is use the timer to display the value of "B", after the correct interval of time. For example, the first value ("B1") appears immediatley, and then five seconds later I need for the value of "B2" to be displayed.

    The interval between new numbers needs to be something like this (where x equals the row because I'm using a loop):
    VB Code:
    1. interval = (A(x+1))-Ax

    Right now (having never written a macro/program in VBA before) I am having trouble finding the "timer" control. There are hundreds of "Additional Controls" and I don't want to sort through them. I really have no idea what I am doing with VBA so thanks for the help in advance. Keep in mind that I have only taken Programming 1 last year, I am 15, and my VB skills are so incredibly limited, so if possible, please explain everything fully and don't assume that I know anything

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Welcome to the Forums.

    Thats because its not a control in Excel. Its just a function called Timer: Returns a Single representing the number of seconds elapsed since midnight.

    Here is an example from the help file on how to use it.

    VB Code:
    1. Dim PauseTime, Start, Finish, TotalTime
    2. If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
    3.     PauseTime = 5    ' Set duration.
    4.     Start = Timer    ' Set start time.
    5.     Do While Timer < Start + PauseTime
    6.         DoEvents    ' Yield to other processes.
    7.     Loop
    8.     Finish = Timer    ' Set end time.
    9.     TotalTime = Finish - Start    ' Calculate total time.
    10.     MsgBox "Paused for " & TotalTime & " seconds"
    11. Else
    12.     End
    13. End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Need Help With Using/(finding) Timer in Excel !

    And, to add to RD's post, you can't put it in either (like you might do with other VB controls). At least, as far as I am aware. You have to do the "Get start point and check each interval" method as shown above by RD.

    zaza

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    So it should look something like this?
    VB Code:
    1. Sub TEST1()
    2.  
    3. Dim PauseTime, Start, Finish, TotalTime
    4. Dim x As Integer
    5.  
    6. For x = 1 To 10
    7.     Display.Caption = ("Bx") 'Display the number from cell Bx
    8.     PauseTime = ("Ax")  ' Set duration (from cell Ax)
    9.     Start = Timer       ' Set start time.
    10.        
    11.         Do While Timer < Start + PauseTime
    12.             DoEvents 'Pause
    13.         Loop
    14.  
    15. x = x + 1
    16. Next x
    17. End Sub

    I get errors for like every other line and I have no idea how to debug them... thanks for helping btw

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    What are the errors?

    Do you know that your declaring all your variables as a Variant? Thats what your doing on this line when you dont specify the type.

    VB Code:
    1. Dim PauseTime, Start, Finish, TotalTime
    2. 'Should be
    3. Dim PauseTime Long, Start As Long '(, Finish, TotalTime) Not used
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    VB Code:
    1. Sub TEST1()
    2.  
    3. Dim PauseTime As Long, Start As Long
    4.  
    5. Dim x As Integer
    6.  
    7. For x = 1 To 10
    8.     Display.Caption = ("Bx") 'Display the number [U][B]<-- run time error '424': object required[/B][/U]
    9.     PauseTime = ("Ax")  'Set duration [U][B]<-- run time error '13': type mismatch[/B][/U]
    10.     Start = Timer       ' Set start time.
    11.        
    12.         Do While Timer < Start + PauseTime
    13.             DoEvents
    14.         Loop
    15.  
    16. x = x + 1
    17. Next x
    18. End Sub

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Ok, where is your "Display" object? What is the Ax supossed to mean? Usually a time value is a long or single value type.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    The "Display" label is on a user form, and the "Ax" is supposed to represent a cell ie A1, A2 etc and the same for "Bx". I know that it's wrong... I just don't know quite how to get the program to recognize the value of a cell

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Ok, where is "Sub TEST1()"? Is it behind the userform code or in a module or ThisWorkbook?

    You can access a sheets cell by referenceing the workbook/sheet depending on where your trying to reference it from.

    VB Code:
    1. PauseTime = Workbooks("Book1").Sheets("Sheet1").Cells(1, 1) 'A1
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    the sub is in a module, so should it look like this?

    VB Code:
    1. Sub TEST1()
    2.  
    3. Dim PauseTime As Long, Start As Long
    4.  
    5. Dim x As Integer
    6.  
    7. For x = 1 To 10
    8.     PauseTime = Workbooks("Book1").Sheets("Sheet1").Cells(1, "x + 1") - Workbooks("Book1").Sheets("Sheet1").Cells(1, "x")
    9.     Display.Caption =  Workbooks("Book1").Sheets("Sheet1").Cells(2, "x")
    10.     Start = Timer       ' Set start time.
    11.         Do While Timer < Start + PauseTime
    12.             DoEvents
    13.         Loop
    14. x = x + 1
    15. Next x
    16. End Sub

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Almost, "x + 1" and "x" should not have double quotes around them as we want the variable value to add to 1 and not be a complete string representation.

    If your workbook is called "Book1" and your sheet is named "Sheet1" then yes.

    To reference your Display label from a module - UserForm1.Display.Caption = "Something.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    Ok so I did everything that you said... (& my wrkbk is "Book1" and sheet is "Sheet1" and form is "UserForm1") and here is the current code:

    VB Code:
    1. Sub TEST1()
    2. Dim PauseTime As Long, Start As Long
    3. Dim x As Integer
    4.  
    5. For x = 1 To 10
    6.     PauseTime = Workbooks("Book1").Sheets("Sheet1").Cells(1, x + 1) - Workbooks("Book1").Sheets("Sheet1").Cells(1, x)
    7.     UserForm1.Display.Caption = Workbooks("Book1").Sheets("Sheet1").Cells(2, x)
    8.     Start = Timer       ' Set start time.
    9.         Do While Timer < Start + PauseTime
    10.             DoEvents
    11.         Loop
    12. x = x + 1
    13. Next x
    14. End Sub

    Now I can run it without error messages, but the for just sits there and the number stays as "0", which is the default number on "Display"... pretty much nothing happens.

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Place a breakpoint on "TEST()", run your code and in your immediate window type these and post what value you get.
    "?Workbooks("Book1").Sheets("Sheet1").Cells(1, x + 1)"

    "?Workbooks("Book1").Sheets("Sheet1").Cells(2, x)"

    "?PauseTime?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    oh noes I'm so confused... a breakpoint is that thing that happens when you click in the left margin next to a line and a circle appears and the line of code turns burgundy correct? I did that to the line Sub TEST1(), and ran it, but the line just turned yellow with a line pointing to it. Now what might this immediate window be?

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Breakpoint is correct and the yellow highlighted line is the current line of execution that the program is going to execute. You can step through your code line by line by pressing F8.

    The immediate window can be viewed by pressing Ctl+G.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    uuhhhmmm ok so I just did what I first did [make a breakpoint on sub TEST1() ] and then I went to the immediate window and typed in"?Workbooks("Book1").Sheets("Sheet1").Cells(1, x + 1)"
    and pressed enter and a window popped up that said "Compile Error: Expected: Line number or label or statement of end of statement" Should the yellow line be on the line of code that I am refering to? Thanks for helping me through this

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Dont use the double quotes as I used them just to show what to type.
    Press F8 once to advance the yellow line into the procedure to initialize the variables.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    ?Workbooks("Book1").Sheets("Sheet1").Cells(1, x + 1)
    0.1 (<-- that is correct at least)

    ?Workbooks("Book1").Sheets("Sheet1").Cells(2, x)
    application defined or object defined error

    ?PauseTime?
    expected: expression

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    So row 1, column 2 has 0.1 in it and row 2 column 1 has what in it?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    row 2, clm 1 has "0.51" in it, but heh I just figured out that the number I want displayed is in row 1 clm 2 and not row2 clm1 whoopsies so I guess that I got my clms and rows mixed up sorry

  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    At least its straightened out now. So PauseTime should have a correct value in it now?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    Actually no I don't know why... here is the revised code with parts I just changed in bold (I don't think there are any glaring errors?):

    VB Code:
    1. Sub TEST1()
    2. Dim PauseTime As Long, Start As Long
    3. Dim x As Integer
    4.  
    5. For x = 1 To 10
    6.     PauseTime = Workbooks("Book1").Sheets("Sheet1").Cells[B](x + 1, 1)[/B] - Workbooks("Book1").Sheets("Sheet1").Cells[B](x, 1)[/B]
    7.     UserForm1.Display.Caption = Workbooks("Book1").Sheets("Sheet1").Cells[B](x, 2)[/B]
    8.     Start = Timer       ' Set start time.
    9.         Do While Timer < Start + PauseTime
    10.             DoEvents
    11.         Loop
    12. x = x + 1
    13. Next x
    14. End Sub

    ?Workbooks("Book1").Sheets("Sheet1").Cells(x + 1, 1)
    returns "0.1" ,however I just realized that it should be "0.51", because (x + 1 , 1) = A2 the first time through the loop, right? I guess that it isn't correct then :\

    ?Workbooks("Book1").Sheets("Sheet1").Cells(x , 2)
    application-defined or object-defined error :S

    ?Workbooks("Book1").Sheets("Sheet1").Cells(x, 1)
    application-defined or object-defined error

    ?PauseTime
    returns "0"

    no esta bien

  23. #23
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Place a breakpoint on the PauseTime line of code. Then do the "?" printing of your cell values.

    A2 for your first value, (2, 1) = row 2 column 1 or A2.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  24. #24

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    Place a breakpoint on the PauseTime line of code. Then do the "?" printing of your cell values.
    ?Workbooks("Book1").Sheets("Sheet1").Cells(x, 1)
    0.1 (correct)
    ?Workbooks("Book1").Sheets("Sheet1").Cells(x + 1 , 1)
    0.51 (correct)
    ?Workbooks("Book1").Sheets("Sheet1").Cells(x, 2)
    1 (correct)
    ?PauseTime
    0 (I dont think thats correct)

  25. #25
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Ok, since your working with decimal values you need to change your variable from a long to a single.
    VB Code:
    1. Dim PauseTime As Long
    2. 'Should be
    3. Dim PauseTime As Single
    0.51 - 0.1 = 0.41
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  26. #26

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    I just changed PauseTime to single and tried to run the program and nothing happened besides the form showing up, but I placed a breakpoint on Pause Time etc and now I get

    ?PauseTime
    0.41 (correct)

    I can't find anything else that might be the problem... btw this code should be under "Module1" right? Or should it be under "UserForm1"?
    Last edited by washcloth; Nov 20th, 2005 at 10:24 PM.

  27. #27
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Step through your code checking the values from this line of code.
    VB Code:
    1. Do While Timer < Start + PauseTime
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  28. #28

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    They are all correct

  29. #29
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    But as you step through the loop does the values ever change or evaluate to let it go inside the loop? or does it just bypass the loop altogether?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  30. #30

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    yea I have to press f8 reall fast before that 0.41 of a second is up, but all the values are right on all the lines:

    Do While Timer < Start + PauseTime
    DoEvents
    Loop

  31. #31
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Well according to your code its only a pause loop so nothing is going to happen unless you increase the pause to some values that wil be noticeable.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  32. #32

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    but wont it pause for the right interval? ie 0.41 secs? am I wrong?

  33. #33
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    Its probably too fast since its less then 1/2 a second.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  34. #34
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Need Help With Using/(finding) Timer in Excel !

    Isn't the timer in milliseconds?

  35. #35

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    Its probably too fast since its less then 1/2 a second.
    I just tried changed the first ten increments to:
    1 sec , 3, 5, 7, 9, 11, 13, 15, 17, and 19secs after beginning
    and it still didn't work so I know that is probably not the problem
    is that what you meant?

  36. #36

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    Quote Originally Posted by dglienna
    Isn't the timer in milliseconds?
    what do I do then??

  37. #37
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    I'm not sure about that as "Timer: Returns a Single representing the number of seconds elapsed since midnight."

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  38. #38

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    22

    Re: Need Help With Using/(finding) Timer in Excel !

    oh.... so does that mean that I can't work with fractions of a second?? because if so then that's not good at all

  39. #39
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need Help With Using/(finding) Timer in Excel !

    This is part of why I asked if your loop was working and what the values were.
    VB Code:
    1. Do While Timer < Start + PauseTime
    If your pause time is fractional then it will always exit the loop and never go into it.

    Why do you need such short durations?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  40. #40
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Need Help With Using/(finding) Timer in Excel !

    86,400 seconds in a day. It returns 2 decimal places, though. Prolly wouldn't help to try to gauge .41 seconds. I doubt it would register accurately. You could see how many times it was looping, though.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width