Results 1 to 4 of 4

Thread: OOP in Visual Basic

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Afghanistan
    Posts
    9

    OOP in Visual Basic

    Hi friends.

    Recently i am working on a program which requires me to do some conversion from Java to Visual Basic. The area where i am facing problem is the object oriented programming part of visual basic. the problem is here:

    I have a class named IntegerArray. It has the following methods:

    1. Class_Int(size as long) 'Initialization
    2 AddItem(item as Variant) 'Adding an item to array
    3. SetItem(index as Long, item as Variant) ' Setting an item
    4. LastItem() 'gives the last item
    5. FirstItem() 'gives the first item
    6. noItem() 'returns the number of items

    The idea of IntegerArray class is like the Vector class in Java. It is actually an array to hold any type of data types and increase its size as the array is filled to its upper bound.

    The problem arrises here:

    Dim MainArray as IntegerArray
    MainArray.Class_Int 10 'initializing an array of size 10

    'Here i declare another array of type IntegerArray
    Dim Array1 as IntegerArray
    Dim Array2 as IntegerArray
    Array1.Class_Int(10)
    Array2.Class_Int(10)

    'Here is where i get error when i want to store Array1 and Array2 in MainArray.

    MainArray.AddItem Array1
    MainArray.AddItem Array2

    Here it gives me error and says that i cannot store Array1 and Array2 in the MainArray...

    Hope you understood my problem. Please help me as i need to rectify this bug soon... mail me at [email protected] if you need the source code for the class.

    Waiting for your responses...

    Thanks...

    Farshid

  2. #2
    New Member
    Join Date
    Aug 2001
    Location
    Louisiana
    Posts
    2
    It appears that you are trying to pass an object as a variant in the AddItem method. For this application you should use AddItem(item as Object).

    I do not believe that you are going to be able to use one method with both objects and basic data types.

    Hope this helps

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Afghanistan
    Posts
    9

    I agree with u!

    You are right... I already debugged the program and is now running smoothly... the problem that i faced was as you mentioned. In my program ITEM holds only objects so the in assigning ITEM in the array was where i faced the problem but now no more..


    thanks anyway...


  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Are you writing this in Vb6 or VB.net (7)? As far as i know vb.Net
    has dropped support for the variant data type and integer is now short. The way it is in Java.

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