I am trying to place a user defined number of imageboxs inside a picture box. I have tried creating an array of images:
and I can then redimension this array but if I try to load a picture: - for i = 0 to #
-
shapes(i).picture = loadpicture("...")
-
next
it gives an error message : "Object variable or With block variable not set"
Can someone help me out?
10 2531 zmbd 5,501
Expert Mod 4TB
It appears that you posted some generic code, such as "#" in the for loop and the (...) etc...
Please post the actual code.
Hello,
Thanks for your reply. The whole code is the following: - Private Sub ok_Click()
-
Dim test As Integer
-
-
If IsNumeric(Text1.Text) = True Then
-
If Text1.Text > 0 Then
-
test = Text1.Text
-
If Text1.Text - test = 0 Then
-
ReDim shapes.(Text1.Text)
-
For i = 0 To Text1.Text
-
-
shapes(i).Picture = LoadPicture("C:\Users\Neville Junkin\Desktop\School\Ananum\paint\Sans titre.bmp")
-
-
Next
-
Form1.Picture1.DrawWidth = 3
-
Form1.Picture1.ForeColor = vbRed
-
For i = 0 To 831
-
X1 = (Form1.Picture1.Width / 2) + (50 * node(i, 0))
-
Y1 = (Form1.Picture1.Height / 2) + (50 * node(i, 1))
-
Form1.Picture1.PSet (X1, Y1)
-
Next
-
Points.Hide
-
Else
-
MsgBox "Nombre des points doit ętre entier.", vbOKOnly, Error
-
End If
-
Else
-
MsgBox "Nombre des points doit ętre positive.", vbOKOnly, Error
-
End If
-
Else
-
MsgBox "Nombre des points doit ętre un integer.", vbOKOnly, Error
-
End If
-
End Sub
-
With shapes defined in a module as follows :
The code works until after I redimension shapes in line 8, when I try to add a picture to the image I recieve the error message "Object variable or With block variable not set". I have tried: -
Set shapes(i).Picture = LoadPicture("C:\Users\Neville Junkin\Desktop\School\Ananum\paint\Sans titre.bmp")
with "Set" and I recieve the same error.
I have also tried: - set Shapes(i) as New image
But the the option New Image is not available nor is picturebox which I tried after changing the variable to that type of object.
The value of the object is Nothing and I beleive that might be the problem but I can't seem to change it. Any help would be much appreciated.
zmbd 5,501
Expert Mod 4TB
Well....
- I don't see where you have declared any object in the first code block.
- I don't see where the array was declared to start with so I'm surprised the redim works without error; however, VB is a little different from VBA which I work with most of the time.
- Line8 looks odd to me; usually such would be written as ReDim Shapes(text.text) or even ReDim Preserve Shapes(text.text) so as to save anything already stored in the array; however, without the rest of your project I may have missed something... :)
The second code block you've posted has no code at all when expanded, you can go back into your post and edit it so as to post the code that might be helpful. Also, is this part of a class module?
Not sure whether it's your problem, as I've only had a quick glance at the code so far. But ReDim erases all existing entries in the array unless you add the keyword Preserve.
Oops, I see you already mentioned that zmbd.
However, I don't get what you mean about ReDim Preserve Shapes(text.text). This statement is used to change the size of the array, not the contents, so the text.text doesn't seem to have any relevance.
Your line - ReDim shapes.(Text1.Text)
Is not only invalid but not using Preserve everything in the array is wiped, which would lead to the error you're receiving. So change it to - ReDim Preserve Shapes (Text1.Text)
And it should work
zmbd 5,501
Expert Mod 4TB
@killer42
Look at lines 4, 5, and 6.
These give me the impression that "text.text" is the value entered into the form control named "text" as referenced by the "text" property. Really very unfourtunate to use a property name as a control name. Does that help with my suggestion to use ReDim Preserve Shapes(text.text) in that, as stated in OP, Nevj is trying to create an array to hold the information.
If your trying to create several controls and put them into an array do something like this;
add this code into your userform -
dim myImage as new image
-
redim myImage(someNumber)
-
for i = 0 to someNumber
-
set myImage(i) = Me.Controls.Add("forms.image.1", "image" & i, True)
-
... add more code here
-
next
-
I did this in VBA and i'm pretty sure it'll work in vb5 but not possitive.
@zmbd
Sorry, I should have read in more detail before replying.
zmbd 5,501
Expert Mod 4TB
@Killer:
No prob. Took me three reads to figure out what was going on... four lines of code to make sure the "text" control value is numeric and greater than zero... and then... we don't use the type declared variable in the rest of the code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Iain Miller |
last post by:
Now this shouldn't be hard but I've been struggling on the best way as to
how to do this one for a day or 3 so I thought I'd ask the assembled
company.....
I'm writing an application that tracks...
|
by: Patrick |
last post by:
I want to define a set of web-form templates in XML and render the equivalent
web-form with ASP.NET, then process any input server controls on the form.
Reading the XML file from Page_load is...
|
by: foo |
last post by:
Hello,
I have a form that I developed in a small simple project. The form runs
fine by itself. When I try to create a new form that inherits from this
form, the machine goes off in the weeds for...
|
by: Antuane |
last post by:
is it possible for me to create a base form class, & then some how configure
VB.NET,
so that when ever i create a new form, it will automatically be based on the
above form class.
i know i can...
|
by: Brian Cryer |
last post by:
I'm developing a website and for one of the pages I need to create a number
of coloured rectangles - its part of a legend and the user has control over
the actual colours used which is why I want...
|
by: Keith Patrick |
last post by:
I have an app with some graphics on the login page, but they won't show up
because the user is not authenticated, so ASP (2.0) is blocking access to
the files. I can expose the /Images path in...
|
by: ste |
last post by:
Hi there,
I'm just beginning to learn PHP and MySQL, but I'm finding it difficult! I
wondered if someone could help me out with a problem I'm having, or at least
point me in the right...
|
by: TanBrae |
last post by:
Hi all,
I'm fairly new to creating web pages. My current site has a form that has not been working for some time. I've had several people try to fix it, but it still won't work. (long story,...
|
by: cnotsharp |
last post by:
All..
I am new to .NET. I am trying to create a web page where I can display multiple images from a folder. If there are 5 pictures in the folder I want to create 5 image controls at runtime and...
|
by: MNNovice |
last post by:
I would like to display 3 different images on my form fMenu. I created three different images and placed them on the same spot of fMenu. Now I added this code but it is not working. What am I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |