Page 1 of 1

VB6 Month Timer Help

Posted: Sun Aug 09, 2009 5:14 am
by john bunsenburner
Well, this is pretty much as far from spud guns as can get, but still there are a few members on here that are very familiar with visual basic, and so, before I go out and search for a whole new forum, i assumed asking you guys for help would be a good idea, so here I go:

I have been designing a program, just for fun, part of it involves counting months, simply adding 1 to a label's caption every time a month passes. The problem is the fact months tend to vary in length, and because this should be fairly accurate(and no, leap years are no problem, I will deal with those my self) at any given time i have tried to code the program in a manner in which each month is treated separately, now without further ado, I'll just give you guys the code.

Code: Select all

Private Sub Form_Load()
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Label1.Caption = (Label1.Caption + 1)
Lbl1.Caption = (Lbl1.Caption + 1)
If Label1.Caption = 60 Then
Label2.Caption = (Label2.Caption + 1)
Label1.Caption = 0
End If
If Label2.Caption = 60 Then
Label3.Caption = (Label3.Caption + 1)
Label2.Caption = 0
End If
If Label3.Caption = 24 Then
Label4.Caption = (Label4.Caption + 1)
Label3.Caption = 0
End If
If Lbl1.Caption = 604800 Then
Label5.Caption = (Label5.Caption + 1)
Lbl1.Caption = 0
End If
If Label4.Caption = 31 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 59 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 90 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 120 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 151 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 181 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 212 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 243 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 273 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 304 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 334 Then
Label6.Caption = (Label6.Caption + 1)
End If
If Label4.Caption = 365 Then
Label6.Caption = 0
Label4.Caption = 0
End If
End Sub
Label4 displays days
Label6 months

Thanks in advance for all your help! Happy spudding, and enjoy your summer, or winter!

Posted: Sun Aug 09, 2009 7:14 am
by jrrdw
Post this at Theopia in the computer section, "Turbosuper" is one of the most knowlagable members that I know of, he probly can help you with this.

Posted: Sun Aug 09, 2009 11:39 am
by jimmy101
You reset Label4.Caption = 0 twice in the program. Once at the end of Febuary and again at the end of the year. Is that what you intend? (Day and month counting like this is often done relative to the first of March instead of Jan 1, since that allows leap years to be treated by adding one day after the last day of the year; Feb. 28.)

"Label6.Caption ++" is much more readable than is "Label6.Caption = (Label6.Caption + 1) ". (Or "++Label6.Caption" or whatever VB's increment by one command is.)

Posted: Sun Aug 09, 2009 3:32 pm
by john bunsenburner
Ok ill post on theopia, i also forgot to mention the problem i get:

When the label4.caption=31 then the label6.caption starts goin up in seconds...

Posted: Sun Aug 09, 2009 8:25 pm
by TurboSuper
Yay, I'm knowledgeable :D

To be fair Zarno and Los Frijoles probably know more about this stuff than I do, I just get to the threads quicker.