HP Forums
New to programming...help ! - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: New to programming...help ! (/thread-3908.html)



New to programming...help ! - Digitaldreams - 05-18-2015 10:39 PM

Tried to print ticks divided by 1000 yet get a line of zero's ?. What is wrong with the below ?. Also what is the command to print at a particular location on the screen ?.


EXPORT TEST()
BEGIN
LOCAL TIC;

PRINT();

REPEAT
TIC=TICKS();
TIC=TIC/1000;
PRINT(TIC);
UNTIL GETKEY >-1;
END;


RE: New to programming...help ! - Eddie W. Shore - 05-19-2015 02:46 AM

(05-18-2015 10:39 PM)Digitaldreams Wrote:  Tried to print ticks divided by 1000 yet get a line of zero's ?. What is wrong with the below ?. Also what is the command to print at a particular location on the screen ?.


EXPORT TEST()
BEGIN
LOCAL TIC;

PRINT();

REPEAT
TIC=TICKS();
TIC=TIC/1000;
PRINT(TIC);
UNTIL GETKEY >-1;
END;

I'm not sure why TIC=TICKS() produces a zero result. However, the following will get what I think you want:

EXPORT TEST()
BEGIN
PRINT();

REPEAT
PRINT(TICKS/1000);
UNTIL GETKEY >-1;
END;


Eddie


RE: New to programming...help ! - Didier Lachieze - 05-19-2015 03:22 AM

(05-18-2015 10:39 PM)Digitaldreams Wrote:  Tried to print ticks divided by 1000 yet get a line of zero's ?. What is wrong with the below ?. Also what is the command to print at a particular location on the screen ?.

You got a line of zero's because you used "TIC=" instead of "TIC:=".
PRINT is printing to the terminal with each PRINT being on a different line, so if you want to print to a particular location on the screen you should use TEXTOUT_P instead of PRINT:

Code:
EXPORT TEST()
BEGIN
  LOCAL TIC;
  RECT();

  REPEAT 
    TIC:=TICKS()/1000;
    TEXTOUT_P(STRING(TIC),0,0,0,0,100,#FFFFFF);
  UNTIL GETKEY>-1;

END;



RE: New to programming...help ! - Digitaldreams - 05-19-2015 05:58 AM

(05-19-2015 02:46 AM)Eddie W. Shore Wrote:  
(05-18-2015 10:39 PM)Digitaldreams Wrote:  Tried to print ticks divided by 1000 yet get a line of zero's ?. What is wrong with the below ?. Also what is the command to print at a particular location on the screen ?.


EXPORT TEST()
BEGIN
LOCAL TIC;

PRINT();

REPEAT
TIC=TICKS();
TIC=TIC/1000;
PRINT(TIC);
UNTIL GETKEY >-1;
END;

I'm not sure why TIC=TICKS() produces a zero result. However, the following will get what I think you want:

EXPORT TEST()
BEGIN
PRINT();

REPEAT
PRINT(TICKS/1000);
UNTIL GETKEY >-1;
END;


Eddie

Thanks Eddie...believe it or not that was my first attempt and it didn't work, now it does !?. Maybe the recent firmware update did the trick....

Regards


RE: New to programming...help ! - Digitaldreams - 05-19-2015 06:18 AM

(05-19-2015 03:22 AM)Didier Lachieze Wrote:  [quote='Digitaldreams' pid='35504' dateline='1431988787']
Tried to print ticks divided by 1000 yet get a line of zero's ?. What is wrong with the below ?. Also what is the command to print at a particular location on the screen ?.

You got a line of zero's because you used "TIC=" instead of "TIC:=".
PRINT is printing to the terminal with each PRINT being on a different line, so if you want to print to a particular location on the screen you should use TEXTOUT_P instead of PRINT:

[code]EXPORT TEST()
BEGIN
LOCAL TIC;
RECT();

REPEAT
TIC:=TICKS()/1000;
TEXTOUT_P(STRING(TIC),0,0,0,0,100,#FFFFFF);
UNTIL GETKEY>-1 ;

END;[/code ]
[/quote ]

Thanks Didier......I shortened it too by removing TIC altogether. What is the function of ':' after a variable ??

Regards


RE: New to programming...help ! - Didier Lachieze - 05-19-2015 06:36 AM

(05-19-2015 06:18 AM)Digitaldreams Wrote:  What is the function of ':' after a variable ??

With "TIC=TICKS()" you get the result of the test "TIC equal TICKS()" which in your case in false (zero).
With "TIC:=TICKS()" you assign the value of TICKS() to the the variable TIC, it's the same as with the Sto command "TICKS()▶TIC" where you store the value to TICKS() into the TIC variable.

So in your original program you were comparing TIC to TICKS(), then TIC to TIC/1000 but never assigning a value to TIC, so the default value (zero) assigned to TIC at its creation by the "LOCAL TIC;" statement was printed.


RE: New to programming...help ! - Digitaldreams - 05-19-2015 06:55 AM

(05-19-2015 06:36 AM)Didier Lachieze Wrote:  
(05-19-2015 06:18 AM)Digitaldreams Wrote:  What is the function of ':' after a variable ??

With "TIC=TICKS()" you get the result of the test "TIC equal TICKS()" which in your case in false (zero).
With "TIC:=TICKS()" you assign the value of TICKS() to the the variable TIC, it's the same as with the Sto command "TICKS()▶TIC" where you store the value to TICKS() into the TIC variable.

So in your original program you were comparing TIC to TICKS(), then TIC to TIC/1000 but never assigning a value to TIC, so the default value (zero) assigned to TIC at its creation by the "LOCAL TIC;" statement was printed.

Thanks again Didier !....I'm sure with other devices I've used, if you want to comparison test you would enter '==' !, no wonder It confused me Smile

Regards