Link to home
Start Free TrialLog in
Avatar of N P
N P

asked on

how to change _screen.Caption value dynamically reading from a text file.

I have a Visual Foxpro program where I want the _screen.Caption to show title that I read from a text file.  I use FIRLTOSTR to get the text I want to display.  I create a copy of my program each year for reuse, and I was trying avoid recompiling the foxpro program.


*get the value from text file and display window title
*modify _screencaption.txt file to avoid recompiling program
lnLines=FILETOSTR(SYS(5)+SYS(2003)+"\_screencaption.txt")  
_screen.Caption = lnLines


Open in new window

my _screencaption.txt file has the following text:


Budget 2022 - 2023 VFP8 ENG70_NP23

Open in new window


The problem is that I have to recompile the program each time I change the the values in the _screencaption.txt file in order to see the text in the file.  I there a way I can avoid recompiling my program and show screen captions by reading a value from some file?  I need to change the screen caption title differently each year.

Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Your code should work and show the caption from the file each time you restart it. No need to recompile. What is the issue here?  Does the program run over the year end so the caption isn't changed immediately?
Of course, the _screencaption.txt file must not be included in the EXE but you have to place it into the folder specified by the expression SYS(5)+SYS(2003).
BTW, you may use the following function to return the path where the EXE is located and use it in the FILETOSTR(). The function should be placed in the main program.
PROCEDURE AppFolder
RETURN ADDBS(JUSTPATH(SUBSTR(SYS(16), AT(" ", SYS(16), 2)+1)))

Open in new window

lnLines=FILETOSTR(AppFolder()+"_screencaption.txt") 

Open in new window

Avatar of N P
N P

ASKER

So I have Folder called "budget2022" from last year which has a _screencaption.txt file with text "Budget 2021 - 2022 VFP8 ENG70_NP23 " and a budget.exe.

What did was create a copy of "budget2022" folder  to "budget2023" folder.

Then I went in "budget2023" folder and changed the _screencaption.txt text value to "Budget 2022 - 2023 VFP8 ENG70_NP23".  When I run the budget.exe file from folder "budget2023", it still shows last years caption "Budget 2021 - 2022 VFP8 ENG70_NP23 ".  

When I into VFP IDE and debugged the main.prg step by step,  "lnLines=FILETOSTR(AppFolder()+"_screencaption.txt")" the lnLines show the correct value in the VFP IDE.  When I run the budget.exe from folder it shows the wrong value.  That is so weird. 

here is the code

Open in new window

 here is what it looks like when I debugged in VFP IDE

correct folder in VFP debug:
User generated image
correct value in VFP debug:
User generated image
correct display of caption when run from debug:
User generated image

Here is my _screencaption.txt with the text
User generated image
I run the budget.exe from budget2023 folder, and it got the wrong title
User generated image
Is the _screencaption.txt file included in the project?
Does the application use CONFIG.FPW ?
Avatar of N P

ASKER

oh, I'm a dummy, looks like I included _screencaption.txt.  I excluded now.   It doesn't look like I have CONFIG.FPW in my budget2023 folder.  I will have to recompile right with the _screencaption.txt excluded?
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of N P

ASKER

Your the man Pavel.  I excluded the file and recompiled.  That worked flawlessly.  I also tried the FPW suggestion, but that seems to require a recompile each year, I wanted to have a solution where I don't have recompile.  Thanks for your invaluable help again. 
With the CONFIG.FPW it is the same story as with the _screencaption.txt. Once the config is included in an EXE you have to recompile.
CONFIG.FPW just does not need extra instructions in the code.

To do everything in two or more different ways is an advantage of VFP... once something fails you still have additional option(s).
Avatar of N P

ASKER

Yeah, I tried config.fpw excluded. Recompiled. Title showed up correctly.  Then went and change the title again in config.fpw using notepad, but it held on the original title value.  
If the code for reading _screencaption.txt is still active then it has precedence to the CONFIG.FPW

Avatar of N P

ASKER

I tried it initially with CONFIG.FPW, and had commented _screencaption.txt read completely.  That's when I discovered that CONFIG.FPW didn't work. 
I've created a new VFP 6 project containing just one PRG file with the only WAIT WINDOW command inside. I've created EXE and added CONFIG.FPW to the same folder:
User generated image
The MVCOUNT is irrelevant here but the Title= setting appeared on the App window title:
User generated imageNo recompilation is necessary to display different title. VFP 8 should work the same way.

My explanation of the behavior described by you: Your CONFIG.FPW is included in the EXE or the application reads different CONFIG.FPW than you expect.

Anyway the issue is solved by correct _screencaption.txt handling so you may ignore this post.:-)