Jump to content
Sign in to follow this  
weststreet

What the hey?! Should work?

Recommended Posts

Hi all,

Once again, when I think I'm making headway with my self- teaching methods, I take one right across the forehead.

I have a number in a text field (so that it will display a hyphen) that is 8 digits long.

12345678

This "job number" can have "sub" jobs, and we ad "-1", "-2", etc.

12345678-1

12345678-2

My script starts like this:

[color:green]Case(

(Length (GetAsNumber (Job Number)) = 8); (Job Number) & "-1";

That determines that the number has 8 numerals and it ads a "-1" to it. It works fine.

Then, if it doesn't see 8 numerals, it asks what the suffix is here (in this case, it sees 12345678-7, and makes the next record 12345678-8. It works fine.

[color:green]Right (Job Number;1)=7; (Left (Job Number;8)) & "-8";

Then, when it gets to the teens, it only adds the last number! I can't figure it out. It does NOT work fine. So the following would be 12345678-13, but the returned number is 12345678-4.

[color:green]Right (Job Number;2)=13; (Left (Job Number;8)) & "-14";

Thanks!

MW

Share this post


Link to post
Share on other sites

It's a little unclear... Is this a Set Field script step? Is everything in green part of the same Case statement?

I'm assuming yes to both of those questions and the answer is simple...a Case statment evaluates test sequentially. So if the job number is -13, the statment evaluates the Right(Job Number;1)=3 first and it tests true and returns -4.

You can rejigger your Case function by switching the second and third tests as stated in your post and it should work, though

I'm guessing the whole statement is very kludgy.

Try this:

Let([

Nums = Length(Trim(Job Number));

NextNum = 1+ Case(Nums = 8;0; Right(Job Number; Nums-9) )

];

Left(Job Number;8) & "-" & NextNum

)

Edited by Guest
Slight change to calc

Share this post


Link to post
Share on other sites

Smack! (That's my palm hitting my forehead)

Yes, it sees the second digit of the teens again.

I am going to try your calc. It is certainly a lot cleaner than mine. One more lesson learned.

Thanks

MW

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.