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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

object required error

Status
Not open for further replies.

mathprof

Programmer
Nov 8, 2000
37
US

code in form1 appears below
error: object required in set statement

project has: form1, module1 and usercontrol1

bmp$ = Graph.Picture
SavePicture Graph.Image, bmp$
Set UserControl1.Picture = bmp$

I omit word 'set' and get same error.

What gives?

Thanks

Mathprof
 
You probably want this. Assuming bmp$ is dimmed as an object.


Set bmp$ = Graph.Picture
SavePicture Graph.Image, bmp$
Set UserControl1.Picture = bmp$

If you don't use set in the first statement, then bmp$ isn't assigned an object, but rather just a long integer that's the pointer to the object.

Robert
 
Same object required error in same statement (Set UserControl1.Picture = bmp)


Private Sub Command1_Click()
Dim bmp As Object

xMin = xMin.Text
xMax = xMax.Text
Ymin = Ymin.Text
Ymax = Ymax.Text
Graph.Scale (xMin, Ymax)-(xMax, Ymin)
Graph.Line (xMin, 0)-(xMax, 0)
Graph.Line (0, Ymax)-(0, Ymin)
For H0 = xMin To xMax
For V0 = Ymin To Ymax
Graph.Circle (H0, V0), 0.1
Next V0
Next H0
Command1.Visible = False
xMin.Visible = False
xMax.Visible = False
Ymin.Visible = False
Ymax.Visible = False
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False

Set bmp = Graph.Picture
SavePicture Graph.Image, bmp
Set UserControl1.Picture = bmp


Unload Form1
End Sub
 
Firstly, I'm assuming that the control called 'Graph' is actually a Picturebox.

If so, then

Set bmp=Graph.Picture

will do assign an empty picture object because, contrary to what you might expect, the picturebox's picture property is empty. You either need to add:

Graph.Picture=Graph.Image

prior to the bmp call, or you need to change the bmp call to:

Set bmp=Graph.Image

Secondly, the second parameter of the savepicture call needs to be a String, not a picture object.

So, changing your code to something like:

Private Sub Command1_Click()
Dim bmpPicture As Picture
Dim strFile as string

strFile="myfilename"

xMin = xMin.Text
xMax = xMax.Text
Ymin = Ymin.Text
Ymax = Ymax.Text
Graph.Scale (xMin, Ymax)-(xMax, Ymin)
Graph.Line (xMin, 0)-(xMax, 0)
Graph.Line (0, Ymax)-(0, Ymin)
For H0 = xMin To xMax
For V0 = Ymin To Ymax
Graph.Circle (H0, V0), 0.1
Next V0
Next H0
Graph.Picture=Graph.Image
Command1.Visible = False
xMin.Visible = False
xMax.Visible = False
Ymin.Visible = False
Ymax.Visible = False
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False

Set bmpPicture = Graph.Picture
SavePicture Graph.Image, strFile
Set UserControl1.Picture = bmpPicture


Unload Form1
End Sub
 
I modified the code.
Form1 has 2 pictureboxes: graph and picture1
I also have UserControl1

This code copies what's in graph and puts it into picture1

If gives an 'object required' error on the statement.
Set UserControl1.Picture = LoadPicture(v$)

Is there a special way of calling a usercontrol from form1?


v$ = "weissman.bmp"
SavePicture Graph.Image, v$
Set Picture1.Picture = LoadPicture(v$)
Set UserControl1.Picture = LoadPicture(v$)
 
StrongM,
No luck with your code. Same 'object required' error in the same place.
Usually, when I get the obj req error it's because of a missing 'path' to the object.
Is there something special about referencing a usercontrol object from without?

 
Ah, yes, it's a usercontrol. Um - how are you exposing the usercontrol's Picture property? Through a public property?
 
I need your help here !
This is my first attempt with a usercontrol.
Please clue me in on just how I should expose the picture property. Step by step if you can.
 
I added the ActiveX control wizard and 'exposed' the usercontrol picture property.

What I need to know now is how do I code to get the picture in usercontrol1.picture?

 
I'm looking at the Set Picture sub, which was created by the wizard.

How can I call this sub from form1?

When I code set picture = v$ the picture appears on form1.

When I code set usercontrol1.picture = v$ I get that 'object required' error.

Public Property Set Picture(ByVal New_Picture As Picture)
Set UserControl.Picture = New_Picture
PropertyChanged "Picture"
End Property
 
That property code is in your usercontrol?

If so, what is the name of the picture control inside your usercontrol? That is what you want to set the picture to, not the usercontrol itself.

Why are you using loadpicture to put the picture in your controls when you already have it loaded in another control? That's not very efficent.

Robert
 
Okey dokey. That looks fine. The wizard has produced appropriate code to expose the usercontrol's Picture property. Now try the following:

Private Sub Command1_Click()
Dim bmpPicture As Picture
Dim strFile As String

strFile = "myfilename"

xMin = xMin.Text
xMax = xMax.Text
Ymin = Ymin.Text
Ymax = Ymax.Text
Graph.AutoRedraw = True
Graph.Scale (xMin, Ymax)-(xMax, Ymin)
Graph.Line (xMin, 0)-(xMax, 0)
Graph.Line (0, Ymax)-(0, Ymin)
For H0 = xMin To xMax
For V0 = Ymin To Ymax
Graph.Circle (H0, V0), 0.1
Next V0
Next H0
Graph.AutoRedraw = False
Graph.Refresh
Set Graph.Picture = Graph.Image
Command1.Visible = False
xMin.Visible = False
xMax.Visible = False
Ymin.Visible = False
Ymax.Visible = False
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False

Set bmpPicture = Graph.Picture
SavePicture Graph.Image, strFile
Set UserControl1.Picture = bmpPicture


Unload Form1
End Sub
 
StrongM: It still gives an 'object required' error
'=====================================================
TheVampire: The Property Code is in the UserControl
I want the picture in the control, not in a box in the control. Just like line 2 of the Set Pricture Property.

Public Property Set Picture(ByVal New_Picture As Picture)
Set UserControl.Picture = New_Picture
PropertyChanged "Picture"
End Property
'======================================================
Here's my current code.

v$ = "weissman.bmp"
SavePicture Graph.Image, v$
Set Picture1.Picture = Picture1.Picture
Set Picture = LoadPicture(v$)
'====================================================
I do not get an 'object req' error, because the picture is printed. However, it's in the form. I want it in usercontrol1.
 
OK, I see what you are trying to do now. I don't know why it's not working though.

If you switch

Set Picture = LoadPicture(v$)

with this:

Set UserControl.Picture = LoadPicture(v$)

Does it give you the error then?

Robert
 
Ok, I think we are getting to the point where you need to do a little research yourself, and read the help files about some of this stuff. You keep trying to modify the example code that has been provided back to some other form before we can get a view as to why such code doesn't work for you even though, for example, it works fine here.

It may be worth trying to walk before trying to run.
 
I thank you both, StrongM and The Vampire.

I bought a book that explains control creation. Although I've been creating exes for many years, activeXs are new to me and a little different.

Anyhow, from what I understand now, the form is used ONLY to test the control. After the test is over, the form is removed and then the project is compiled to make the ocx.

So,.... what I did, was to remove the form and put the command1 button (and the other objects) on the control. Now, of course, the picture is drawn on the control with errors.

Thanks again for all your time and concern.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top