Variables replacement with numbers

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Martin Page
Drutt
Posts: 18
Joined: Mon Oct 31, 2022 11:04 am

Variables replacement with numbers

Post 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.
User avatar
PeterJ
Site Admin
Posts: 6942
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Variables replacement with numbers

Post by PeterJ »

Welcome @Martin Page,

Are these yours?

https://spectrumcomputing.co.uk/list?label_id=9320
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Variables replacement with numbers

Post 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.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
Martin Page
Drutt
Posts: 18
Joined: Mon Oct 31, 2022 11:04 am

Re: Variables replacement with numbers

Post 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
User avatar
stupidget
Dynamite Dan
Posts: 1654
Joined: Wed Jan 24, 2018 2:09 pm
Location: Sunny Wolverhampton

Re: Variables replacement with numbers

Post 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.
Martin Page
Drutt
Posts: 18
Joined: Mon Oct 31, 2022 11:04 am

Re: Variables replacement with numbers

Post 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.
Martin Page
Drutt
Posts: 18
Joined: Mon Oct 31, 2022 11:04 am

Re: Variables replacement with numbers

Post 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.
User avatar
patters
Manic Miner
Posts: 474
Joined: Thu Apr 11, 2019 1:06 am

Re: Variables replacement with numbers

Post 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
SNG
Drutt
Posts: 13
Joined: Sat Dec 23, 2023 12:16 am

Re: Variables replacement with numbers

Post 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!
Post Reply