# 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 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 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 on other sites

Thanks crazy eye,

Works like a charm.

MW

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×
×
• Create New...