Demivec wrote:A command to "alias" the variable would also be a solution to this scenario.
There's already a solution for your "alias":
Code: Select all
Macro Line
Command
EndMacro
Procedure DoSomethingImportant()
Protected Command.s
For i = 0 to count ; loop 1
Command = ProgramParameter()
; ...
Next
For i = 0 to 10 ; loop 2
Line = ReadString(1)
; ...
Next
EndProcedure
It's ugly, I know...
In this example the variable "Command.s" from loop 1 is reused as "Line.s" in loop 2.
Now there are two questions:
1. Why do I reuse that variable instead of declaring another one?
Imagine a Procedure that is called more often, maybe even recursive, and imagine there'd be 10 or 20 such loops - it would lead to a lot of memory beeing wasted or in the worst case even to a stack overflow.
2. Why don't I simply call that Variable String1?
Because I want my code to be readable!
PS and BTW:
A nice solution would be:
Code: Select all
Procedure DoSomethingImportant()
Protected Command.s Alias Line.s Alias String.s Alias ...
For i = 0 to count ; loop 1
Command = ProgramParameter()
; ...
Next
For i = 0 to 10 ; loop 2
Line = ReadString(1)
; ...
Next
For i = 0 to 10000 ; loop 3
String = Mid(...)
; ...
Next
EndProcedure
or:
Code: Select all
Procedure DoSomethingImportant()
Protected String1
Alias String1 As Command
For i = 0 to count ; loop 1
Command = ProgramParameter()
; ...
Next
Alias String1 As Line
For i = 0 to 10 ; loop 2
Line = ReadString(1)
; ...
Next
Alias String1 As String
For i = 0 to 10000 ; loop 3
String = Mid(...)
; ...
Next
EndProcedure
or maybe even this:
Code: Select all
Procedure DoSomethingImportant()
Protected String1
Alias String1 As Command
For i = 0 to count ; loop 1
Command = ProgramParameter()
; ...
Next
RemoveAlias Command
Alias String1 As Line
For i = 0 to 10 ; loop 2
Line = ReadString(1)
; ...
Next
RemoveAlias Line
Alias String1 As String
For i = 0 to 10000 ; loop 3
String = Mid(...)
; ...
Next
RemoveAlias String
EndProcedure