Menu

Print hours and minutes, STR$() with leading zeros

Help
Anonymous
2016-10-14
2019-06-13
  • Anonymous

    Anonymous - 2016-10-14

    In my app, I have have a timer. I would like it have the format "xx:yy" where x are the minutes and y are the seconds. I have tried many things, but have been unable to get anything to work. I know there are probably ways to do this this within a lot of string variable constructs, but preferring a simpler way, is it possible to use a TEXT command that uses the "USING" comand?

    Kevin

     
  • Kevin

    Kevin - 2016-11-16

    Ok, I guess it's ok to answer your own question.

    Although this has been gnawing at me for some time, it was not a show stopper, and I had many more problems to fix. And although I have been through the manual over and over many times, my mind is not capable of even understanding most of it, nor large enough to categorize and memorize it. However, yesterday I came across the USING$ command, and it was assigned to a string$ constant. I was familiar with the PRINT USING command from the '70s, but this was the 1st time I had come upon the USING$ command that actually registered as a posible candidate to rectify my situation.
    So I tried this: text 425,105,USING$(mins%,"00")+":"+USING$(secs%,"00")
    and it worked.
    I had prviously tried: text 425,105,STR$(mins%,2)+":"+STR$(secs%,2) and several other things,
    but always, the leading zeros disappeared.
    The nice thing I like about the USING$ construct above, is I did not have to define another string variable, which I thought at first I would have to do. Thus, my program does not have to grow as much, as it's now exceeding 1000 statements, and I'm trying to limit it where ever possible.

     
  • Markus Hoffmann

    Markus Hoffmann - 2016-12-01

    Well,
    STR$(mins%,2,2,1)
    would also produce leading zeroes.

     
  • Kevin

    Kevin - 2016-12-03

    I was anonymous (and lost) when I submitted the 1st post.
    I never tried using the "c" expression in STR$ since I didn't think significant digits would be useful when displaying an integer, and just thought the length descriptor was sufficient.

    Ok, I'm going to assume you made a typo. You said STR$(mins%,2,2,1), and I'm going to assume you meant STR$(mins%,2,2), since, according to the manual, STR$ only has an a, b, and c expression. If I'm wrong, let me know

    Kevin

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.