Author Topic: Changing font color in the middle of a print statement  (Read 1658 times)

0 Members and 1 Guest are viewing this topic.

Offline lawsonm1

  • Newbie
  • Posts: 64
    • View Profile
Changing font color in the middle of a print statement
« on: May 26, 2020, 09:43:38 pm »
I have a program that pulls some stock prices from a website. I take the opening price as a base and then display it and the current price on the same line. Since things are displayed in USD, I use Print Using statement so I can get the value formatted properly, and I want it all on the same line. I'd like to be able to change the color of the 'current' value to red if the price goes down. I can't seem to find a way to change font color in the middle of a Print statement though. Here is a snippet of the code I use to display the line. I know it can probably be shortened, but this makes it easier for my pea brain to understand. Thanks, Mike

Code: QB64: [Select]
  1. LOCATE 20, 1: PRINT USING "$$#####.##"; XYZopen;
  2. PRINT " (Open)   ";
  3. PRINT USING "$$#####.##"; XYZcur;
  4. PRINT " (Curr)   ";
  5. PRINT USING "$$#####.##"; (XYZcur - XYZopen); 'red if negative
  6. PRINT " (Delta)   ";
  7. PRINT USING "$$#####.##"; ((XYZcur * XYZsh) - (XYZpr * XYZsh)) 'red if negative

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Changing font color in the middle of a print statement
« Reply #1 on: May 26, 2020, 10:21:05 pm »
Code: QB64: [Select]
  1. SCREEN 12 '<<<<<<<<<<<< set color according to screen setup
  2. XYZcur = 100
  3. XYZopen = 200
  4. LOCATE 20, 1: PRINT USING "$$#####.##"; XYZopen;
  5. PRINT " (Open)   ";
  6. PRINT USING "$$#####.##"; XYZcur;
  7. PRINT " (Curr)   ";
  8. IF (XYZcur - XYZopen) < 0 THEN COLOR 12 '<< red for screen 12
  9. PRINT USING "$$#####.##"; (XYZcur - XYZopen); 'red if negative
  10. PRINT " (Delta)   ";
  11. IF ((XYZcur * XYZsh) - (XYZpr * XYZsh)) < 0 THEN COLOR 12 '<< red for screen 12
  12. PRINT USING "$$#####.##"; ((XYZcur * XYZsh) - (XYZpr * XYZsh)) 'red if negative
  13.  

Offline lawsonm1

  • Newbie
  • Posts: 64
    • View Profile
Re: Changing font color in the middle of a print statement
« Reply #2 on: May 26, 2020, 10:27:20 pm »
Thanks bplus, I was trying to add the color change on the same line! der de der. I am so stoopid sometimes. I will try that in the morning. Mike

Offline lawsonm1

  • Newbie
  • Posts: 64
    • View Profile
Re: Changing font color in the middle of a print statement
« Reply #3 on: May 27, 2020, 10:13:48 am »
I made the changes this morning, and it has been working great. Thank you so much, Mike