Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a form like a function 1

Status
Not open for further replies.

HotMadras

Programmer
Apr 20, 2001
74
GB
I have a form with a set of buttons on it and a textbox. It is intended to act as a soft-keyboard to provide input facilities within an application intended for handheld devices. The form itself works fine. What I need to do is to be able to call it from any point in the program (wherever the user needs to input data), and return the value held in the textbox as a variable. So, essentially, I want to be able to call the keyboard form and take a result from it.

In other languages I'd create a function which asked the user for input (analogous to the form) and returned the value to where the call was made from, in the form: newVar=getInput() or something. I'm not entirely sure how I should go about this with VB.

Thanks
 
You can call Public Sub/Function inside a form. Have the
form Show itself modally and return answer. Allow for CANCEL.
[/code]
Set frm = New FormCalculate
strAnswer = frm.GetAnswer
Set frm = Nothing
if Len(StrAnwser) > 0 then
....
end if
'..In FormCalulate.........
' Form Level variable
' Set if Cancel button
Private mblnCancel as boolean
Public Function GetAnswer() as string
Dim strText as string
' Wait until HIDE (Do Not UNLOAD elsewhere) '
Me.Show vbModal
blnCancel = mblnCancel
strText = txtIn.Text
Unload Me
if blnCancel then strText = ""
GetAnswer = strText
End Function
[/code] Compare Code (Text)
Generate Sort in VB or VBScript
 
Have you tried InputBox()?

If it's no good, you'll be stuck with using a Global Variable that you set in the Form_Unload method.

Wil Mead
wmead@optonline.net

 
Hi,

Try to call a function from a simple module. You can use a global var.

The function will start the form. The form will set the global var (in case of cancel to - show the form modal and without control box)

After the calling line set up the function with the variable value)

You can set up an initial value of the variable amd in this case You don't have to care about the Cancel. You will have only one point where the variable can change it's value.

Tibi

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top