Results 1 to 2 of 2

Thread: Problem getting information from a property in a class [Resolved all by myself :) ]

  1. #1

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Resolved Problem getting information from a property in a class [Resolved all by myself :) ]

    I have a class which stores information on what to search for in active directory along with some information about how the UI should display the results.

    when I run a search I create an object and fill it with information based on what options are selected in the UI. The program will then store this object in a list view which acts as a previously search collection. I have a collection I created to store and get information from the object. This part was working fine until I added a new property to my class. Now when I attempt to run a previous search from the list box I get this error. "Cast from string "RegEx" to type 'Byte' is not valid. "

    This error is produce on this line....

    VB Code:
    1. Dim lookforme As New objLocate(SearchCollection.Item(intClicked).SearchFor, SearchCollection.Item(intClicked).SearchMachineUse, SearchCollection.Item(intClicked).SearchString, SearchCollection.Item(intClicked).SaveNameString)

    Here is the code from the function that the error happens on....

    VB Code:
    1. Private Sub RunSaveSearch()
    2.         'This function will get the currently selected item in the saved listview
    3.         'it will then perform the search based on what item was selected
    4.         Dim intClicked As Integer
    5.         intClicked = lstSaved.SelectedIndex
    6.         If intClicked = -1 Then
    7.             'No item was selected so exit the sub
    8.             Exit Sub
    9.         End If
    10.         If SearchCollection.Count = 0 Then
    11.             'There were no items in the search collection so don't do anything
    12.             'ERROR CONTROL
    13.         Else
    14.             'Set the searchfor textbox to the value of the search string
    15.             'in the object [Some search funtions rely on the information
    16.             'being in the textbox]
    17.             txtSearchFor.Text = SearchCollection.Item(intClicked).SearchString
    18.             'Dim lookforme As New objLocate(SearchCollection.Item(intClicked).SearchFor, SearchCollection.Item(intClicked).SearchMachineUse, SearchCollection.Item(intClicked).SearchString, SearchCollection.Item(intClicked).SearchRegEx, SearchCollection.Item(intClicked).SearchMachineModel)
    19.             Dim lookforme As New objLocate(SearchCollection.Item(intClicked).SearchFor, SearchCollection.Item(intClicked).SearchMachineUse, SearchCollection.Item(intClicked).SearchString, SearchCollection.Item(intClicked).SaveNameString)
    20.             Find(lookforme)
    21.         End If
    22.     End Sub

    Here is the code for the class that the object is created from.....

    VB Code:
    1. Public Class objLocate
    2.     'This class is used to create objects
    3.     'that will store information based
    4.     'on what the user wishes to search for
    5.     'this class is the core of the searching
    6.     'functions. All the searching functions will
    7.     'only work if a object created from this class
    8.     'is passed to them as an arguement
    9.  
    10.     Dim enumSearchFor As SearchFor 'An enumeration used to tell what the program
    11.     'the program should search for
    12.     Dim enumMachineUse As desMachineType 'An enumeration that tracks what type
    13.     'of machine to search for EX: workstation, Laptop, Pool Laptop ect.
    14.     Dim strSearchFor As String 'A string that holds the information usually
    15.     'stored in txtSearchFor  [The textbox where the user types a search in]
    16.     Dim bolRegEx As Boolean 'Boolean used to keep track if the search is
    17.     'going to use the regular expression to search
    18.     Dim strMachineType As String 'A string that holds information on what
    19.     'model machine to search for EX: GX110 , GX400 , GX270 ect.
    20.     Dim enumSaveName As enumSaveName 'A enumeration that holds information on what name
    21.     'to use for the saved search
    22.     Dim strSaveName As String
    23.     Public ReadOnly Property SaveNameString() As String
    24.         Get
    25.             Return ConvertSaveNameEnum(enumSaveName)
    26.         End Get
    27.     End Property
    28.     Public WriteOnly Property SaveName() As enumSaveName
    29.         Set(ByVal Value As enumSaveName)
    30.             enumSaveName = Value
    31.         End Set
    32.     End Property
    33.     Public Property SearchMachineModel() As String
    34.         Get
    35.             Return strMachineType
    36.  
    37.         End Get
    38.         Set(ByVal Value As String)
    39.             strMachineType = Value
    40.         End Set
    41.     End Property
    42.     Public Property SearchRegEx() As Boolean
    43.         Get
    44.             Return bolRegEx
    45.         End Get
    46.         Set(ByVal Value As Boolean)
    47.             bolRegEx = Value
    48.         End Set
    49.     End Property
    50.  
    51.     Public Property SearchFor() As SearchFor
    52.         Get
    53.             Return enumSearchFor
    54.  
    55.         End Get
    56.         Set(ByVal Value As SearchFor)
    57.             enumSearchFor = Value
    58.         End Set
    59.     End Property
    60.     Public Property SearchMachineUse() As desMachineType
    61.         Get
    62.             Return enumMachineUse
    63.         End Get
    64.         Set(ByVal Value As desMachineType)
    65.             enumMachineUse = Value
    66.         End Set
    67.     End Property
    68.     Public Property SearchString() As String
    69.         Get
    70.             Return strSearchFor
    71.         End Get
    72.         Set(ByVal Value As String)
    73.             strSearchFor = Value
    74.         End Set
    75.     End Property
    76.     Public Sub New(ByVal SearchFor As SearchFor, ByVal MachineUse As desMachineType, ByVal strSearchString As String, _
    77.     ByVal SaveNameEnum As enumSaveName, Optional ByVal bolReg As Boolean = True, Optional ByVal strType As String = "")
    78.         enumSearchFor = SearchFor
    79.         enumMachineUse = MachineUse
    80.         strSearchFor = strSearchString
    81.         bolRegEx = bolReg
    82.         strMachineType = strType
    83.         enumSaveName = SaveNameEnum
    84.     End Sub
    85.     Private Function ConvertSaveNameEnum(ByVal enumName As enumSaveName) As String
    86.         Select Case enumName
    87.             Case 1 : ConvertSaveNameEnum = "RegEx"
    88.             Case 2 : ConvertSaveNameEnum = "First Name"
    89.             Case 3 : ConvertSaveNameEnum = "Last Name"
    90.             Case 4 : ConvertSaveNameEnum = "Phone"
    91.             Case 5 : ConvertSaveNameEnum = "Location"
    92.             Case 6 : ConvertSaveNameEnum = "Model"
    93.             Case 7 : ConvertSaveNameEnum = "Dell Tag"
    94.             Case 8 : ConvertSaveNameEnum = "Useage"
    95.             Case 9 : ConvertSaveNameEnum = "Workstation"
    96.             Case 10 : ConvertSaveNameEnum = "HomeWorkstation"
    97.             Case 11 : ConvertSaveNameEnum = "Pool Laptop"
    98.             Case 12 : ConvertSaveNameEnum = "Laptop"
    99.             Case 13 : ConvertSaveNameEnum = "WoTo"
    100.             Case 14 : ConvertSaveNameEnum = "GX110"
    101.             Case 15 : ConvertSaveNameEnum = "GX400"
    102.             Case 16 : ConvertSaveNameEnum = "GX260"
    103.             Case 17 : ConvertSaveNameEnum = "GX270"
    104.             Case 18 : ConvertSaveNameEnum = "GX280"
    105.             Case 19 : ConvertSaveNameEnum = "SX280"
    106.             Case 20 : ConvertSaveNameEnum = "Machine"
    107.             Case 21 : ConvertSaveNameEnum = ""
    108.         End Select
    109.     End Function
    110. End Class

    Here is the code for the custom collection. [I don't think the error is coming from this class at all... just including it just in case...]

    VB Code:
    1. Class SavedSearchCollection
    2.     'This class was created to store the
    3.     'objects created from the objLocate Class
    4.     Inherits CollectionBase
    5.  
    6.     Default Public Property Item(ByVal Index As Integer) As objLocate
    7.         Get
    8.             If Index = -1 Then
    9.                 'Do nothing
    10.             Else
    11.                 Return CType(list.Item(Index), objLocate)
    12.             End If
    13.  
    14.         End Get
    15.         Set(ByVal Value As objLocate)
    16.             list.Item(Index) = Value
    17.         End Set
    18.     End Property
    19.  
    20.     Public Function Add(ByVal Item As objLocate) As Integer
    21.         Return list.Add(Item)
    22.     End Function
    23. End Class

    I am sure it's something dumb. The error actually happens on this part of the line in question
    SearchCollection.Item(intClicked).SaveNameString)

    the savenamestring is used to be the prefix for the seach type in the list view since there are many types of seachers htis program can do.

    The search collection correctly has the information in the object contained in it. I know this because i stepped through each line in the code and checked values.

    Thanks brothers
    Last edited by Porsche944; May 25th, 2005 at 08:24 PM.

  2. #2

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Talking Re: Problem getting information from a property in a class

    I am sorry I didn't notice that the constructor requires enumSavedName which is an enumeratino instead of a string. I change the property for SaveName to be both readable and writeable and changed it from SavedNameString to SavedName

    Now it works correctly.

    I feel stupid now

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