vb "mid" function throws an error

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
webber123456
Newbie
Posts: 11
Joined: Thu Aug 04, 2005 10:06 pm

vb "mid" function throws an error

Post by webber123456 » Fri Aug 05, 2005 8:35 am

error thrown on mid function for this macro - which is supposed to find the leading whitespce for line in clipboard.

VBSTART

Function GetWhiteSpace (vLine)
Dim i
Dim vChar
Dim vWhitespace
Dim vlenLine

vWhitespace=0
i=0

vlenLine = Len(vLine)
For i= 0 to vlenLine
vChar = mid(vLine,i,1)
If vChar = " " then vWhitespace = vWhitespace + 1
If vChar notepad*
GetClipBoard>cbLine
Length>cbLine,lenLine
VBEval>GetWhiteSpace(cbLine),answer

//Output
//----------------
Send Character/Text>This is supposed to get the leading whitespace of the line in the clipboard .
Press Enter

Send Character/Text>cbLine
Press Enter

Send Character/Text> - total length is:
Send Character/Text> lenLine
Press Enter

Send Character/Text> - WhiteSpace length is
Send Character/Text>answer
Press Enter
________
Medical Marijuana Patient
Last edited by webber123456 on Thu Feb 10, 2011 9:37 pm, edited 1 time in total.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Aug 05, 2005 2:19 pm

VBScript wants quotes around strings. Plus you are trying to pass a native variable into VBScript. You need to do this:

VBEval>GetWhiteSpace("%cbLine%"),answer
MJT Net Support
[email protected]

User avatar
webber123456
Newbie
Posts: 11
Joined: Thu Aug 04, 2005 10:06 pm

still getting error

Post by webber123456 » Fri Aug 05, 2005 7:43 pm

It still throws an error on the mid function:

=========================

VBSTART

Function GetWhiteSpace (vLine)
Dim i
Dim vChar
Dim vWhitespace
Dim vlenLine

vWhitespace=0
i=0

vlenLine = Len(vLine)
For i= 0 to vlenLine
vChar = mid(vLine,i,1)
If vChar = " " then vWhitespace = vWhitespace + 1
If vChar notepad*
GetClipBoard>cbLine
Length>currentLine,lenLine
VBEval>GetWhiteSpace("%cbLine%"),answer

//Output
//----------------
Send Character/Text>This is supposed to get the leading whitespace of the line in the clipboard .
Press Enter

Send Character/Text>%cbLine%
Press Enter

Send Character/Text> - length is: %lenLine%
Press Enter

Send Character/Text> - WhiteSpace length is: %answer%
Press Enter
________
VAPIR ONE VAPORIZER
Last edited by webber123456 on Thu Feb 10, 2011 9:37 pm, edited 1 time in total.

User avatar
webber123456
Newbie
Posts: 11
Joined: Thu Aug 04, 2005 10:06 pm

Post by webber123456 » Sat Aug 06, 2005 3:11 am

i beleive the error can be fixed by changing the "For" line of code to:

For i= 1 to vlenLine
________
ESSENTIAL VAAAPP VAPORIZER
Last edited by webber123456 on Thu Feb 10, 2011 9:37 pm, edited 1 time in total.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Sun Aug 07, 2005 8:23 am

Yes, VBScript strings start at position 1, not 0.

So is your problem now solved?
MJT Net Support
[email protected]

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