how to creat code with VB to calculate dat ot Year(2012)
I would like to know how to write vb code about this:
My question is
1. a combobox to selct month
2. a textbox to input Day
3. a label to display Day of Year(2012)
4. and click add the button to calculate and show the result
For example:
Feb. 14 is : the 45th day of this year.
I'm new and still learning.
Thank you so much for your help.
Re: how to creat code with VB to calculate dat ot Year(2012)
Look up the DateDiff-Function in your Help-File
Re: how to creat code with VB to calculate dat ot Year(2012)
There's no need to do any calculation. The DateTime data type has a DayOfYear property. You can construct a DateTime by invoking a constructor and passing the year, month and day and then just get that property value. If you want the current year then that would be DateTime.Now.Year.
Re: how to creat code with VB to calculate dat ot Year(2012)
Quote:
Originally Posted by
jmcilhinney
There's no need to do any calculation. The DateTime data type has a DayOfYear property. You can construct a DateTime by invoking a constructor and passing the year, month and day and then just get that property value. If you want the current year then that would be DateTime.Now.Year.
And you're sure you're talking about VB6?
Sounds like .NET to me
Re: how to creat code with VB to calculate dat ot Year(2012)
Quote:
Originally Posted by
Zvoni
And you're sure you're talking about VB6?
Sounds like .NET to me
Ah bummer! I found this thread in the New Posts section and when I looked across to the right to see what forum it was in I must have gone a bit wonky. Not the first time I've done that and I suspect that it won't be the last. Sorry about that.
That said, I have to wonder why anyone who is just starting out with programming, as it would appear that the OP is, would start with VB6 when VB.NET has been around for over 10 years now.
Re: how to creat code with VB to calculate dat ot Year(2012)
Re: how to creat code with VB to calculate dat ot Year(2012)
Quote:
Originally Posted by
jmcilhinney
That said, I have to wonder why anyone who is just starting out with programming, as it would appear that the OP is, would start with VB6 when VB.NET has been around for over 10 years now.
At a guess, because he's probably using Excel/VBA instead of the original VB-IDE
Re: how to creat code with VB to calculate dat ot Year(2012)
Welcome to the forums :wave:
Here is another way using DatePart
Code:
Option Explicit
Private Sub Form_Load()
Dim i As Long
For i = 1 To 12
Combo1.AddItem MonthName(i)
Combo1.ItemData(Combo1.NewIndex) = i
Next
End Sub
Private Sub Command1_Click()
Dim intDayOfYear As Integer
intDayOfYear = DatePart("y", Combo1.ItemData(Combo1.ListIndex) & "/" & CInt(Text1.Text) & "/" & Year(Now))
Text2.Text = intDayOfYear
End Sub