[Gambas-user] overgive a value Nb.II

Benoît Minisini gambas at ...1...
Sat Jan 4 00:58:07 CET 2003


Le Vendredi 3 Janvier 2003 22:24, Jochen Georges a écrit :
> hello,
> after some gambasless days I will work on my problem again.
>
>
> there's a Form (Fmain) with two Buttons (btn_1 and btn_2).
> If one of the buttons is clicked, a new Form (Fsecond) opens.
> Fsecond shows only one Label, it should say something like this:
> " Button  <1 or 2 >   was clicked"
>
> how can I give a value to the other Form.
>
> thanks for any hint
>
> beste gruesse
> jochen
>
>

Hi Jochen,

If you display Form2 modal, you can use its contructor _new (welcome to the 
object-oriented programming). If you display Form2 modeless, you have to 
create a public method to update your label, and set the Persistent property.

in Form1:

PRIVATE hForm AS Form2

PUBLIC SUB Button1_Click()
  ShowForm2(1, TRUE)
END

PUBLIC SUB Button2_Click()
  ShowForm2(2, TRUE)
END

PRIVATE SUB ShowForm2(iVal AS Integer, bModal AS BOOLEAN)

  IF bModal THEN
    hForm = NEW Form2(iVal)
    hForm.ShowModal
  ELSE
    IF NOT hForm THEN hForm = NEW Form2
    hForm.UpdateLabel(iVal)
    hForm.Show
  ENDIF

END

in Form2:

PUBLIC SUB UpdateLabel(iVal AS Integer)
  Label1.Caption = CStr(iVal)
END

PUBLIC SUB _new(OPTIONAL iVal AS Integer)
  UpdateLabel(iVal)
END

Best regards,

-- 
Benoît Minisini
mailto:gambas at ...1...




More information about the User mailing list