I am currently working on an assignment and it's asking me to use a function with the header Function DayofWeek(dt As Date) As String
. This program would be finding the day of the week for a specific date, if someone could explain to me how to implement this function it would be greatly appreciated.
As far as using the function, you'd probably end up doing something like this. I agree with plutonix that you should ideally not really have much in the way of code inside an event handler like code to handle a button click. Rather you should write code in a separate Sub and then invoke the sub from the button click handler - a bit like this maybe
Public Class Form1
Function DayofWeek(dt As Date) As String
'your code here ofc :)
End Function
Private Sub showWhatDayItIs()
Dim todaysDay As String
todaysDay = DayofWeek(Date.Now)
MessageBox.Show("It's " + todaysDay + " today!")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
showWhatDayItIs()
End Sub
End Class
I'm not trying to be condescending, but this article on the Code Project is a pretty good starter for Object Oriented Programming :-
http://www.codeproject.com/Articles/8825/Object-Oriented-Programming-In-VB-NET
You could do this:
Public Function DayofWeek(dt As Date) As String
Return dt.DayOfWeek.ToString()
End Function
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.