|
-
Sep 13th, 2012, 10:15 PM
#1
Thread Starter
New Member
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.
-
Sep 14th, 2012, 01:15 AM
#2
Re: how to creat code with VB to calculate dat ot Year(2012)
Look up the DateDiff-Function in your Help-File
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Sep 14th, 2012, 01:19 AM
#3
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.
-
Sep 14th, 2012, 01:23 AM
#4
Re: how to creat code with VB to calculate dat ot Year(2012)
 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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Sep 14th, 2012, 01:35 AM
#5
Re: how to creat code with VB to calculate dat ot Year(2012)
 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.
-
Sep 14th, 2012, 02:18 AM
#6
Addicted Member
Re: how to creat code with VB to calculate dat ot Year(2012)
-
Sep 14th, 2012, 04:20 AM
#7
Re: how to creat code with VB to calculate dat ot Year(2012)
 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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Sep 14th, 2012, 08:13 AM
#8
Re: how to creat code with VB to calculate dat ot Year(2012)
Welcome to the forums 
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|