-
Hi,
Appreciate very much if someone can point out my mistake on the code sample below. What I am trying to do is to eliminate the "'" in front and at the back of the date string.
Kind regards
Public mtext As String
Private Sub Command1_Click()
Dim rDate As String
rDate = "'09/07/00'"
mtext = strip34(rDate)
msgbox(mtext) ' THIS MSGBOX RETURNED EMPTY STRING
End Sub
Private Function strip34(mStr As String)
Dim xCount%, iPos%
For xCount% = 1 To 2
iPos% = InStr(mStr, "'")
'Found at first position?
If iPos% = 1 Then
mStr = Mid(mStr, iPos% + 1, Len(Trim(mStr)))
Else
mStr = Mid(mStr, 1, iPos% - 1)
End If
Next xCount%
mtext = mStr
End Function
-
Loose the % and try again.
-
Code:
Public mtext As String
Private Sub Command1_Click()
Dim rDate As String
rDate = "'09/07/00'"
mtext = strip34(rDate) 'mtext is assigned the value returned by strip34
MsgBox (mtext) ' THIS MSGBOX RETURNED EMPTY STRING
End Sub
Private Function strip34(mStr As String) As String
Dim xCount%, iPos%
For xCount% = 1 To 2
iPos% = InStr(mStr, "'")
'Found at first position?
If iPos% = 1 Then
mStr = Mid(mStr, iPos% + 1, Len(Trim(mStr)))
Else
mStr = Mid(mStr, 1, iPos% - 1)
End If
Next xCount%
strip34 = mStr 'ASSIGN THE VALUE OF mStr to be returned by this function
End Function
-
<?>
Code:
Option Explicit
Public mtext As String
Private Sub Command1_Click()
Dim rDate As String
rDate = "'09/07/00'"
rDate = strip34(rDate)
MsgBox mtext
End Sub
Public Function strip34(mStr As String) As String
Dim xCount As Integer, intLen As Integer
intLen = Len(mStr)
For xCount = 1 To intLen
If Mid(mStr, xCount, 1) = "'" Then Mid(mStr, xCount, 1) = " "
Next xCount
mStr = Trim(mStr)
mtext = mStr
End Function
-
Thanks YoungBuck, it is working now!
Magic word is strip34 = mstr
kind regards
-
Many thanks to all those who has responded to my problem above.
Kind regards
-
<?>
If you have VB6 there is also Replace
rDate = replace(rdate,"'","")
-
Thanks to HeSaidJoe, Replace function pointed is even more efficient.
Best regards