Google Answers Logo
View Question
Q: VB6 coding ( Answered 5 out of 5 stars,   3 Comments )
Subject: VB6 coding
Category: Computers > Programming
Asked by: rbrian2-ga
List Price: $15.00
Posted: 20 Jan 2003 12:22 PST
Expires: 19 Feb 2003 12:22 PST
Question ID: 146049

I need a help with some code:  In our application if a User logged in
ONLY with two specific roles assigned on his user name (or either one
of those two) than give a warning.
In case Else if user has many roles including those two it is ok to
proceed with the rest of the logic.

Any help with the code would be appreciated.


Request for Question Clarification by hammer-ga on 21 Jan 2003 04:39 PST
Are you just looking for help on the logic, or do you also need to
determine what roles are assigned to a particular User?

- Hammer

Clarification of Question by rbrian2-ga on 21 Jan 2003 06:40 PST
Hi Hammer,

I need help with both.  These two roles are belong to another
application for login, but they must be created in our application
(both applications sharing the same logic for login). The purpose of
my request is - if acidentally the user was assigned ONLY those two
roles and tries to login in our application (instead of another
application), the warning message will be issued. If the user was
assigned other roles among with these two - it is Ok.

Request for Question Clarification by hammer-ga on 21 Jan 2003 07:21 PST
Then I need to know how we get "our application" to tell me what roles
have been assigned. I can write the logic for this, but I have no idea
where your app keeps these roles or how to ask for them, in order to
compare them to anything else.

- Hammer

Clarification of Question by rbrian2-ga on 21 Jan 2003 07:25 PST

I am going to send you some code and explanation.  Give me a little bit time.

Clarification of Question by rbrian2-ga on 21 Jan 2003 08:08 PST

Here is the some explanations and examples of logic.  If you need any
additional info, please ask.

We open recordsets (class module) and then do SELECT on tables in

I have included all declarations in one place, so don’t take me wrong

1. Login logic (example how we do checking for roles)
2. Further in another function there is a code, where we open
recordset, do select on table( similar to this).
    That function proceeds to open screens.  There I need to include
checking for those two roles
    (example:  If user has ONLY those 2 roles then
                        give a warning
                        exit application
                      Else   ‘proceed with the existing logic above
                        Set rsMain = New clsRS
                        On Error GoTo ErrorDB
                        rsMain.Query "SELECT * FROM tbl1…..”
                        If Not rsMain.EOF Then
                       End If
Private Sub cmdLogin_Click()
    Dim sRoles As String
    Dim sRole As String
    Dim rsTerminal As clsRS
    Dim rsUser As clsRS
    Dim rsRoles As clsRS
    Dim a as Integer
    Public gsTerminalRoles(100) As String
    Public gcTerminalRoles As New Collection
    Public gsUserRoles(100) As String
    Public gsRoles(100) As String
    Public gcUserRoles As New Collection  
    Dim iTerminalCnt, iRoleCnt
‘Checking terminal roles
Set rsTerminal = New clsRS
            rsTerminal.Query "select roles from tblRoles….”

If rsTerminal.RecordCount <= 0 Then
                MsgBox "No roles for this terminal”
                Unload Me
                Exit Sub
                sRoles = Trim(rsTerminal.FldValue("roles")) + ","
	    a = 1

                Do While Len(sRoles) > 0
                    b = InStr(sRoles, ",")
                    sRole = UCase(Trim(Left(sRoles, b - 1)))
                    sRoles = Trim(Mid(sRoles, b + 1))

                    gsTerminalRoles(a) = sRole
                    gcTerminalRoles.Add sRole, sRole
                    a = a + 1

                iTerminalCnt = a - 1
            End If
            Set rsTerminal = Nothing

	‘Checking granted roles
Set rsRoles = New clsRS
            rsRoles.Query "select granted_role from tblUser privs"

            If rsRoles.RecordCount > 0 Then

                Do While rsRoles.EOF <> True
                    If Left(rsRoles.FldValue("granted_Role"), 3) =
"CC_" Then
                        gsUserRoles(a) =
                        sRoles = rsRoles.FldValue("granted_Role")
rsRoles.FldValue("granted_Role"), rsRoles.FldValue("granted_Role")
                        a = a + 1
                    End If


                iUserCnt = a - 1
            End If

            Set rsRoles = Nothing

For Each v In gcTerminalRoles
                If Is_Member(v, gcUserRoles) Then
                    gsRoles(iRoleCnt) = gcUserRoles(v)
                    iRoleCnt = iRoleCnt + 1
                End If
            Next v

iRoleCnt = iRoleCnt - 1

   If iRoleCnt <= 0 Then
      MsgBox "Combined user and terminals do not allow
      Unload Me
      Exit Sub
   End If
Subject: Re: VB6 coding
Answered By: hammer-ga on 21 Jan 2003 14:30 PST
Rated:5 out of 5 stars

You're doing a bunch of trimming and parsing and moving things into
arrays, and I don't have the classes you're using to retrieve the
data, but I think I've managed to put together a code snippet that
will help you. Let me know if you need clarification.

Public Sub CheckRoles()
Dim rsRoles As clsRS 
Dim strCheckRole1 as String
Dim strCheckRole2 as String
Dim blnGotRequiredRole1 as Boolean
Dim blnGotRequiredRole2 as Boolean
Dim blnOkayToOpen as Boolean
Dim intRoleCnt as Integer

	' Initialize variables
	strCheckRole1 = "Admin"
	strCheckRole2 = "Manager"
	blnGotRequiredRole1 = False
	blnGotRequiredRole2 = False
	blnOkayToOpen = True
	intRoleCnt = 0

	‘Checking granted roles 
	Set rsRoles = New clsRS 
	rsRoles.Query "select granted_role from tblUser privs" 

	' Ensure that RecordCount is correctly populated
	If Not rsRoles.BOF And Not rsRoles.EOF Then
	End If
	intRoleCnt = rsRoles.RecordCount
	' We must have more than two roles to allow access
	If intRoleCnt > 2 Then 
		' Run through the granted roles checking 
		' for the two we must have
		Do Until rsRoles.EOF 
			If rsRoles.FldValue("granted_Role") = strCheckRole1 Then
				blnGotRequiredRole1 = True
			End If
			If rsRoles.FldValue("granted_Role") = strCheckRole2 Then
				blnGotRequiredRole2 = True
			End If
		' See if we found both required roles
		If (blnGotRequiredRole1 = False) Or (blnGotRequiredRole2 = False)
			blnOkayToOpen = False	
		End If
		blnOkayToOpen = False
	End If 

	' Clean up
	Set rsRoles = Nothing 

	' Final check to see if all conditions are met
	If blnOkayToOpen = False Then
		MsgBox "Terminating.”
		Unload Me 		
	End If
End Sub

As usual, none of the lines of code should wrap. I have hard coded in
the two roles to check for. You can substitute whatever roles you are
actually looking for. The comments should explain what each block is
doing. Again, let me know if you need something explained.

- Hammer
rbrian2-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
Thanks a lot, I just slightly modified your code to meet my needs,
other than that, it is very helpful and useful.  Thanks again.

Subject: Re: VB6 coding
From: cybergeek20001-ga on 20 Jan 2003 19:19 PST
You need to speak logically for a answer. 

If a user logs on with 1 or 2 roles they get a warning, else they
logon with 3 or more roles they can proceed? Let me know if thats what
your trying to say. Then ill give u the code .. If not specify what
your asking for....
Subject: Re: VB6 coding
From: rbrian2-ga on 21 Jan 2003 06:47 PST
Hi cybergeek20001,

I appologies for my confusing question.  I need to determine if the
user has assigned particular roles (their names). Our logic determines
the User name and then checking what roles are assigned to him. Based
on that you are getting different screens and different permissions. 
I need to include some checking for those two roles ( their names)
alone.  If user has assigned only those two roles, then warning and
exit application, if they (two roles) were assigned among with other
roles, it is ok to proceed. I hope I helped. Let me know.
Subject: Re: VB6 coding
From: rbrian2-ga on 22 Jan 2003 06:21 PST

Thanks, I will let you know in a little bit if I have any questions.


Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy