Another Question, Go figure!!

Here is the problem:
[purple]Although .NET objects have a rich security architecture supporting them, it is necessary that the application take advantage of this information to implement the intended business rules that will support the application that the programmer is creating the object for. Using a word document, create a method called ChangeGrade that takes the value of the old grade as a string, the new grade as a string, the course number as a string, and semester taken as a string. If the person making the request has the role of Registrar, stored in a private value called strUserRole, then you should call the internal routine pvtChangeGrade with parameters sent to your method. If the user is not in the role of Registrar, then you should raise an exception. For the purpose of this assignment, the specific details of the routine pvtChangeGrade are not important, and all parameters are assumed to be identical to those passed to your method. [/purple]

I have created the "try" statement here:

[red]Try
strUserRole = "Registrar"
If strUserRole = "Registrar" Then
Call pvtChangeGrade()
Else
Throw New Exception
End If
Catch ex As Exception
MessageBox.Show("You do not have access to change the grades", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand)
End Try [/red]

But I am just not sure how to begin the method, Should it be something like this?

[blue]Public Sub ChangeGrade(byval oldgrade as string, byval newgrade as string, byval coursenumber as string, byval semester as string) handles changegrade [/blue]

???? Thanks in advance!
Lindsay

Comments

  • The beginning of the Sub looks good, but why have "handles changegrade"? It is an event handler? If it's just a sub that is called from your program, remove the "handles" part.

    The snippet of code you gave is a bit weird: you first make a Try to catch an expection. Then you check if a user has the priviledges to access this function and if he does not you raise an expection, which you then want to catch in the same function?! The point of Raising an Exception is to let the caller of the function know something went wrong. You don't need to catch the exception in your sub, because your sub already 'knows' if it worked or not!

    Change it to something like this:

    [code]
    Public Sub ChangeGrade(byval oldgrade as string, _
    byval newgrade as string, byval coursenumber as string, _
    byval semester as string)

    If strUserRole = "Registrar" Then
    Call pvtChangeGrade()
    Else
    Throw New Exception
    End If
    End Sub
    [/code]

    And place the Try statement where you call this function.

    [code]
    Sub AnySub()

    Try
    ChangeGrade(...)
    Catch ex As Exception
    MessageBox.Show("You do not have access to change " & _
    the grades", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand)
    End Try

    End Sub
    [/code]

    Greets...
    Richard

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion