my brain is struggling a bit right now and I'm trying to accomplish what is said in the title. To reiterate, if I have an arbitrary string and I want to find the position of four consecutive numbers (of integer value between 0 and 9), separated by two "-", so I need to find "-****-" where each "*" represents an integer between 0 and 9. The ideal return value of the function would be the position of the first "-".
What I have tried so far, which returns all integers within an arbitrary string. I haven't been able to get much farther than this.
Function onlyDigits(s As String) As Integer
Dim retval As String ' This is the return string. '
Dim i As Integer ' Counter for character position. '
Dim firstDashPosition As Integer
Dim foundDash As Boolean
foundDash = False
firstDashPosition = 0
Debug.Print s
retval = ""
For i = 1 To Len(s)
If Mid(s, i, 1) Like "-" Then
If foundDash = True Then
retval = retval + "-"
firstDashPosition = i
onlyDigits = firstDashPosition - 6
Exit Function
End If
Debug.Print "here"
foundDash = True
retval = retval + "-"
ElseIf Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" And foundDash = True Then
retval = retval + Mid(s, i, 1)
Else
foundDash = False
retval = ""
End If
Next
onlyDigits = firstDashPosition
End Function