Subject Re: Control passing back and fro in a form sub routine
From Mervyn Bick <invalid@invalid.invalid>
Date Tue, 25 Jul 2023 17:50:58 +0200
Newsgroups dbase.getting-started
Attachment(s) square.wfmsquare.prg

On 2023/07/25 16:53, Milind Nighojkar wrote:
> Milind Nighojkar Wrote:
>
>> Scenerio : from a form (say myform) control is branched to another program (say.T.prg)  to execute some code. How to come back to myform and go back to t,prg
>
> Additionaaly I want to use a value of  myform in T,prg and refresh myform and return back to T.prg


If you give us more details of what you want to do you'll get a better
answer.

Users usually interact with applications using forms.  Forms can execute
a program and use the output from the program as often as one likes but
it is more normal to leave focus on the form afterwards

There are MANY ways to do what you want and the attached example shows
one simple method.  Type a numeric value into the upper entryfield,
click the pushbutton and the square of the numeric value will be
displayed in the lower entryfield.   NO error checking is done so you
will get errors if don't use numeric values.

If you save a function in a .prg file of the same name as the function
you can execute the function from the Command Panel or another program.
  You can also execute the function from withing a form as if the
function was part of the form.

Once you have saved the files try the following in teh Command Panel
before you run the form.

?square(4)

Have a look at the pushbutton's onClick event handler.  This takes the
value from the upper entryfield, passes it to the function as a
parameter, executes the function and then assigns the value returned by
the function to the lower entryfield.

Mervyn.










** END HEADER -- do not remove this line
//
// Generated on 2023-07-25
//
parameter bModal
local f
f = new squareForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class squareForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 16.0
      left = 7.4286
      top = 1.6818
      width = 40.0
      text = ""
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      onGotFocus = class::ENTRYFIELD1_ONGOTFOCUS
      height = 1.0
      left = 16.0
      top = 4.0455
      width = 8.0
      value = ""
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 1.0909
      left = 13.0
      top = 7.4091
      width = 15.2857
      text = "Calculate square"
   endwith

   this.ENTRYFIELD2 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD2)
      height = 1.0
      left = 16.0
      top = 10.4545
      width = 8.0
      value = ""
   endwith


   function ENTRYFIELD1_onGotFocus()
      this.value = ''
      form.entryfield2.value = ''
      return

   function PUSHBUTTON1_onClick()
      //Because the default value of entryfield1 has been set to blank
      //dBASE sees any value entered as a character.  VAL() is used to
      //convert the character(s) to numeric values.
      form.entryfield2.value = square(val(form.entryfield1.value))
      return

   function form_onOpen()
      set procedure to square.prg
      return

endclass



function square(nVal)
  local retVal
  retVal = nVal*nVal
  return retVal