string lenght problem

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
rblack
Pro Scripter
Posts: 87
Joined: Sat Dec 22, 2007 12:39 pm

string lenght problem

Post by rblack » Sat Mar 08, 2008 1:43 pm

Hi, i'm freakin out with a simple script. I want to fill out form with entered previous string, but if its less then 6 characters, the last digit is multiplied, for example:
input: one,
output oneeee
or
input: 1
output: 111111

I tried this code, but the output string is only 2 characters long, and i dont know why


let>pass={"1"}
//check if length is correct
Length>%pass%,leng

If>leng [this > sign after 6 is not in code but i cannot paste it in other way]

MidStr>%pass%,%leng%,%leng%,last

label>leng2
let>%pass%=%pass%%last%
MessageModal>num: %leng%
let>leng=%leng%+1
MessageModal>num: %leng%
if>leng]
goto>leng2
endif
endif


Messages output always the same: first one num:1, second one num:22, so the last character is added only once. I dont get it. Please heeeelp

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Mar 08, 2008 2:23 pm

Good start, just needs a little clean up:

[code]
let>pass=1
//check if length is correct
Length>pass,leng

If>lengpass,leng,1,last

label>leng2
Concat>pass,last
Let>leng=leng+1
MessageModal>num: %leng% password: %pass%
if>lengleng2
endif
endif
MessageModal>final password: %pass%

[/code]

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

Post by Marcus Tettmar » Sat Mar 08, 2008 3:41 pm

Neater:

Code: Select all

let>pass=1
//check if length is correct
Length>pass,leng
If>leng<6
  MidStr>pass,leng,1,last
  Repeat>leng
    Concat>pass,last
    Let>leng=leng+1
    MessageModal>num: %leng% password: %pass%
  Until>leng=6
endif
MessageModal>final password: %pass%
Or if you want to be clever and briefer:

Code: Select all

VBSTART
VBEND
let>pass=1
VBEval>"%pass%" & string(6 - len("%pass%"), Mid("%pass%",len("%pass%"),1)),pass
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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