Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Analog Clock


Reply
 
Thread Tools Display Modes
  #1  
Old 08-14-2002, 04:21 AM
ali
Guest
 
Posts: n/a
Lightbulb Analog Clock


Hi,
i have some limited experience in VB, i am interested in making an analog clock for my desktop.
i havent got a clue how?
i'll real appreciate, if any one could give some suggestions.
thanks in advance.
Ali
Reply With Quote
  #2  
Old 08-14-2002, 05:34 AM
Pookie's Avatar
Pookie Pookie is offline
Gaming God

Retired Leader
* Expert *
 
Join Date: Feb 2002
Location: Brisbane, Australia
Posts: 2,363
Default

Try www.planetsourcecode.com/vb
and do a search for analog clocks.
I'm sure they will have millions of them.
__________________
. <--- Photo of me viewed from the Hubble telescope
Reply With Quote
  #3  
Old 08-14-2002, 07:52 AM
Merrion's Avatar
Merrion Merrion is offline
Ultimate Contributor

* Guru *
 
Join Date: Sep 2001
Location: Dublin, Ireland
Posts: 1,828
Default

I am strangely drawn to this one
Reply With Quote
  #4  
Old 08-14-2002, 08:30 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

An anologue clock is a good simple application to make. A timer control and a bit of smart math is all it takes. You could create a small form and then use SetWindowPos API to make it float on top of all other windows.

__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #5  
Old 08-14-2002, 09:19 AM
Mill Mill is offline
Just another Excel nerd

Retired Moderator
* Guru *
 
Join Date: Feb 2000
Location: Michigan, USA
Posts: 2,624
Default

Here's an Excel file that does something similar.

Besides just being an interesting file to look at, it might help you with some of the math for drawing the hands and such.

http://www.j-walk.com/ss/excel/files/clockchart.htm
__________________
"The face of a child can say it all, especially the mouth part of the face." - Jack Handey
Reply With Quote
  #6  
Old 08-14-2002, 09:26 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Okay, I just couldn't resist. Here's the code to be put into a form. Add 3 line controls and a timer control to the form.



Code:
Option Explicit Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Const HWND_TOPMOST = -1 Const SWP_NOMOVE = &H2 Const SWP_NOSIZE = &H1 Const MYHOUR As Double = 1 / 24 Const MYMIN As Double = MYHOUR / 60 Const MYSEC As Double = MYMIN / 60 Const PI As Double = 3.14159276 Const RAD As Double = PI / 180 Dim CentreX As Single, CentreY As Single Dim Radius As Single Private Sub Form_Load() Timer1_Timer Me.Show Me.DrawWidth = 1 SetWindowPos Me.hwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, SWP_NOMOVE Or SWP_NOSIZE End Sub Private Sub Form_Paint() If Me.WindowState = vbMinimized Then Exit Sub CentreX = Me.ScaleWidth / 2 CentreY = Me.ScaleHeight / 2 If Me.ScaleWidth < Me.ScaleHeight Then Radius = (Me.ScaleWidth - 30) / 2 Else Radius = (Me.ScaleHeight - 30) / 2 End If Me.Cls Me.Circle (CentreX, CentreY), Radius Dim i As Integer Dim iRad As Integer For i = 0 To 359 Step 6 If i Mod 5 Then iRad = Radius / 80 Else iRad = Radius / 35 Me.Circle (CentreX + Sin(i * RAD) * (Radius / 1.1), CentreY + Cos(i * RAD) * (Radius / 1.1)), iRad Next i End Sub Private Sub Form_Resize() Form_Paint End Sub Private Sub Timer1_Timer() Dim dTime As Double Dim X As Single, Y As Single Dim Angle As Single dTime = Time If dTime > 0.5 Then dTime = dTime - 0.5 Angle = ((dTime / MYHOUR) * (PI / 6)) - PI / 2 X = (Cos(Angle) * (Radius / 1.5)) + CentreX Y = (Sin(Angle) * (Radius / 1.5)) + CentreY Line1.X1 = CentreX Line1.Y1 = CentreY Line1.X2 = X Line1.Y2 = Y dTime = (Minute(Time) * MYMIN) + (Second(Time) * MYSEC) Angle = ((dTime / MYMIN) * (PI / 30)) - PI / 2 X = (Cos(Angle) * (Radius / 1.2)) + CentreX Y = (Sin(Angle) * (Radius / 1.2)) + CentreY Line2.X1 = CentreX Line2.Y1 = CentreY Line2.X2 = X Line2.Y2 = Y dTime = Second(Time) * MYSEC Angle = ((dTime / MYSEC) * (PI / 30)) - PI / 2 X = (Cos(Angle) * Radius) + CentreX Y = (Sin(Angle) * Radius) + CentreY Line3.X1 = CentreX Line3.Y1 = CentreY Line3.X2 = X Line3.Y2 = Y End Sub
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #7  
Old 08-14-2002, 09:28 AM
Mill Mill is offline
Just another Excel nerd

Retired Moderator
* Guru *
 
Join Date: Feb 2000
Location: Michigan, USA
Posts: 2,624
Default

Since when can you define constants with equations?
__________________
"The face of a child can say it all, especially the mouth part of the face." - Jack Handey
Reply With Quote
  #8  
Old 08-14-2002, 09:31 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Since...... forever. As long as the constant doesnt involve a function call, then it's fine.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #9  
Old 08-14-2002, 09:33 AM
Mill Mill is offline
Just another Excel nerd

Retired Moderator
* Guru *
 
Join Date: Feb 2000
Location: Michigan, USA
Posts: 2,624
Default

Hmmmm... I mainly only program with VBA these days, but I didn't think you could do that.
__________________
"The face of a child can say it all, especially the mouth part of the face." - Jack Handey
Reply With Quote
  #10  
Old 08-14-2002, 09:59 AM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

API Windows messages are sometimes defined as "WM_USER + someoffset". There are other examples as well....
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #11  
Old 08-14-2002, 02:05 PM
Robert Neilson's Avatar
Robert Neilson Robert Neilson is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Newcastle
Posts: 289
Default

love that one you posed squirm - i think i might make my own one to put into my A-level coursework - bit classier ofcourse but prib built on same math
__________________
As technology develops, so does our imagination
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->