AOB
Registered User.
- Local time
- Today, 22:24
- Joined
- Sep 26, 2012
- Messages
- 633
Hi guys,
I'm trying to do a string compare between two variables. One string variable is part of an array (which I'm looping through), the other is passed to the function as an argument.
(Background, if it helps; the function should return the position of a field in the OrderBy string of a subform. So I can see the priority of a field in the sort)
Here's the VBA :
The weird thing is, the line in blue returns True when, by watching the variables, it appears that it should not, and returns False when it appears that it should?
For example :
I would have thought the expression "[RandomField]" Like "[RandomField]*" should return True?
And similarly the expression "[SomeFieldName]" Like "[ADifferentField]*" should return False?
Any suggestions? Have been using 'Like' for donkey's years and never seen it throw results like this before?
(P.S. The reason I need to use 'Like' rather than a straight = is to account for the possibility that a field may be sorted descending, and therefore to nullify the DESC keyword which may follow any given field...)
Thanks!
AOB
I'm trying to do a string compare between two variables. One string variable is part of an array (which I'm looping through), the other is passed to the function as an argument.
(Background, if it helps; the function should return the position of a field in the OrderBy string of a subform. So I can see the priority of a field in the sort)
Here's the VBA :
Code:
Private Function SortPosition(strOrderBy As String, strField As String) As String
[INDENT]Dim arrSortedFields() As String
Dim i As Long
If Len(strOrderBy) > 0 And InStr(strOrderBy, strField) > 0 Then
[INDENT]arrSortedFields = Split(strOrderBy, ",")
For i = LBound(arrSortedFields) To UBound(arrSortedFields)
[INDENT]If [COLOR=blue]arrSortedFields(i) Like "[" & strField & "]*"[/COLOR] Then
[INDENT]SortPosition = "Sort Priority " & i + 1 & " of " & UBound(arrSortedFields) + 1
Exit For
[/INDENT]
End If
[/INDENT]
Next i
[/INDENT]
Else
[INDENT]SortPosition = ""
[/INDENT]
End If
[/INDENT]
End Function
The weird thing is, the line in blue returns True when, by watching the variables, it appears that it should not, and returns False when it appears that it should?
For example :
arrSortedFields(i) = "[RandomField]"
strField = "RandomField"
arrSortedFields(i) Like "[" & strField & "]*" = False
arrSortedFields(i) = "[SomeFieldName]"
strField = "ADifferentField"
arrSortedFields(i) Like "[" & strField & "]*" = True
I would have thought the expression "[RandomField]" Like "[RandomField]*" should return True?
And similarly the expression "[SomeFieldName]" Like "[ADifferentField]*" should return False?
Any suggestions? Have been using 'Like' for donkey's years and never seen it throw results like this before?
(P.S. The reason I need to use 'Like' rather than a straight = is to account for the possibility that a field may be sorted descending, and therefore to nullify the DESC keyword which may follow any given field...)
Thanks!
AOB