Simple Visual Basic function am I missing something?

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Mundekis
Newbie
Posts: 16
Joined: Fri Apr 18, 2003 10:15 pm

Simple Visual Basic function am I missing something?

Post by Mundekis » Fri Apr 18, 2003 10:44 pm

I'm a VB Newbie
Windows 2000
Ver 7.2.031

All I want this to do is trim my string. It returns the Value but doesn't want to trim the string.


Let>name= Ron

VBSTART

Function Trimstr(name)

Trimstr = Trim("%name%")

End Function


VBEND


VBEval>Trimstr(name),answer
MessageModal>%answer%

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Apr 19, 2003 12:01 am

Hello Mundekis....

Try this script.
I added a few more spaces at front and end of name and modified the message to make the result more visible.

VBSTART
VBEND

Let>name= Ron

VBEval>Trim("%name%"),answer

MessageModal>Original Start.....%name%.....Stop%CRLF%%CRLF%has been modified to:%CRLF%%CRLF%Start.....%answer%.....Stop
Since Trim is already a VB function you do not need to redefine it. Just run the VBSTART/VBEND at the beginning of the script. Then use VBEVAL with the normal VB syntax.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Mundekis
Newbie
Posts: 16
Joined: Fri Apr 18, 2003 10:15 pm

Thanks Bob

Post by Mundekis » Mon Apr 21, 2003 1:26 am

I'm now on my way to mastering VBScript. That takes care of lots of questions I've had.

gavinb

VBEval and Trim

Post by gavinb » Mon Aug 23, 2004 3:40 am

I have cust and pasted the code from Bob Hansen's sample and it does not work for me.

The return value is an empty string.

Any ideas?
Let>name= Ron

VBEval>Trim("%name%"),answer

MessageModal>Original Start.....%name%.....Stop%CRLF%%CRLF%has been modified to:%CRLF%%CRLF%Start.....%answer%.....Stop

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Aug 23, 2004 4:42 am

Be sure when you Cut/Paste from the forum that you remove all trailing space characters. You can do this from the Macro Scheduler Editor. Click on Edit, Show All Chars and Remove Trailing Spaces.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Lumumba

Post by Lumumba » Mon Aug 23, 2004 6:43 am

Marcus,
please create a sticky note
Subject: How to copy and paste code from the forum.
Message body: Be sure when you Cut/Paste ...
Thx.
-----
Bob,
F3:: TrailingSpaces = Be sure when you Cut/Paste from the forum that you remove all trailing space characters. You can do this from the Macro Scheduler Editor. Click on Edit, Show All Chars and Remove Trailing Spaces.

ControlSend, %TrailingSpaces%
Return
FileExtension: ahk
Run it with its assigned program and press F3 to fire your C&P comment as often as you like.
btw: why not using the cmd/command comment as a second hotkey in the same script ? :wink:

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Aug 24, 2004 9:32 pm

The latest version of Macro Scheduler automatically removes trailing spaces and control chars from pasted code that has been copied from an HTML source (such as from Internet Explorer). So it really shouldn't be necessary to do this manually. In any case there is the Edit/Remove Trailing Spaces option that does it in one go.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Aug 24, 2004 10:10 pm

Good suggestion Lumumba, maybe for someone else, but I rarely make hot keys.

And I don't have the problem, usually. You and I and other long time users are familiar with this. I usually include the caution in a forum message when I see a new user on the forum with some unknown problem, or try to prevent them from having the problem if I think they might be doing Cut/Paste from something I have submitted.

No big deal to clear them from the Edit menu when I have them. The big problem is knowing that you may need to do it, and do look for it. And as Marcus mentioned, the latest version corrects that, and now that I think about it, I honestly don't know that last time I actually had to do that myself.

Re a "sticky", that may be redundant. The following information is "whispered" just above the box I am typing into now:
If pasting script code, highlight it and press the 'Code' button to ensure it can be copied and pasted correctly
That was pointed out to me many years ago when I was complaining about Cut/Paste. I was told that by using "Code" the problem would not occur. But I can't be bothered to use Code in addition to Quote and prefer the appearance that I see with Quote tools.
=====================

With all that said, I wonder if that caused/corrected the problem that was originally brought up a few messages ago?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts