Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the difference between trim and trim$ in vba? Accidentally today when I used left and trim functions in vba, The compiler said cant find project or library

When I googled it ,On one of the forum I found the user using like these

vba.trim("string")

He answered to prefix with vba for the functions. and surprisingly it worked on my pc too.But I found these functions

trim and trim$
left and left$
leftb and leftb$

I was wondering what is trim and trim$. I wanted to find the difference So I started to google it but the results are for trim ignoring the $ alphabet.

I'm just curious to know about it.I was suspecting that trim is vba function and trim$ is excel sheet function. But we have Application.worksheetfunction to use excel functions right?Could anyone differentiate trim and trim$.

What I have tried:

trim and trim$
left and left$
leftb and leftb$
Posted
Updated 24-Oct-17 8:02am
Comments
Richard MacCutchan 24-Oct-17 12:55pm    
Use the VBA help to find explanations and sample code.

1 solution

A common difference between functions is that that function without $ returns variant, but with $ retruns string. Seems that using function with $ at the end is excuted bit faster. See: Dollar Sign ($) Functions[^]

Note: When you work with MS Access, you have to be aware, that using function with $ together with Null as an input parameter will generate error 94 (Invalid use of Null).

That's all!
 
Share this answer
 
v2
Comments
CHill60 24-Oct-17 14:26pm    
5'd! Very comprehensive answer.
As an aside I once had to prove to management that trim$ was faster in VB6. That brought back some ancient memories :-)
Maciej Los 24-Oct-17 14:32pm    
Thank you, Caroline.
I haven't experienced difference in the time of execution. I have to believe you ;)
CHill60 24-Oct-17 14:34pm    
Actually I think it might have been VB3! :-O
Maciej Los 24-Oct-17 14:49pm    
Wow! As Wiki states VB3 was released at the summer of the 93. Pretty ancient times...
JayyMehta 25-Oct-17 5:14am    
@marciej so that means that there's no major difference between these terms except the fact that the execution is faster with $...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900