Greg was telling us:
Greg nous racontait que :
Try something like:
Sub Test()
Dim myDate
Dim myDayOfWeek
Dim myYear As String
Retry:
myYear = InputBox("Enter the four digit year: ")
If Len(myYear) <> 4 Or Not IsNumeric(myYear) Then GoTo Retry
myDate = "1/1/" & myYear
myDayOfWeek = Weekday(myDate)
Select Case myDayOfWeek
Case Is = 1
MsgBox "Sunday"
Case Is = 2
MsgBox "Monday"
Case Is = 3
MsgBox "Tuesday"
Case Is = 4
MsgBox "Wednesday"
Case Is = 5
MsgBox "Thursday"
Case Is = 6
MsgBox "Friday"
Case Is = 7
MsgBox "Saturday"
Case Else
'Do Nothing
End Select
End Sub
Just in case you had not seen this alternative way of checking user input
for errors...
If you have a long piece of code, the GoTo statements may cause you to pull
out your hair when debugging... Of course, in this case, since the code is
so simple, it is not a problem, but as a matter of habit, I never use GoTo
in such cases. I use this instead:
Do
myYear = InputBox("Enter the four digit year: ")
Loop While Len(myYear) <> 4 Or Not IsNumeric(myYear)
Or, if you want to allow the user a chance to cancel out of the loop:
Do
myYear = InputBox("Enter the four digit year: ")
If myYear = "" Then Exit Sub
Loop While Len(myYear) <> 4 Or Not IsNumeric(myYear)
So, using Helmut's code, the code would be:
'_______________________________________
Dim myDate As String
Dim myYear As String
Do
myYear = InputBox("Enter the four digit year: ")
If myYear = "" Then Exit Sub
Loop While Len(myYear) <> 4 Or Not IsNumeric(myYear)
myDate = "1/1/" & myYear
MsgBox Format(Weekday(myDate), "dddd")
'_______________________________________
As the saying goes, there are many ways to skin a cat!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org