Return single message after 5 repetitions of command

Asked

Viewed 40 times

2

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

The problem is I need to call this sub 5 times, which will return 5 Msgbox. How could I ever return a single Msgbox with the 5 information saying type '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

1 answer

1

One of the ways is to create a variable to store the names that are valid or not valid through your method ChecaUser and then just show on MsgBox that 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 the Sopt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.