Solved

How do I accept a User Input from multiple forms using the same "Input form"?

Posted on 2007-11-25
5
176 Views
Last Modified: 2010-04-23
I want to have the user be able to click in any text box and when they do, a "User Input" keyboard will pop-up and they can Enter in a value (the program is going to be running on a touch screen with no keyboard, so on-screen keyboard is required). The value they enter will appear in a text box on the "User Input" form. When they hit accept, I want that value to be transfered to the textbox on the form in which they originally clicked in. I want the "User Input" keyboard to be able to be used multiple times throughout the program, and Ideally I just want to have to call a sub-routine or function when the user "Enters" the text box in which they want to type in.

I have tried this multiple ways and can't seem to get it working correctly. It kind of works, but not like I would hope.  I wish I still had my original code, but i have been tinkering with it; and It's pretty messed up at the moment. A basic concept of what i was doing is:

---------------------------------
Form1

txt_textbox (on Enter event)

txt_textbox.text = Module1.UserInput



-------------------------
Module1

Public UserInputValue as String

Public Function UserInput

frm_UserInput.Show
frm_Userinput.TopMost = True

UserInput = UserInputValue

UserInputValue = Nothing

End Function


-------------------------
frm_UserInput


btn_Accept.Click

UserInputValue = txt_Value.Text
txt_Value.Text =""
Me.Close()

--------------------------

This would work kind of. It was like it would sometimes work and others not. Especially the first textbox i would try would usually fail. The textboxes after that seemed to work just fine.

I know there is an easy way of doing what I'm trying to do, Any ideas/suggestions?
0
Comment
Question by:Gssc1414
  • 3
  • 2
5 Comments
 
LVL 3

Author Comment

by:Gssc1414
ID: 20347552
Or at least I would think there is an easy way, and im just thinking too much into it.
0
 
LVL 3

Author Comment

by:Gssc1414
ID: 20347691
Hmm... I think i may have figured out a good way of doing it.

1. Defined a "textbox" variable publically.

2. Set the variable to the texbox that i want text to appear in.

3. Set the Variables ".text" property when the user hits the accept button to what is in the UserInput text box.

Below is my code:

Is this a good/recommeneded way of doing it?
    Private Sub txt_CurrentBladeRPM_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_CurrentBladeRPM.Enter
 

        txtBox = Me.txt_CurrentBladeRPM

        frm_UserInput.Show()
 
 

    End Sub
 
 
 

Module SAW

    Public SupervisorLoginCache As Boolean

    Public LoggedInUser As String

    Public UserInputValue As String

    Public txtBox As TextBox
 

End Module
 
 

    Private Sub btn_Accept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Accept.Click
 

        txtBox.Text = txt_Value.Text

        txt_Value.Text = ""

        Me.Close()
 

    End Sub

Open in new window

0
 
LVL 11

Accepted Solution

by:
AkisC earned 500 total points
ID: 20350203
What I'd reccoment is...
 a global variable on the "UserInput" form
    Public pub_userInput as string=""

 Private Sub btn_Accept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Accept.Click
 
        txtBox.Text = txt_Value.Text
        pub_userInput= txt_Value.Text  '//assuming this is the value your user has typed.
        Me.Close()
 
    End Sub

And you can use it like (from any form)

    Public Function getFormInput() As String
        Dim myText As String = ""

        Dim f As New formUserInput  '// assuming formUserInput is the form name
        f.ShowDialog()
        myText = f.pub_userInput  '// myText has the value of the user input
        f.close()

        If myText Is DBNull.Value Then myText = ""
        Return myText
    End Function
0
 
LVL 3

Author Comment

by:Gssc1414
ID: 20352011
Is there any benefit to do it the way you posted it over the solution I came upon above, or is it just the way that your used to / makes most since to you?

Thanks for the response, I am just wondering if there are any benefits (performance/scalability ect.) to your method.
0
 
LVL 11

Expert Comment

by:AkisC
ID: 20352724
Whatever fits you.
I find the way I posted easier to debug in the future.

Take care
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now