Results 1 to 5 of 5

Thread: inherited class-check were ive gone wrong

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    inherited class-check were ive gone wrong

    can someone check where i am going wrong?
    I have a form with a map on it. There are several doors. A person has to nevigate through the map. A person cannot be at location 1(represented by ID1 etc) and access door 6. They have to go through the certain doors. So basically they cannot just transport from one place to another.
    Attached is a picture of the map.
    I have two, classes, a door class and a location class.
    I have a feeling ive gone wrong some where but i dont know where. can some one help? Any help will be extremly appreciated.

    Public Class location
    Private id As Integer
    Private securityclearence As Integer

    Sub New()
    id = 1
    securityclearence = 1
    End Sub

    Sub New(ByVal ids1 As Integer, ByVal isecurityclearence As Integer)
    id = 1
    securityclearence = 0

    End Sub

    Public ReadOnly Property ids() As Integer
    Get
    Return id
    End Get
    End Property

    Public ReadOnly Property sc() As Integer
    Get
    Return securityclearence
    End Get
    End Property

    Public Function access() As Boolean
    If id = 1 Then
    securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    ElseIf id = 2 Then
    securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    ElseIf id = 3 Then
    securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    ElseIf id = 4 Then
    securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    ElseIf id = 5 Then
    securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    ElseIf id = 6 Then
    securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    ElseIf id = 7 Then
    securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    ElseIf id = 8 Then
    securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    ElseIf id = 9 Then
    securityclearence = 2 Or securityclearence = 1
    ElseIf id = 10 Then
    securityclearence = 2 Or securityclearence = 1
    End If
    End Function
    End Class


    Public Class Door
    Inherits location

    Protected ID1 As Integer
    Protected ID2 As Integer
    Private door As String

    Sub New()
    ID1 = 0
    ID2 = 1
    Door = "doora"
    End Sub

    Sub New(ByVal IDs1 As Integer, ByVal IDs2 As Integer, ByVal idoor As String)
    ID1 = IDs1
    ID2 = IDs2
    Door = idoor
    End Sub

    Public Property ids1() As Integer
    Get
    Return ID1
    End Get
    Set(ByVal Value As Integer)

    End Set
    End Property

    Public Property ids2() As Integer
    Get
    Return ID2
    End Get
    Set(ByVal Value As Integer)

    End Set
    End Property

    Public Property idoor() As String
    Get
    Return door
    End Get
    Set(ByVal Value As String)

    End Set
    End Property

    Public Function doorlocation() As Boolean
    If door = "DoorA" Then
    ID1 = 0
    ID2 = 1
    ElseIf door = "Door1" Then
    ID1 = 1
    ID2 = 2
    ElseIf door = "Door2" Then
    ID1 = 2
    ID2 = 3
    ElseIf door = "Door3" Then
    ID1 = 2
    ID2 = 4
    ElseIf door = "Door4" Then
    ID1 = 2
    ID2 = 5
    ElseIf door = "Door5" Then
    ID1 = 2
    ID2 = 6
    ElseIf door = "DoorC" Then
    ID1 = 2
    ID2 = 7
    ElseIf door = "Door6" Then
    ID1 = 8
    ID2 = 7
    ElseIf door = "Door7" Then
    ID1 = 9
    ID2 = 7
    ElseIf door = "Door8" Then
    ID1 = 10
    ID2 = 7
    ElseIf door = "DoorB" Then
    ID1 = 0
    ID2 = 7
    ElseIf door = "DoorD" Then
    ID1 = 7
    ID2 = 0
    End If
    End Function
    End Class


    this is the where the classes are called.
    Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
    Dim s1 As Door
    If s1.idoor <> "Door1" Then
    MsgBox("You cannot access this room. You are not in the correct region", MsgBoxStyle.Critical, "Door A")
    Else
    s1.ids1 = 2
    s1.ids2 = 1
    End If
    End Sub

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    First of All its alot easier to understand code formatted with [ vbcode ] [ /vbcode ] tags

    And If your not gonna use the Set statement of the propertys declare it readonly

    VB Code:
    1. Public Class location
    2.     Private id As Integer
    3.     Private securityclearence As Integer
    4.  
    5.     Sub New()
    6.         id = 1
    7.         securityclearence = 1
    8.     End Sub
    9.  
    10.     Sub New(ByVal ids1 As Integer, ByVal isecurityclearence As Integer)
    11.         id = 1
    12.         securityclearence = 0
    13.  
    14.     End Sub
    15.  
    16.     Public ReadOnly Property ids() As Integer
    17.         Get
    18.             Return id
    19.         End Get
    20.     End Property
    21.  
    22.     Public ReadOnly Property sc() As Integer
    23.         Get
    24.             Return securityclearence
    25.         End Get
    26.     End Property
    27.  
    28.     Public Function access() As Boolean
    29.         If id = 1 Then
    30.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    31.         ElseIf id = 2 Then
    32.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    33.         ElseIf id = 3 Then
    34.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    35.         ElseIf id = 4 Then
    36.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    37.         ElseIf id = 5 Then
    38.             securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    39.         ElseIf id = 6 Then
    40.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    41.         ElseIf id = 7 Then
    42.             securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    43.         ElseIf id = 8 Then
    44.             securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    45.         ElseIf id = 9 Then
    46.             securityclearence = 2 Or securityclearence = 1
    47.         ElseIf id = 10 Then
    48.             securityclearence = 2 Or securityclearence = 1
    49.         End If
    50.     End Function
    51. End Class
    52.  
    53.  
    54. Public Class Door
    55.     Inherits location
    56.  
    57.     Protected ID1 As Integer
    58.     Protected ID2 As Integer
    59.     Private door As String
    60.  
    61.     Sub New()
    62.         ID1 = 0
    63.         ID2 = 1
    64.         Door = "doora"
    65.     End Sub
    66.  
    67.     Sub New(ByVal IDs1 As Integer, ByVal IDs2 As Integer, ByVal idoor As String)
    68.         ID1 = IDs1
    69.         ID2 = IDs2
    70.         Door = idoor
    71.     End Sub
    72.  
    73.     Public Readonl Property ids1() As Integer
    74.         Get
    75.             Return ID1
    76.         End Get
    77.     End Property
    78.  
    79.     Public ReadOnly Property ids2() As Integer
    80.         Get
    81.             Return ID2
    82.         End Get
    83.         Set(ByVal Value As Integer)
    84.  
    85.         End Set
    86.     End Property
    87.  
    88.     Public ReadOnly Property idoor() As String
    89.         Get
    90.             Return door
    91.         End Get
    92.     End Property
    93.  
    94.     Public Function doorlocation() As Boolean
    95.         If door = "DoorA" Then
    96.             ID1 = 0
    97.             ID2 = 1
    98.         ElseIf door = "Door1" Then
    99.             ID1 = 1
    100.             ID2 = 2
    101.         ElseIf door = "Door2" Then
    102.             ID1 = 2
    103.             ID2 = 3
    104.         ElseIf door = "Door3" Then
    105.             ID1 = 2
    106.             ID2 = 4
    107.         ElseIf door = "Door4" Then
    108.             ID1 = 2
    109.             ID2 = 5
    110.         ElseIf door = "Door5" Then
    111.             ID1 = 2
    112.             ID2 = 6
    113.         ElseIf door = "DoorC" Then
    114.             ID1 = 2
    115.             ID2 = 7
    116.         ElseIf door = "Door6" Then
    117.             ID1 = 8
    118.             ID2 = 7
    119.         ElseIf door = "Door7" Then
    120.             ID1 = 9
    121.             ID2 = 7
    122.         ElseIf door = "Door8" Then
    123.             ID1 = 10
    124.             ID2 = 7
    125.         ElseIf door = "DoorB" Then
    126.             ID1 = 0
    127.             ID2 = 7
    128.         ElseIf door = "DoorD" Then
    129.             ID1 = 7
    130.             ID2 = 0
    131.         End If
    132.     End Function
    133. End Class

    VB Code:
    1. 'this is the where the classes are called.
    2. Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
    3.     Dim s1 As Door
    4.     If s1.idoor <> "Door1" Then
    5.         MsgBox("You cannot access this room. You are not in the correct region", MsgBoxStyle.Critical, "Door A")
    6.     Else
    7.         s1.ids1 = 2
    8.         s1.ids2 = 1
    9.     End If
    10. End Sub
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    VB Code:
    1. Public Function access() As Boolean
    2.         If id = 1 Then
    3.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    4.         ElseIf id = 2 Then
    5.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    6.         ElseIf id = 3 Then
    7.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    8.         ElseIf id = 4 Then
    9.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    10.         ElseIf id = 5 Then
    11.             securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    12.         ElseIf id = 6 Then
    13.             securityclearence = 5 Or securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    14.         ElseIf id = 7 Then
    15.             securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    16.         ElseIf id = 8 Then
    17.             securityclearence = 4 Or securityclearence = 3 Or securityclearence = 2 Or securityclearence = 1
    18.         ElseIf id = 9 Then
    19.             securityclearence = 2 Or securityclearence = 1
    20.         ElseIf id = 10 Then
    21.             securityclearence = 2 Or securityclearence = 1
    22.         End If
    23.     End Function

    after you test the conditions you to not return a wither the player has access or not so it defaults to false

    Test out this code and tell me if it solves ur problem

    VB Code:
    1. 'it shorter but it should do what u wanted
    2.     Public Function Acceess() As Boolean
    3.         If (securityclearence = 1) Or (securityclearence = 2) Then
    4.             'They have access to everything
    5.             Return True
    6.         End If
    7.         If (securityclearence = 3) Or (securityclearence = 4) And (Not (id = 10) Or Not (id = 9)) Then
    8.             'has access to everthing except 10 + 9
    9.             Return True
    10.         End If
    11.         If (securityclearence = 5) And (Not (id = 5) Or (id > 6)) Then
    12.             Return True
    13.         End If
    14.     End Function
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    I appreciate the quick response. I have to go to work but i'll be sure to check out the code as soon as i return. The above code is were i was a bit 'iffy' on. I wasn't sure if i was calling the classes correctly. Is the above code ok? Each label represents a door. I'm espcecially a bit weary on the line:

    If s1.idoor <> "Door1" Then

    Is this the correct way to call the classes or is there a better method?

    VB Code:
    1. 'this is the where the classes are called.
    2. Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
    3.     Dim s1 As Door
    4.     If s1.idoor <> "Door1" Then
    5.         MsgBox("You cannot access this room. You are not in the correct region", MsgBoxStyle.Critical, "Door A")
    6.     Else
    7.         s1.ids1 = 2
    8.         s1.ids2 = 1
    9.     End If
    10. End Sub

  5. #5
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    your right it wont work.

    you should use:

    VB Code:
    1. Dim d1 as New Door()
    2. 'or
    3. Dim d1 as  New Door(2,1, "Door Name")

    to create a door object but I dont think you are doing this right but i need more of the source to understand how you are trying to do this.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width