Variables ( Solved )

Variables ( Solved )

Postby lailton.webmaster » Sat Sep 05, 2009 4:46 pm

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.
lailton.webmaster
 
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Variables

Postby Enrico Maria Giordano » Sat Sep 05, 2009 8:21 pm

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

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

Re: Variables

Postby lailton.webmaster » Sat Sep 05, 2009 8:41 pm

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

Postby lailton.webmaster » Sat Sep 05, 2009 8:43 pm

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:
lailton.webmaster
 
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Variables

Postby Enrico Maria Giordano » Sat Sep 05, 2009 8:57 pm

Code: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Variables

Postby lailton.webmaster » Sat Sep 05, 2009 11:22 pm

DOnt have other code ?

that dont need add M-> VAr ?

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

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

Re: Variables

Postby Enrico Maria Giordano » Sun Sep 06, 2009 9:12 am

I don't understand, sorry.

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

Re: Variables

Postby James Bott » Sun Sep 06, 2009 4:21 pm

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

Code: Select all  Expand view
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  Expand view
// 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: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Variables

Postby James Bott » Sun Sep 06, 2009 4:28 pm

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  Expand view
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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Variables

Postby lailton.webmaster » Sun Sep 06, 2009 6:04 pm

Good James

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

Re: Variables

Postby James Bott » Sun Sep 06, 2009 6:15 pm

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Variables

Postby fraxzi » Tue Sep 08, 2009 12:57 am

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
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: Variables

Postby James Bott » Tue Sep 08, 2009 1:30 am

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Variables

Postby lailton.webmaster » Tue Sep 08, 2009 3:09 am

THanks

I did how James Bott say me.

i created method GetEvent

:) to be perfect.

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

Re: Variables

Postby fraxzi » Tue Sep 08, 2009 3:26 am

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
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 55 guests