Mand, thanks for describing your situation in more detail. ne detail is still not very clear:
i have a keypress(F3) that when press, another form(2) modal will appear
Did you program code iunto a keypress event that does start form2 or did you program ON KEY LABEL F3?
The suggestions I made would still work very well, too. Given you have modal forms Steve's alternative solution can also work, as you can return values from modal forms in their Unload event code, that's what VFPs help also describes here:
help said:
To return a value to the TO VarName clause in the DO FORM command, use the RETURN command in the Unload event. For more information, see DO FORM Command.
That refers to what Steve said in point 1 of his instructions to [tt]DO Form2
TO myResult[/tt]
The help describes that in the help topic of
DO FORM
help said:
TO VarName
Specifies a variable to hold a value returned from the form. If the variable doesn't exist, Visual FoxPro automatically creates it. Use the RETURN command in the Unload event procedure of the form to specify the return value. If you do not include a return value, the default value of true (.T.) is returned. If you use TO, the WindowType property of the form must be set to 1 (Modal). If the form Init event procedure returns .F., preventing the form from being instantiated, the Unload event procedure will not return a value to VarName.
As your form2 is modal, this works, but it has one disadvantage, the unload event has to run - as an event - not just by calling it, so what you can't do in your button of form2 doing calculations you then set form2.returnvalue <and call form2.unload, the unloiad has to happen, which means form2 has to be released to trigger this return mechanism. So the DO form2 ... TO Varname and RETURN value from form2.Unload is a mecahnism that only works when form2 is modal and you close it, as the modal state means you get back to the DO FORM line of the calling form. form2 also then does not set form1s textboxes 11 and 12 to whatever you need, form1 has to do that from the variable Varname or in Steves instructions the myResult variable. Which also means you can only return 1 value and to return two values for text11 andtext12, you need to put them both into one return value you can split.
So Steve's instructios work, but are limited to working only when form2 closes and make it harder to return two values. You can return an object that has two properties, you could return an array, you could return a string that has valuefortext11 + semicolon + valuefortext12, but if the types of them are numeric wouldn't work that simple. You see, it's complicated, too.
I wonder what step you didn't manage to do in the solution first proposed by Griff, and in more detail by me. I try to explain it in the multiple steps you need to do:
The idea as Griff sketched it that form2 knows how to address form1.text11 and form1.text12. Well, Griffs's checking whether type('form1.text11')='O' and he expects form1 to be a valid object reference. That's likely not the case. The way to be able to addess a form and its controls in code that is not inside that form is to have a reference, whcih first needs to be passed from form1 to form2 in the moment form1 calls form2, so that's where this begins:
1. form2 has to have the ability to receive an object reference to form1 in its init, so the form2 init event has to have this code:
Code:
LPARAMETERS toFormWithText11andtext12
Thisform.Addproperty('oFormWithText11andtext12',toFormWithText11andtext12)
2. form1 has to make the call to form2 like this:
Code:
DO Form2 [i]With Thisform[/i]
Instead of just DO FORM2.
So point2 has to be done in the keypress, that will fail if you mean an ON KEY LABEL f3, because then "THISFORM" won't be a valid form object reference. That's why it's so important we know what you mean by keypress. If you don't mean the keypress event of a text1 box in form1, than you're discombobulating us and yourself, too. I hope not.
These two parts of the changes already establish that form2 knows form1 and can act on it, for example it can do what you want and set the text11 and text12 texboxes.
Now the third change you need is within the "button that when click it includes computations". Thjat is part of form2, so it can access the property oFormWithText11andtext12 the init of form2 created and set to the passsed in reference. So in that calculation butt you can add to your code:
Code:
*... do calculations
Thisform.oFormWithText11andtext12.text11.value = calculationresult1
Thisform.oFormWithText11andtext12.text12.value = calculationresult2
Thisform.oFormWithText11andtext12.refresh()
Where you better know than us what to put in as calculationresult1 and calculationresult2.
But that's it. Now form2 could even do this multiple times during the calculations. For example if calculations are done in a scan..endscan loop you could update the text11 and text12 values multiple times, you don't
have to, but you
could.
In my previoius decription I said
myself said:
for example you add a form property "oCAllform"
This time I used Steve's idea of uaing Addproperty instead, but it would actually be better to add a property to the form when editing it - at design time - because that also means you already have it, also while you write code that uses it intellisense could help ou refer to it.
It's simple to add a property to a class or form when you modify it, that's why I didn't tell that in detail, when you edit form2 you have the menu "Form" and the first menu item of that is "New Property" to define a form property that can be used, as here to store a received value. And you have to store a received parameter in init, because after init all init parameters you don't store away anywhere are released and forgotton, but you need the form reference to form1 later in the calculatio button.
Mandy, just one more thing that you should never do, is just ssaying "i cant still get it". You also don't need to be sorry about that, it's not shameful you don't understand something we said to do, but undersstnad one thing: I wrote a long post with multiple sections, then please descibe what of it you don't get. It's also not helpful you star posts when you couldn't do what was recommended to you, as you mark something as a solution to future readers and you should not do this just by believing anything posted is surely right, but only after something actually helped you as non expert to get your problem solved. It's not just a marker for what you have read, either, it's a signal you give to other forum readers and it shouldn't be done just with assuming it will eventually help, it's feedback after it actually did help and you're not there yet, very obviously.
Chriss