Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public Functions not working as expected

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
In my visio ap I have a single form, which calls code from the default code module (module1)

I also have a class module, which has a load of public strings, and also a public subroutine, defined as below

Public ObjClass

Public sName As String
Public ..
..
..
..

Public Sub SetData(T As Shape)
sName = T.Name
..
..
end sub

I have an array of these ObjClass objects


Now in my code module (Module1) I can write and read directly to the sName variable like so

for i = 0 to 9
Array(i).sName = "Foo"
Next

But if I try to use

for i = 0 to 9
Array(i).SetData(myObject)
Next
I get an error message 424 - object required

T is defined as an object, then set to a Shape object

Now I can get round the problem in this instance by just filling in all the data by hand, but I don't see why I shouldn't be able to do this, and all I have tried has failed (changing the Type of T, changing the type of myObject), etc

Anyone got any other ideas before I try to re-engineer my solution ?
 
could you post more coding? Something doesnt seem right
 
ok, here is my declaration for my Class
Code:
Public ObjClass

Public sManufacturer As String
Public sProductNumber As String
Public sPartNumber As String
Public sAssetNumber As String
Public sProductDescription As String
Public sSerialNumber As String
Public sLocation As String
Public sRoom As String
Public sBuilding As String
Public sDepartment As String
Public sName As String
Public sIP As String

'Function to be called to fill an object with the Appropriate Data
Public Sub SetData(T As Shape)

sManufacturer = T.Section(visSectionProp).Row(0).Cell(visCustPropsValue).Formula
sProductNumber = T.Section(visSectionProp).Row(1).Cell(visCustPropsValue).Formula
sPartNumber = T.Section(visSectionProp).Row(2).Cell(visCustPropsValue).Formula
sAssetNumber = T.Section(visSectionProp).Row(4).Cell(visCustPropsValue).Formula
sProductDescription = T.Section(visSectionProp).Row(3).Cell(visCustPropsValue).Formula
sSerialNumber = T.Section(visSectionProp).Row(5).Cell(visCustPropsValue).Formula
sLocation = T.Section(visSectionProp).Row(6).Cell(visCustPropsValue).Formula
sRoom = T.Section(visSectionProp).Row(8).Cell(visCustPropsValue).Formula
sBuilding = T.Section(visSectionProp).Row(7).Cell(visCustPropsValue).Formula
sDepartment = T.Section(visSectionProp).Row(9).Cell(visCustPropsValue).Formula
sName = T.Name
If InStr(1, mString, &quot;ethernet&quot;, vbTextCompare) < 1 Then
    sIP = T.Section(visSectionProp).Row(10).Cell(visCustPropsValue).Formula
End If

End Sub

And here is the code that I want to call it

Code:
Dim ArrayCount As Integer
Dim MaxArray As Integer
Dim mShape As Object
Dim i, j As Integer
Dim mString As String

ArrayCount = 0
j = 0
'Make sure that the Array is the right size
MaxArray = myPage.Shapes.Count - 1
ReDim ObjectArray(MaxArray)
For i = 0 To (MaxArray)
    Set ObjectArray(i) = New ObjClass
Next

'Scan through all Objects, and add to the array if it is an object
'of interest

For i = 0 To MaxArray
        Set mShape = myPage.Shapes(i + 1)
        mString = mShape.Name

'Parse the Name, to see if the Object is of an Interested in type

   ObjectArray(j).SetData (mShape)
   ArrayCount = ArrayCount + 1
   j = j + 1
Next

As I am new to VB, my guess would be that I haven't declared the object correctly.

K
 
Pardon me if I am wrong cause its been way too long since i have dealt with classes in visual basic.But..
do not have

Public ObjClass

Name your class module ObjClass and take out that dim statment , than you can declare your array as ObjClass.Why not declare the array as objclass in the beginning.This way all its members will be of that type and there will be no need to declare each individual member of the array as type objclass.

dim objectarray as objclass

from there you will be able to reference all the variables of objclass.

Also unless you want to be able to access all those variables within your coding (outside of the class,and possibly change the variables) you can declare them as private cause the only functiion that uses them is the one within the class. When they are private only function within the class can use them.

Hope this helped, let me know if you need more help. Or if i possibly made a mistake.

Paul J.
 
oh also you must keep setdata as public if you are actually going to change the rest of them to private....sorry forgot to mention that.

Goodluck
 
Thanks for the replies, but still nothing works as expected :/

in VB, can I have an array of objects, and call a member function of a particular object in hte manner I am trying to, or ahve I declared my class wrong ?

 
did you name the actual class objclass......when you open up the project explorer does it say under class modules objclass??? Than you can declare the entire array as type objclass.
 
Yes, the module is called ObjClass, and the array is of type ObjClass, all I was trying to do earlier was to ensure that the array was empty.
The problem is nothing to do with the array, I have created a single instance of my class, and when I call teh Subroutine, I get the same error.
The problem is eithe rin the declaration of the class, the declaration of the Subroutine in the class, or the way I am calling the subroutine in my code

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top