FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Variables ( Solved )
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Variables ( Solved )
Posted: Sat Sep 05, 2009 04: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

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Variables
Posted: Sat Sep 05, 2009 08:21 PM

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

EMG

Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Variables
Posted: Sat Sep 05, 2009 08: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

Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Variables
Posted: Sat Sep 05, 2009 08: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:

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Variables
Posted: Sat Sep 05, 2009 08:57 PM
Code (fw): Select all Collapse
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
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Variables
Posted: 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

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Variables
Posted: Sun Sep 06, 2009 09:12 AM

I don't understand, sorry.

EMG

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Variables
Posted: Sun Sep 06, 2009 04:21 PM
In order to see data outside the class it has to be defined as data of the class.

Code (fw): Select all Collapse
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 (fw): Select all Collapse
// 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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Variables
Posted: Sun Sep 06, 2009 04: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 (fw): Select all Collapse
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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Variables
Posted: Sun Sep 06, 2009 06:04 PM

Good James

thanks

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Variables
Posted: Sun Sep 06, 2009 06: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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: Variables
Posted: 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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Variables
Posted: Tue Sep 08, 2009 01: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Variables
Posted: Tue Sep 08, 2009 03:09 AM

THanks

I did how James Bott say me.

i created method GetEvent

to be perfect.

thanks :)

:)

Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: Variables
Posted: Tue Sep 08, 2009 03: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