Variables ( Solved )

lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Variables ( Solved )

Post by lailton.webmaster »

MyArray:={ {'campo1', 30}, {'campo2', 50}}

for n = 1 to len(MyArray)

// How make it ?
// #define MyArray[n][1] MyArray[n][2]

next n

msginfo(campo2) // need return 50

i maked it

// it´s OK more is define campo2 as 50 only inside this function when i try msginfo(campo2) in other function
// give me erro variable no exist.
&( " "+Alltrim(MyArray[n][1]) +" := " + Alltrim(str(MyArray[n][1])) )

i try make it too.

&( "Public "+Alltrim(MyArray[n][1]) +" := " + Alltrim(str(MyArray[n][1])) )

More give me erro.

Someone can help ?

thanks
Last edited by lailton.webmaster on Tue Sep 08, 2009 4:22 am, edited 1 time in total.
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Variables

Post by Enrico Maria Giordano »

Sorry, I don't understand what you're trying to do. Can you rephrase your question?

EMG
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Variables

Post by lailton.webmaster »

METHOD Events() CLASS MyActiveX
local act, oReg, cTypeLib, aEvents

oReg := TReg32():New( HKEY_CLASSES_ROOT, "CLSID\" + ::cString + "\InprocServer32" )
cTypeLib := oReg:Get( "" )
oReg:Close()
act:=TactiveX():new(::Janela, ::cString,0,0,0,0)
if ! Empty( cTypeLib ) .and. File( cTypeLib )
aEvents = ActXEvents( cTypeLib, act:hActiveX )
endif
for n = 1 to len(aEvents)
#define aEvents[n][1] aEvents[n][2] // problem aqui :) no stay defined ...
next n

Return nil
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Variables

Post by lailton.webmaster »

other sample

MyArray:={ {'campo1', 30}, {'campo2', 50},{'kakaka',100},{'mouseon',20},{'click',-12} }
// this Array i receive in function ActEvents of fivewin. it´s only sample. no return always same array.

for n = 1 to len(MyArray)

#define MyArray[n][1] MyArray[n][2]
next n

:lol:
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Variables

Post by Enrico Maria Giordano »

Code: Select all

FUNCTION MAIN()

    LOCAL aArray := { { "SYMBOL1", 10 }, { "SYMBOL2", 20 } }

    LOCAL i

    FOR i = 1 TO LEN( aArray )
        &( "M -> " + aArray[ i, 1 ] + " := " + LTRIM( STR( aArray[ i, 2 ] ) ) )
    NEXT

    ? M -> SYMBOL1
    ? M -> SYMBOL2

    RETURN NIL
EMG
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Variables

Post by lailton.webmaster »

DOnt have other code ?

that dont need add M-> VAr ?

and i need too call this var in a function OutSide this method.

thanks
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Variables

Post by James Bott »

In order to see data outside the class it has to be defined as data of the class.

Code: Select all

class myActiveX
   data aEvents
   ...
endclass

Now you can access aEvents:

MsgInfo( oActiveX:aEvents[1][1] )

MsgInfo( oActiveX:aEvents[1][2])
You cannot use #DEFINE to define data of the class.

Or, if you want to make a class for each type of ActiveX that you are using, then you can define all the event names as data of the class, then you can assign the values to them when the object is initialized. Then you can access each event from outside the class.

Code: Select all

// ActiveX calendar class
CLASS calendar from TActiveX
   DATA Campo1
   DATA Campo2
endclass

Method new()
   ...
   aEvents = ActXEvents( cTypeLib, act:hActiveX )
   ::Campo1 := aEvents[1][2]
   ::Campo2 := aEvents[2][2]
   ...
return self

oCalendar := calendar():new()

msgInfo( oCalendar:Campo1 ) // returns value, e.g. 30
James
Last edited by James Bott on Sun Sep 06, 2009 4:30 pm, edited 2 times in total.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Variables

Post by James Bott »

Here is another way you could do it. Create a method getEvent() and pass it the name of the event to get the value.

Code: Select all

method getEvent( cEvent )
  local uValue, i
  cEvent:= upper(alltrim(cEvent))
  for i=1 to len( ::aEvents )
     if upper(::aEvents[i]) == cEvent
        uValue:= ::aEvents[i][2]
     endif
  next
return uValue

msgInfo( oCalendar:getEvent("campo1") )  // returns 30
James
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Variables

Post by lailton.webmaster »

Good James

thanks
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Variables

Post by James Bott »

If you haven't already read them, there are some articles on writing FW classes on my website at http://www.gointellitech.com.

James
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: Variables

Post by fraxzi »

lailton.webmaster wrote:MyArray:={ {'campo1', 30}, {'campo2', 50}}

for n = 1 to len(MyArray)

// How make it ?
// #define MyArray[n][1] MyArray[n][2]

next n

msginfo(campo2) // need return 50

i maked it

// it´s OK more is define campo2 as 50 only inside this function when i try msginfo(campo2) in other function
// give me erro variable no exist.
&( " "+Alltrim(MyArray[n][1]) +" := " + Alltrim(str(MyArray[n][1])) )

i try make it too.

&( "Public "+Alltrim(MyArray[n][1]) +" := " + Alltrim(str(MyArray[n][1])) )

More give me erro.

Someone can help ?

thanks
To get the value 50 on the second element of second sub-element is like this (as I understand your code):

....
LOCAL aX

MyArray:={ {'campo1', 30}, {'campo2', 50}}

FOR EACH aX IN MyArray
IF aX[2] == 50 //second sub element of MyArray var
msginfo( aX[1] ) //as 'campo2'
msgInfo( aX[2] ) //as 50
END
NEXT
.....


Regards,
Frances
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Variables

Post by James Bott »

Frances,

That may work but assigning value to PUBLICs inside a class is not good OOP practice. It kind of defeats the purpose of having a class. The data should be stored inside the class.

Regards,
James
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Variables

Post by lailton.webmaster »

THanks

I did how James Bott say me.

i created method GetEvent

:) to be perfect.

thanks :)
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: Variables

Post by fraxzi »

James Bott wrote:Frances,

That may work but assigning value to PUBLICs inside a class is not good OOP practice. It kind of defeats the purpose of having a class. The data should be stored inside the class.

Regards,
James

Thanks for the Idea. Best solution.
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Post Reply