I'm not a Basic programmer. So forgive me if this is a stupid question.
I have written the following sub routine. I pass a date formatted as a string to the sub. The date string is formatted as mm/dd/yyyy. Inside the sub, I want to split out the mm, dd, yyyy components. I am using the SubString2 function to do this. The local variable sMonth is set correctly. But the next line where I try to set sDay throws the following exception:
An error has occurred in sub: main_validdate(B4A line: 92)
sday = ThisDate.Substring2(3,2)
java.lang.StringIndexOutOfBoundsException.
The sub is shown below. Any help will be appreciated.
Sub ValidDate(ThisDate As String) As Boolean
' Error if empty or length <> 10
If ThisDate.Trim.Length = 0 OR ThisDate.Length <> 10 Then
Return False
End If
' Error if 2nd or 5th char is <> "/"; string array is 0-based
Dim sLength As Int
sLength = ThisDate.Length
For i = 0 To sLength-1
Dim s As String
s = ThisDate.CharAt(i)
If (i <> 2) AND (i <> 5) AND (Not (IsNumber(ThisDate.CharAt(i)))) Then
Return False
End If
If ((i = 2) OR (i = 5)) AND (ThisDate.CharAt(i) <> "/") Then
Return False
End If
Next
Dim smonth As String
Dim sday As String
Dim syear As String
'This line works
smonth = ThisDate.SubString2(0,2)
'Exception is thrown when the next line is executed
sday = ThisDate.SubString2(3,2)
syear = ThisDate.SubString2(6,4)
End Sub
I have written the following sub routine. I pass a date formatted as a string to the sub. The date string is formatted as mm/dd/yyyy. Inside the sub, I want to split out the mm, dd, yyyy components. I am using the SubString2 function to do this. The local variable sMonth is set correctly. But the next line where I try to set sDay throws the following exception:
An error has occurred in sub: main_validdate(B4A line: 92)
sday = ThisDate.Substring2(3,2)
java.lang.StringIndexOutOfBoundsException.
The sub is shown below. Any help will be appreciated.
Sub ValidDate(ThisDate As String) As Boolean
' Error if empty or length <> 10
If ThisDate.Trim.Length = 0 OR ThisDate.Length <> 10 Then
Return False
End If
' Error if 2nd or 5th char is <> "/"; string array is 0-based
Dim sLength As Int
sLength = ThisDate.Length
For i = 0 To sLength-1
Dim s As String
s = ThisDate.CharAt(i)
If (i <> 2) AND (i <> 5) AND (Not (IsNumber(ThisDate.CharAt(i)))) Then
Return False
End If
If ((i = 2) OR (i = 5)) AND (ThisDate.CharAt(i) <> "/") Then
Return False
End If
Next
Dim smonth As String
Dim sday As String
Dim syear As String
'This line works
smonth = ThisDate.SubString2(0,2)
'Exception is thrown when the next line is executed
sday = ThisDate.SubString2(3,2)
syear = ThisDate.SubString2(6,4)
End Sub