2009/8/30 Ariel Constenla-Haile <[email protected]>:
> Hello Johnny,
>
> On Sunday 30 August 2009, 12:57, Johnny Rosenberg wrote:
>> I have a dialogue with some buttons and boxes. Eight of the buttons
>> does basically the same thing, but to different objects, so I need to
>> write 8 macros for these, one for each button, since I can not call a
>> subroutine with parameters from a command button.
>
> but you get an event object, see bellow...
>
>> My solution right now is to let the buttons call each own subroutine,
>> for example the first button calls:
>> Sub MySub1
>>    MySub(1)
>> End Sub
>>
>> So all the subroutines call MySub, but with different parameters, and
>> of course MySub looks something like this:
>> Sub MySub(X As Integer)
>>    Dim CtlName As String
>>    Dim Ctl As Object
>>    Ctl=Dlg.getControl("ComboBox" + LTrim(Str(X)))
>>    ' Well, then it's doing stuff with Ctl and so on…
>> End Sub
>>
>> Of the easiest way would to assign the first button to MySub(1) and so
>> on, making 8 subroutines unnecessary, but no matter what I try it
>> doesn't seem like this is possible.
>> Another solution would be to let all the 8 buttons call this one and
>> only subroutine:
>> Sub MySub
>>    Dim X As String
>>    X=Blahblah ' The name of the last button that was pressed…
>>    Select Case X
>>    Case "CommandButton1"
>>       'Do something
>>    'And so on
>>    End Select
>> End Sub
>>
>> Hm… when thinking about it, this solution is maybe not that much
>> convenient after all…
>>
>> Suggestions?
>
>
> assign all the buttons to the same macro:
>
> Sub BtnPressed(oEvent as Object)
>        Dim oControl as Object
>        Dim oModel as Object
>
>        oControl = oEvent.Source
>        oModel = oControl.getModel()
>
> End Sub
>
>
> In this way, you can access the control and its model, and check what button
> was pressed (by checking the control's model name, which is unique; or by
> setting an action command to each button; etc. etc. use your imagination)

Thanks! I think this (and the other reply I got) will help me a lot.

Johnny Rosenberg

>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to