Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get correct dialogresult from myform.showdialog

Posted on 2013-02-06
4
Medium Priority
?
452 Views
Last Modified: 2013-02-06
I have a main form that I load, and the first thing it does is load another login form.  I need to get the result of the form, which I am able to do, but if they have the wrong password, I want to ask them to try again or cancel.  Its that dialogresult I don't seem to to catch.  Here is the load function of the main form.

 Private Sub frmMaintenance_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myLogin As New frmSetupLogin
        If myLogin.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim mVersion As String = Application.ProductVersion.ToString
            Dim myUtil As New InspectionSetup
            mSetupMarkUp = myUtil.GetSetupMarkup
            Me.Text = Me.Text & Space(10) & "Version  " & mVersion
        Else
            Dim i As Integer
            i = MsgBox("Invalid password", MsgBoxStyle.RetryCancel)
            If i = vbCancel Then
                End
            Else
                myLogin.ShowDialog()
                ' myLogin.ShowDialog()
            End If
        End If
    End Sub

Here is the code in the login form click event

 Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If txtPassword.Text = "xxxxxx" Then
            Me.DialogResult = DialogResult.OK
        Else
            Me.DialogResult = Windows.Forms.DialogResult.No

        End If
    End Sub

thanks in advance.
0
Comment
Question by:mgmhicks
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:appari
ID: 38862178
code looks fine to me, only modification i suggest is frmMaintenance_Load event.
change your existing frmMaintenance_Load event to
 Private Sub frmMaintenance_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myLogin As New frmSetupLogin
        While True


            If myLogin.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim mVersion As String = Application.ProductVersion.ToString
                Me.Text = Me.Text & Space(10) & "Version  " & mVersion
                Exit While
            Else
                Dim i As Integer
                i = MsgBox("Invalid password", MsgBoxStyle.RetryCancel)
                If i = vbCancel Then
                    End
                Else
                    'myLogin.ShowDialog()
                    ' myLogin.ShowDialog()
                End If
            End If
        End While

    End Sub

Open in new window

0
 

Author Comment

by:mgmhicks
ID: 38862238
thanks appari, that is much better, but if I click nothing in password, it comes back and asks to retry, that's good.  But when I then enter the correct password, I have to click ok 2 times before it takes, then goes into the program.  This is what the code looks like now.

Dim myLogin As New frmSetupLogin

        While True
            If myLogin.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim mVersion As String = Application.ProductVersion.ToString
                Dim myUtil As New InspectionSetup
                mSetupMarkUp = myUtil.GetSetupMarkup
                Me.Text = Me.Text & Space(10) & "Version  " & mVersion
                Exit While
            Else
                Dim i As Integer
                i = MsgBox("Invalid password", MsgBoxStyle.RetryCancel)
                If i = vbCancel Then
                    End
                Else
                    myLogin.ShowDialog()
                    ' myLogin.ShowDialog()
                End If
            End If
        End While
0
 
LVL 39

Accepted Solution

by:
appari earned 2000 total points
ID: 38862276
remove the  
myLogin.ShowDialog()
in the else part
Dim myLogin As New frmSetupLogin

        While True
            If myLogin.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim mVersion As String = Application.ProductVersion.ToString
                Dim myUtil As New InspectionSetup
                mSetupMarkUp = myUtil.GetSetupMarkup
                Me.Text = Me.Text & Space(10) & "Version  " & mVersion
                Exit While
            Else
                Dim i As Integer
                i = MsgBox("Invalid password", MsgBoxStyle.RetryCancel)
                If i = vbCancel Then
                    End
                End If
            End If
        End While 

Open in new window

0
 

Author Closing Comment

by:mgmhicks
ID: 38862301
That did it.  Thanks a lot.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

886 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