Solved

How to get correct dialogresult from myform.showdialog

Posted on 2013-02-06
4
430 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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 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