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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use a custom form like an inputbox 1

Status
Not open for further replies.

victoryhighway2

Programmer
Jul 18, 2005
42
0
0
US
Hello,
I'm writing an application where I would like to open a custom form get a string value back and then close the form (sort of like the intrinsic inputbox). However, the reason that I would like to do this instead of using the inputbox is because I want to restrict both the characters that can be entered as well as the number of characters that can be entered. Here's what I've done so far:

In my main code, I've entered the following:
Code:
        Dim GetPassword As New frmPassword
        Dim password As String
        password = GetPassword.Password

In my frmPassword, I have the following code written for the password property:
Code:
    Public Property Password() As String

        Get
            Me.Show()
            Return m_Password
        End Get

        Set(ByVal value As String)
            m_Password = value
        End Set

    End Property

However, this isn't doing what I want. When the Get code is run, it runs the Form_Load code for frmPassword, but it doesn't wait to actually display the form. Instead, it automatically goes to the following line:
Code:
Return m_Password
Obviously, I'm doing something wrong. Does anyone have experience doing this in VB 2005?

Thanks in advance for your help.

Regards,
Geoffrey
 
Hi earthandfire,
That helps a bit. However, when I ran through that, I converted the System.Windows.Forms.DialogResult to a String and displayed it in a messagebox. It said that the result was "Cancel". I'm looking to get a six digit password back from the user. Is there a way that I could get .ShowDialog to return the value that the user is entering into the text box instead of a System.Windows.Forms.DialogResult?

Thanks,
Geoffrey
 
OK, I think I'm a bit closer. I now have written the following:

Code:
            If GetPassword.ShowDialog = Windows.Forms.DialogResult.OK Then
                password = GetPassword.Password
                MessageBox.Show(password)
            End If

However, what I need to do is find out how to return the value of Windows.Forms.DialogResult.OK when the user clicks on my OK button and Windows.Forms.DialogResult.Cancel when the user clicks on Cancel. How do I go about doing that?

Thanks,
Geoffrey
 
You could try something a little bit different.



in your frmPassword, do this

Code:
'btnOk click event
me.DialogResult = txtPassword.text

'btnCancel click event
me.DialogResult = dialogResult.Cancel



in the other form do

Code:
dim f as new frmPassword

dim result as dialogResult = f.showdialog

if not result.tostring = "Cancel" then

password = result.tostring 

end if



i haven't tested it but it should work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top