Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UBasic Modulo Function Update

Status
Not open for further replies.

MiggyD

Programmer
May 23, 2000
1,152
0
0
US
With regards to thread204-1706016

JHHPavel said:
I was writing a program in UBasic, ... and couldn't remember the proper format for the modulo function.

I tried googling for help but ... I couldn't find a math function help screen.

Does anyone know the proper format? Or have a link to a UBasic help site that doesn't deal with focusing cameras?

Found a site that may help -- even though it's a 2-year old post, this may be of use for the next person. It mentions cameras towards the later half of the wiki.


Once there, search for the section entitled (now get this...)

Math Expressions allowed in uBASIC

It is approximately 1/4 of the way down from the top (currently). I'd recommend you use your browser's "FIND" function for the above (or at least 'Math Expressions').

Then carefully read the first 2 paragraphs.


AND Before anyone gets mad; there is no uBASIC on this site. Not like it's still active nor popular, BUT I've checked and we have:

[ul]
[li] DarkBASIC [/li]
[li] Visual BASIC [/li]
[li] Visual BASIC for Applications (VBA) [/li]
[li] QBasic [/li]
[li] Even, Vb Script [/li]
[/ul]

So I think this was the only choice forum to post that question. And (at least for me) warranted some help.

--MiggyD
 
In case the wiki is gone, I'd thought I'd follow up....

In short MODULO (in UBasic) simply means "REMAINDER" -- and -- the mathematical expression to activate it is by using the percent sign (%).

FROM The Wiki Page said:
Most of the expressions are easy to understand, but the % (remainder) operation might like a short explanation.

Example: Let's say you have computed a number to equal how many seconds something will take for a duration. Such as s=(some math expression) Where s is being assigned the number of seconds computed.
In math it's called "modulo".

Now you want to display that as minutes and seconds. You will need a print statement such as:

print "Total Time:" , s/60; "min", (the remainder of s/60); "sec"

There is a very simple way to do this using the % command. Think of % as "the remainder of s being divided by". So all you need to do is have this print statement:

print "Total Time:" , s/60; "min", s%60; "sec"

If s had the value of 328 seconds, then this would print out to

Total Time: 5 min 28 sec
--OR--
Total Time: (328/60)=5 min (the remainder of 328/60)=28 sec


So based on that info, if someone gave you (US) 459 pennies you could use modulo to tell you that a customer gave you 4 dollars and 59 cents with:

print " whole dollars:", 459/100
print "additional cents:", 459%100

In this example, 1 U.S. dollar (the WHOLE unit) is made up of 100 pennies.
In the wiki example, 1 minute (the WHOLE unit) is made up of 60 seconds.

Modulo may be appropriate in certain calculations. One would just need to know the Whole Unit and it's constituents.
[pre]

Kitchen...
1 fluid cup = 8 fluid ounces // 1 quart = 4 cups = 32 ounces

Medical...
1 cc = 1 mL // 1 tsp = 5 cc // 1 Tbsp = 3 tsp = 15 cc (or 15 mL)
1 fluid ounce = 2 Tbsp = 30 cc (or 30 mL)

(etc)
[/pre]

HTH
--MiggyD

After pondering the riddle (for many years I might add) I finally got the answer (inadvertently through a movie): "If a tree falls in the forest and no one is around, does it make a sound?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top