# How to pass a value

- How to pass a value
  - The Program
  - The Code:
    - Fmain.class
    - Fsecond.class:

## The Program

Button1 opens a modal window, whose label shows the Text "modal".
Button2 opens a nonmodal window, whose label shows the Text "modeless".
(If you do not know the difference between modal and nonmodal windows have a look at How to open a modal Form.)
In each case, the Text is passed as a value.

## The Code:

### Fmain.class

    PRIVATE hNew AS Fsecond

    STATIC PUBLIC SUB Main()
      DIM hForm AS Form
      hForm = NEW Fmain
      hForm.show
    END

    PUBLIC SUB Button1_Click()

'if the second parameter is true, the new window should be modal

      ShowSecond("modal, " & TextBox1.Text, TRUE)
    END

    PUBLIC SUB Button2_Click()
      ShowSecond("modeless, " & TextBox1.Text, FALSE)
    END

    PRIVATE SUB ShowSecond(strVal AS String, bmode AS Boolean)
      IF bmode THEN

'here the constructor of the class Fsecond is used
'to receive the passed value.
'have a look at Fsecond's constructor _new()!

        hNew = NEW Fsecond(strVAl)
        hNew.ShowModal
      ELSE

'here a method of Fsecond is used to receive the
'passed value.

        hNew = NEW Fsecond
        hNew.UpdateField(strVal)
        hNew.Show
      ENDIF
    END

### Fsecond.class:

'the parameter has to be optional,
'otherwise it would be impossible to
'initialize an instance of this class
'without a parameter

    PUBLIC SUB _new(OPTIONAL X AS String)
      UpdateField(X)
    END

    PUBLIC SUB UpdateField(wort AS String)
      TextLabel1.Text=wort
    END