PDA

Click to See Complete Forum and Search --> : OOP in Visual Basic


Farshid
Aug 16th, 2001, 10:44 PM
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 webkiddie@yahoo.com if you need the source code for the class.

Waiting for your responses...

Thanks...

Farshid

tjfse2000
Aug 22nd, 2001, 08:32 AM
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

Farshid
Aug 23rd, 2001, 03:08 AM
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...

:)

Dillinger4
Sep 10th, 2001, 11:12 PM
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.