Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim$ function problem... 1

Status
Not open for further replies.

Sheffield

Programmer
Jun 1, 2001
180
US
I'm attempting to remove trailing spaces from a queried field in a database, with no luck. However, I don't want to alter the database, itself. Every field in the column has at least one trailing blank space.

Given Values
DataEnviron.rscmdStation.Fields!Station = "WPXN "
Text1.Text = "WPXN"

For reasons unknown, the code below doesn't 'trim' down the "WPXN " to "WPXN".
Code:
If Trim$(.rscmdStation.Fields!Station)= Text1.Text Then
     '- do whatever
End If

Any ideas?
 
Trim Removes spaces (CHR$(32)). If you last character was a null character (CHR$(0)) or someother non-printing character, trim will not remove it. - Jeff Marler B-)
 
How can such characters (null, non-printing ones) like (CHR$(0)) be removed?

Very curious...
 
John,

It is O.K. - to JUST taks care of the Null. AT the "END" of the string.

I think this is more Complete:

Code:
Public Function basReallyTrim(strIn As String) As String

    Dim strTrim As String
    Dim Idx As Long
    Dim strTmp As String

    strTrim = Trim$(strIn)      'Removes Spaces ONLY

    Idx = 1
    Do While Idx <= Len(strTrim)
        MyChr = Mid(strTrim, Idx, 1)
        Select Case UCase(MyChr)
            Case Chr(32) To Chr(94)     'Space through ^
                strTmp = strTmp & MyChr

            Case Chr(97) To Chr(126)    'a through ~
                strTmp = strTmp & MyChr

        End Select
        Idx = Idx + 1
    Loop

    basReallyTrim = strTmp

End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
jmarler, JohnYingling & MichaelRed,

Everything works perfectly!

Many thanks for all your help:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top