update value of a variable outside a class in VB.NET

Posted by dpp on Stack Overflow See other posts from Stack Overflow or by dpp
Published on 2012-12-06T04:36:18Z Indexed on 2012/12/06 5:04 UTC
Read the original article Hit count: 171

Filed under:
|

I have a class derived from a Form, it has textbox for username and password and an OK button. I want it to behave like an InputBox so I can use it like this:

Dim Username As String = ""
Dim Password As String = ""
Dim authorization As New Authorization(Username, Password)
authorization.ShowDialog()
    'The user will click OK and I will expect the Username and Password to change based on the user input
MsgBox(Username & " " & Password)

The Authorization class:

Public Class Authorization
    Dim RefUsername As String
    Dim RefPassword As String

    Public Sub New(ByRef Username As String, ByRef Password As String)
        InitializeComponent()

        RefUsername = Username 'I'm trying to pass reference instead of value
        RefPassword = Password 'I'm trying to pass reference instead of value
    End Sub

    Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AuthorizeButton.Click
        RefUsername = Username.Text 'I'm trying to change value of variable outside the class
        RefPassword = Password.Text 'I'm trying to change value of variable outside the class
        Me.Close()

    End Sub
End Class

In short, I want to change the value of variables outside the class when the user clicks the OK, how am I going to accomplish that?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about pass-by-reference