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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim does not work

Status
Not open for further replies.

zrazzaq

MIS
Apr 13, 2005
102
US
Hi all:
I created a textbox and a button that the user can open a dialog window and get there file and import it. The problem is I have all these unforseen characters at the end of the file.
I trimmed it and still does not work.
C:\Documents and Settings\razzaz\My Documents\Databases Testfiles\CMS\agentsumd_7042006.csv
Now if you go to the end of this you will notice all the spaces after the csv. That is how long the file name is which is bunching up my code to get the date to import...
I have no idea what else to try...
Any suggestions
Thanks
Zishan
 
Ok I got the chr which is chr(32)
Now how do I delete all of these after csv...
Thanks
Z
 
Just a thought, when you use the Trim command you must assign the result to a variable for example

Trimmed = Trim(mystring)

not just
Trim(mystring)
 
Assuming that all of your data has no spaces in it except the end, you can loop through each character until you find the first space (chr(32)) and take that as the 'new' path:

Code:
Function playwith()
Dim oldpath As String
Dim newpath As String
Dim char    As String
Dim x As Integer


oldpath = "C:\Documents and Settings\razzaz\My Documents\Databases Testfiles\CMS\agentsumd_7042006.csv                      "


For x = 1 To Len(Mid(oldpath, 71)) 'starts at the file name
 If Mid(oldpath, 70 + x, 1) = Chr(32) Then 'start looking for chr(32) in the file name
    newpath = Mid(oldpath, 1, Len(oldpath) - x + 6)
    Debug.Print "old "; Len(oldpath)
    Debug.Print newpath
    Debug.Print "new"; Len(newpath)
    Exit For
 End If
Next x
 
End Function

You can play around with this if you think this is an acceptable way to do this.
 
Hi!

Another possibility (assuming that the letter combination csv will not be present anywhere but at the end) is:

newpath = Left(oldpath, InStr(oldpath, "csv") + 2)

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
just a shot... was this file create in a unix environment. I had this once many years ago, and I needed to run a Unix2DOS command to convert it to an acceptable ascii format. htwh,

Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
Actually I think it is...But I got it figured out...I took the len of it and got it from there. But thank you for all the help.
Thanks
Z
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top