Create a variable
Create a variable
Hi,
To create a variable, I can write, for example: LOCAL AAA
Is it possible to create such a variable programmatically ?
To create a variable, I can write, for example: LOCAL AAA
Is it possible to create such a variable programmatically ?
- Antonio Linares
- Site Admin
- Posts: 42521
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 76 times
- Contact:
Re: Create a variable
Yes, but it won't be local
Simply assign it. At the top write:
memvar MyVar
later in your code:
MyVar = ...
but it will not be local, it will be public
Simply assign it. At the top write:
memvar MyVar
later in your code:
MyVar = ...
but it will not be local, it will be public
Re: Create a variable
Thanks Antonio, but this is somewhat not what I need. For example, I need to make 10 variables
for st=1 to 10
create variable "n_"+ltrim(str(st))
next
for st=1 to 10
create variable "n_"+ltrim(str(st))
next
Re: Create a variable
Perhaps,
for st=1 to 10
cName:= "n_"+ltrim(str(st))
PRIVATE &cName
next
regards
for st=1 to 10
cName:= "n_"+ltrim(str(st))
PRIVATE &cName
next
regards
- Marc Venken
- Posts: 1485
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: Create a variable
Maybe better use a array ?Natter wrote:Thanks Antonio, but this is somewhat not what I need. For example, I need to make 10 variables
for st=1 to 10
create variable "n_"+ltrim(str(st))
next
Local aGallery := ARRAY(12) // Max = 12 items
is very easy to programmaticaly fill these with specific data in a loop
for i = 1 to len(aGallery)
aGallery = i // or any dbf value or .....
next
You only have to think of 1 var name .... (Local of public,...)
Marc Venken
Using: FWH 23.08 with Harbour
Using: FWH 23.08 with Harbour
- Marc Venken
- Posts: 1485
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: Create a variable
Maybe better use a array ?Marc Venken wrote:Natter wrote:Thanks Antonio, but this is somewhat not what I need. For example, I need to make 10 variables
for st=1 to 10
create variable "n_"+ltrim(str(st))
next
Local aGallery := ARRAY(12) // Max = 12 items
is very easy to programmaticaly fill these with specific data in a loop
for i = 1 to len(aGallery)
aGallery = i // or any dbf value or .....
next
You maybe also consider using Hashes (I prefer them)
look : http://forums.fivetechsupport.com/viewt ... sh#p104891
Marc Venken
Using: FWH 23.08 with Harbour
Using: FWH 23.08 with Harbour
Re: Create a variable
Thank you, an interesting opportunity !
Last edited by Natter on Thu Nov 17, 2022 6:54 am, edited 1 time in total.
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Create a variable
No.Natter wrote:Hi,
To create a variable, I can write, for example: LOCAL AAA
Is it possible to create such a variable programmatically ?
Because, the local declarations must be available to the compiler.
Ofc, you can create private variables at runtime.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Antonio Linares
- Site Admin
- Posts: 42521
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 76 times
- Contact:
Re: Create a variable
Dear Yuri,
This is another possible way:
This is another possible way:
Code: Select all | Expand
#include "hbclass.ch"
function Main()
local oVars := TLocal(), n
for n = 1 to 10
__objAddData( oVars, "n_" + LTrim( Str( n ) ) )
next
oVars:n_1 = 123
? oVars:n_1
return nil
return nil
CLASS TLocal
ENDCLASS
Re: Create a variable
Thank you very much for an interesting opportunity !
Last edited by Natter on Thu Nov 17, 2022 6:59 am, edited 1 time in total.
- Otto
- Posts: 6403
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 24 times
- Been thanked: 2 times
- Contact:
Re: Create a variable
Hello,
May I ask, what is the purpose of these variables?
Best regards,
Otto
May I ask, what is the purpose of these variables?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************