Shop OBEX P1 Docs P2 Docs Learn Events
a lil help trimming this fat please — Parallax Forums

a lil help trimming this fat please

skynuggetskynugget Posts: 172
edited 2008-11-09 16:12 in BASIC Stamp
hey all,
im tryiing to trim down a project, one of my hoggy pieces of code is this

GET 8,hrs
GET 9, mins
GET 10, secs

GET 11, month
GET 12, date
GET 13, year

GET 14,1hrs
GET 15, 1mins
GET 16, 1secs

GET 17, 1month
GET 18, 1date
GET 19, 1year

at one point i have 20 lines og "gets".

im trying to figure out a way to do it with a for next and lookup, but im just in a duh moment..

can anyone help me out, pritty please?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-08 23:50
    If you declare the variables (hrs, mins, secs, month, ...) in the same order as the GET locations, you can use hrs as an array and use a FOR/NEXT loop to copy the values like:
    FOR i = 0 to 11
       GET 8+i,hrs(i)
    NEXT
    
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-09 06:00
    Mike's way is excellent. The following might execute a little faster, not having to update a subscript:

    Get 9, hrs, mins, secs, month, date, year, ... etc ...

    Also it appears from your sample that you're naming, or trying to name, a variable "1year", and so forth. I believe variable names can't start with digits.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • skynuggetskynugget Posts: 172
    edited 2008-11-09 16:12
    thanks guys! you know ive been playing with stamps for a year now, and i have yet to use an array, i forgot they could!! thanks again
Sign In or Register to comment.