Page 1 of 1

Variables replacement with numbers

Posted: Mon Oct 31, 2022 11:22 am
by Martin Page
I wrote a few 48k BASIC programs back in the eighties, which were published by Sinclair User. To save space, I used variables for some of the commonly used numbers, e.g. a=1, b=2, c=3, etc. One of these programs I would like to develop more. To easily understand what I had written around 35 years ago is quite difficult with letters for numbers. Yes, I could manually replace all the variables with their relevant values but that would be a fiddly job and is prone to mistakes being made. Does anyone know of a program which could list the program variables with an option to automatically update all occurrences of those variables with their correct number value? Hope this makes sense!

Cheers, Martin.

Re: Variables replacement with numbers

Posted: Mon Oct 31, 2022 11:56 am
by PeterJ
Welcome @Martin Page,

Are these yours?

https://spectrumcomputing.co.uk/list?label_id=9320

Re: Variables replacement with numbers

Posted: Mon Oct 31, 2022 12:10 pm
by TMD2003
Martin Page wrote: Mon Oct 31, 2022 11:22 am Does anyone know of a program which could list the program variables with an option to automatically update all occurrences of those variables with their correct number value? Hope this makes sense!
There is a machine code routine to list the program variables in Hewson's "40 Best Machine Code Routines" - which I've already tested and have as an .ASM file that can be pasted into Spin's Z80 assembler.

Or, this is a roundabout way of seeing the variables: either load it into BASin, or, if that doesn't work, LLIST it with Fuse (make sure "Emulate printers" is checked...) and edit the .TXT file to remove all the carriage returns after 32 characters. Then, rename it to .BAS and open with BASin, run it, and there will be a window showing what variables are defined and what their values are.

Re: Variables replacement with numbers

Posted: Mon Oct 31, 2022 1:24 pm
by Martin Page
Yes, guilty as charged!
PeterJ wrote: Mon Oct 31, 2022 11:56 am Welcome @Martin Page,

Are these yours?

https://spectrumcomputing.co.uk/list?label_id=9320

Re: Variables replacement with numbers

Posted: Mon Oct 31, 2022 1:38 pm
by stupidget
Martin Page wrote: Mon Oct 31, 2022 1:24 pm Yes, guilty as charged!
Welcome to this great forum.

Forest of Long Shadows is an excellent game and is always in my top 10 of favourite Speccy games.

Re: Variables replacement with numbers

Posted: Mon Oct 31, 2022 2:02 pm
by Martin Page
Thanks Mr. Get, it's great to get good feedback albeit over 30 years later!
stupidget wrote: Mon Oct 31, 2022 1:38 pm Welcome to this great forum.

Forest of Long Shadows is an excellent game and is always in my top 10 of favourite Speccy games.

Re: Variables replacement with numbers

Posted: Tue Nov 01, 2022 12:48 pm
by Martin Page
TMD2003 wrote: Mon Oct 31, 2022 12:10 pm There is a machine code routine to list the program variables in Hewson's "40 Best Machine Code Routines" - which I've already tested and have as an .ASM file that can be pasted into Spin's Z80 assembler.

Or, this is a roundabout way of seeing the variables: either load it into BASin, or, if that doesn't work, LLIST it with Fuse (make sure "Emulate printers" is checked...) and edit the .TXT file to remove all the carriage returns after 32 characters. Then, rename it to .BAS and open with BASin, run it, and there will be a window showing what variables are defined and what their values are.
Thanks for the info.

Cheers, Martin.

Re: Variables replacement with numbers

Posted: Thu Nov 03, 2022 9:50 pm
by patters
Hi Martin,

My suggestion would be to install fuse-utils:
https://sourceforge.net/projects/fuse-e ... ils/1.4.3/

In there is a tool called listbasic that can convert a BASIC program within a .tap file into a modern text file. Then you can edit it in any modern code editor. E.g. Sublime (with my syntax highlighter for instance - see link in my sig). You'd be able to use a regular find&replace to convert your variables back to numbers.

Then you can use zmakebas to build your text file back into a tap file to test on a Spectrum emulator:
https://github.com/ohnosec/zmakebas

Re: Variables replacement with numbers

Posted: Sat Dec 23, 2023 4:21 pm
by SNG
Use my MultiSearch from Your Spectrum issue 12

http://www.users.globalnet.co.uk/~jg27p ... r12_47.htm

I also find it handy for eliminating spurious %s in NextBASIC after renumbering.

https://simon.mooli.org.uk/nextech/index.html#NoGo

Two cheers for compatibility!