Return single message after 5 command repetitions

1

I have a very simple code that checks if the user exists and returns a "Guaranteed Access" or "Access Denied" message.

The problem is that I need to call this Sub 5 times, which will return 5 MsgBox . How could I return a unique MsgBox with the 5 information saying 'User Y does not exist ...'?

Dim UserName
Dim UserPass    

Dim Mateus: Mateus = "Math"
Dim SenhaMateus: SenhaMateus ="123"

Dim Chris: Chris = "Chris99"
Dim SenhaChris: SenhaChris = "@#23"

Dim Samurai: Samurai = "Samuca"
Dim SenhaSamurai: SenhaSamurai = "CH1N4" 

Dim Kaguya: Kaguya = "Kaguy"
Dim SenhaKaguya: SenhaKaguya = "Naruto"

Dim Maroto: Maroto = "Marotinho"
Dim SenhaMaroto: SenhaMaroto = "78D99D"

Dim Jorge: Jorge = "Jorge"
Dim SenhaJorge: SenhaJorge = "Benjor"

Call ChecaUser(Mateus,SenhaMateus)
Call ChecaUser(Chris,SenhaChris)
Call ChecaUser(Samurai,SenhaSamurai)
Call ChecaUser(Kaguya,SenhaKaguya)
Call ChecaUser(Maroto,SenhaMaroto)
Call ChecaUser(Jorge,SenhaJorge)

Sub ChecaUser(UserName,UserPass)
if (UserName = "Jorge" and UserPass = "Benjor") then
MsgBox "Acesso Garantido"
Else
MsgBox  "Usuario não existe"
End if
End Sub
    
asked by anonymous 23.08.2018 / 14:53

1 answer

0
One of the ways is to create a variable to go by storing the names that are or are not valid through your ChecaUser method and then just show in MsgBox this variable. Ex:

Dim UserName
Dim UserPass

Dim InvalidUsers
Dim ValidUsers

Dim Mateus: Mateus = "Math"
Dim SenhaMateus: SenhaMateus ="123"

Dim Chris: Chris = "Chris99"
Dim SenhaChris: SenhaChris = "@#23"

Dim Samurai: Samurai = "Samuca"
Dim SenhaSamurai: SenhaSamurai = "CH1N4" 

Dim Kaguya: Kaguya = "Kaguy"
Dim SenhaKaguya: SenhaKaguya = "Naruto"

Dim Maroto: Maroto = "Marotinho"
Dim SenhaMaroto: SenhaMaroto = "78D99D"

Dim Jorge: Jorge = "Jorge"
Dim SenhaJorge: SenhaJorge = "Benjor"

Call ChecaUser(Mateus,SenhaMateus)
Call ChecaUser(Chris,SenhaChris)
Call ChecaUser(Samurai,SenhaSamurai)
Call ChecaUser(Kaguya,SenhaKaguya)
Call ChecaUser(Maroto,SenhaMaroto)
Call ChecaUser(Jorge,SenhaJorge)

If (Len(InvalidUsers) > 0) Then
    MsgBox "Usuário(s) inexistentes(s): " & InvalidUsers
End If

if (Len(ValidUsers) > 0) Then
     MsgBox "Usuário(s) válido(s): " & ValidUsers
End If    

Sub ChecaUser(UserName,UserPass)
    If (UserName = "Jorge" and UserPass = "Benjor") then
        ValidUsers = ValidUsers & UserName & " | "
    Else
        InvalidUsers = InvalidUsers & UserName & " | "
    End If
End Sub

Welcome to SOpt.

    
23.08.2018 / 16:51