sayth
sayth

Reputation: 7048

VB.Net retrieve string values from separate Module

How do I reference the values in a textbox in a separate VB module.

In my login.aspx.vb module I have

Public Class login
    Inherits System.Web.UI.Page

    Private _inlineAssignHelper As String

    Protected Sub LoginButton(ByVal sender As Object, 
                              ByVal e As System.EventArgs) Handles Button1.Click

        Dim UserLogin As New String("")
        Dim UserPass As New String("")

        UserLogin = username.Text
        UserPass = password.Text

        Dim SecurityUser As New SecurityUser(UserLogin)
        Dim SecurityPass As New SecurityPass(UserPass)
    End Sub

End Class

Now in my separate Security.vb module I want to check that the values aren't null and send them to the database but I can't appear to reference the values correctly to do this. Can anyone help?

Public Sub securityCheck(UserLogin, UserPass)

    Dim securityCheck As Array()
    ' Dim User As String = TheNRLPredator.login.LoginButton(UserLogin)

    If (String.IsNullOrEmpty(TheNRLPredator.login.(UserLogin) _
       && String.IsNullOrEmpty(TheNRLPredator.login.(UserLogin) =True) Then
        MsgBox("You need to enter a Username and Password")
    Else
        'send to database to check.
    End If

End Sub

Upvotes: 0

Views: 694

Answers (1)

Kjartan
Kjartan

Reputation: 19151

Is the securityCheck sub in a class? I would change the code a little, like this:

Public Class SecurityChecker

    ' Note the Shared. PS: I would also rename "securityCheck()" to "Validate()":
    Public Shared Function Validate(UserLogin, UserPass) As Bool

         dim isValid as Bool = true

         ' Also, I think I would simplify this:
         If (String.IsNullOrEmpty(UserLogin) _
             OrElse String.IsNullOrEmpty(UserPass) Then
               isValid = false                   
         End If            

         ' Let the caller know if validation succeeded:
         return isValid 
    End Sub
End Class

Now reference it using class-name where you want to use this, and call the database logic separately from the validation:

Protected Sub LoginButton(ByVal sender As Object, 
                          ByVal e As System.EventArgs) Handles Button1.Click

    if ( SecurityChecker.Validate(username, password) ) Then
         ' Call metod for storing to DB here
    Else
        MsgBox("You need to enter a Username and Password")
    End If

End Sub

Upvotes: 1

Related Questions