EirikDaude
12-10-2013, 11:27 AM
I have the following code for checking if the data put into an inputbox is a valid year (between 1990 and 2100):
Sub klikk()
Dim år As Long: år = 0
Dim inndata As String
Do While år > 2100 Or år < 1990
inndata = InputBox("Skriv inn året du vil lage skiftplan for.", "År", Year(Date) + 1)
If IsNull(inndata) Then
Exit Sub
ElseIf Len(inndata) < 1 Then
år = 0
ElseIf Not IsNumeric(inndata) Then
år = 0
Else
år = CLng(inndata)
End If
Loop
End Sub
While I think it works well enough, I was wondering if any of you guys could think of a way to shorten the code (e.g. some way to combine the two else-if statements to one), or if there are any possibilities for invalid input which I have forgotten about?
Sub klikk()
Dim år As Long: år = 0
Dim inndata As String
Do While år > 2100 Or år < 1990
inndata = InputBox("Skriv inn året du vil lage skiftplan for.", "År", Year(Date) + 1)
If IsNull(inndata) Then
Exit Sub
ElseIf Len(inndata) < 1 Then
år = 0
ElseIf Not IsNumeric(inndata) Then
år = 0
Else
år = CLng(inndata)
End If
Loop
End Sub
While I think it works well enough, I was wondering if any of you guys could think of a way to shorten the code (e.g. some way to combine the two else-if statements to one), or if there are any possibilities for invalid input which I have forgotten about?