Shop OBEX P1 Docs P2 Docs Learn Events
Countdown timer, combine 3 variables into one. — Parallax Forums

Countdown timer, combine 3 variables into one.

jayovejayove Posts: 2
edited 2006-06-15 22:05 in BASIC Stamp
I am developing a countdown timer circuit using BS2.· I start by setting·3 variables in an array.· For example:
var1=7
var2=2
var3=0

I want var4 to = 720.· How can I combine var1-3?

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-06-14 20:49
    Quick & Dirty way:

    var4 = var3
    var4 = var2 * 10 + var4
    var4 = var1 * 100 + var4
  • Tristan TTristan T Posts: 31
    edited 2006-06-14 23:13
    Quick and less dirty way:
    var4 = (var1 + (var2*10) + (var3*100))
    [noparse];)[/noparse]
  • SSteveSSteve Posts: 808
    edited 2006-06-14 23:19
    Tristan, that would give the value 27 instead of 720. You meant:
    var4 = (var1*100) + (var2*10) +var3
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-06-15 13:55


    PBASIC·recognizes groups with·( ) ?·

    I thought that it just goes left to right regardless.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-15 14:11
    PJ,

    ·· In the Editor Help File under PBASIC Operators it explains that you can use parenthesis to change the order that things are evaluated in.· Within the parenthesis it is also from left to right.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-06-15 14:29

    · Well, dangit...

    ··OK, I looked up parentheses in PBASIC Help's Search and found Operator Precedence.
    · Before, I've only looked up stuff from the Index -- and·there's been that Search tab there all this time.· Boy, howdy.
    · Got it.

    Post Edit --

    · BTW, jayove, VARiables·with values greater than 255 (e.g. var4, var1) will need to be declared as Words.

    Post Edited (PJ Allen) : 6/15/2006 2:33:29 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-15 14:33
    PJ,

    ·· You don't even have to search...If you click the + next to PBASIC Reference (In Contents) then click the words PBASIC Operators you're right in the section that explains how they're evaluated.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Tristan TTristan T Posts: 31
    edited 2006-06-15 15:07
    SSteve, yeah you're right. Note to self: check your work when being a smart**s.

    Post Edited By Moderator (IT Guy (Parallax)) : 6/15/2006 8:15:27 PM GMT
  • grimshadygrimshady Posts: 80
    edited 2006-06-15 22:05
    I think only the BS1 lacks the ability to use (Parenthesis)
    PJ Allen said...



    PBASIC·recognizes groups with·( ) ?·

    I thought that it just goes left to right regardless.

Sign In or Register to comment.