need to create an integer

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1415
Joined: Sun Nov 03, 2002 3:19 am

need to create an integer

Post by Dorian (MJT support) » Wed Apr 21, 2004 8:21 pm

Hi guys,

How can I make a script create an integer from a number with decimal places? I want it to always round up to the next whole number.

I have a script which generates webpages, each containing 5 images, from a list of raw image names in a text file. So if I have 17 images, it will make 4 pages - three with 5 images and one with 2. I then need MS to know how many pages it made, and start working on another macro which makes a menu along the line of - so MS needs to know how many items to add to the menu.

So if I was to count the number of image names in the textfile and divide 5 I would get 3.4. I need to round this number up to 4 automatically.

Can this be done?

Lumumba

Post by Lumumba » Wed Apr 21, 2004 9:55 pm

:idea: So a non-integer output should contain a dot, correct ?

Check for the char "." in the output (I guess the Position> command would work).

If you've detected a dot - take the number in front of the dot (MidStr> command) and increase it with one. 8)

BTW: There's definitely a VBS option, which will be provided by a MSched Pro !

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 » Wed Apr 21, 2004 10:02 pm

Quick and dirty approach:

1. Normally take value and add .5 to help with rounding if equal or greater than .5. So to take any fraction to next integer, add .9
2. Find position of decimal in value
3. Take all characters to left of decimal position.

Samples:
Original Number.............Add............Decimal position........Left of decimal
12.5..............................13.4......................3...........................13
312.0............................312.9.....................4.........................312
6177.8.........................6178.7.....................5.......................6178
15...................................15.9.....................3...........................15
11.1.................................12.0.....................3...........................12
Input>Original,Enter a value to be rounded
Let>N=%Original%+.9
Position>.,%N%,1,Decimal
If>%Decimal%=0,WholeNumber

Label>Fraction
Let>Stop=%Decimal%-1
MidStr>%N%,1,%Stop%,Answer
Goto>Finish

Label>WholeNumber
Let>Answer=%N%

Label>Finish
MsgBox>Original %Original% has been raised to %Answer%
Be sure to Remove Trailing Spaces after doing Cut/Paste from forum.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1415
Joined: Sun Nov 03, 2002 3:19 am

Post by Dorian (MJT support) » Wed Apr 21, 2004 11:10 pm

Thanks guys, I really appreciate your help. This is exactly what I was looking for.

I don't know what I'd do without you guys to help me over my little stumbling blocks.

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