473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

creating images from code on a form in VB5

2
I am trying to place a user defined number of imageboxs inside a picture box. I have tried creating an array of images:

Expand|Select|Wrap|Line Numbers
  1. dim shapes() as image
and I can then redimension this array but if I try to load a picture:

Expand|Select|Wrap|Line Numbers
  1. for i = 0 to #
  2. shapes(i).picture = loadpicture("...")
  3. next
it gives an error message : "Object variable or With block variable not set"

Can someone help me out?
Oct 20 '12 #1
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.
Oct 20 '12 #2
PsychoCoder
465 Expert Mod 256MB
Moved to proper forum :)
Oct 20 '12 #3
Nevj
2
Hello,
Thanks for your reply. The whole code is the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ok_Click()
  2. Dim test As Integer
  3.  
  4. If IsNumeric(Text1.Text) = True Then
  5.     If Text1.Text > 0 Then
  6.         test = Text1.Text
  7.         If Text1.Text - test = 0 Then
  8.             ReDim shapes.(Text1.Text)
  9.             For i = 0 To Text1.Text
  10.  
  11.             shapes(i).Picture = LoadPicture("C:\Users\Neville Junkin\Desktop\School\Ananum\paint\Sans titre.bmp")
  12.  
  13.             Next
  14.             Form1.Picture1.DrawWidth = 3
  15.             Form1.Picture1.ForeColor = vbRed
  16.             For i = 0 To 831
  17.                 X1 = (Form1.Picture1.Width / 2) + (50 * node(i, 0))
  18.                 Y1 = (Form1.Picture1.Height / 2) + (50 * node(i, 1))
  19.                 Form1.Picture1.PSet (X1, Y1)
  20.             Next
  21.             Points.Hide
  22.         Else
  23.             MsgBox "Nombre des points doit ętre entier.", vbOKOnly, Error
  24.         End If
  25.     Else
  26.     MsgBox "Nombre des points doit ętre positive.", vbOKOnly, Error
  27.     End If
  28. Else
  29. MsgBox "Nombre des points doit ętre un integer.", vbOKOnly, Error
  30. End If
  31. End Sub
  32.  
With shapes defined in a module as follows :

Expand|Select|Wrap|Line Numbers
  1. Public shapes() as Image
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:
Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. 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.
Oct 21 '12 #4
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?
Oct 21 '12 #5
Killer42
8,435 Expert 8TB
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.
Oct 22 '12 #6
PsychoCoder
465 Expert Mod 256MB
Your line

Expand|Select|Wrap|Line Numbers
  1. 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

Expand|Select|Wrap|Line Numbers
  1. ReDim Preserve Shapes (Text1.Text)
And it should work
Oct 22 '12 #7
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.
Oct 22 '12 #8
If your trying to create several controls and put them into an array do something like this;

add this code into your userform
Expand|Select|Wrap|Line Numbers
  1. dim myImage as new image
  2. redim myImage(someNumber)
  3. for i = 0 to someNumber
  4.   set myImage(i) = Me.Controls.Add("forms.image.1", "image" & i, True)
  5.   ... add more code here
  6. next
  7.  
I did this in VBA and i'm pretty sure it'll work in vb5 but not possitive.
Oct 22 '12 #9
Killer42
8,435 Expert 8TB
@zmbd
Sorry, I should have read in more detail before replying.
Oct 23 '12 #10
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.
Oct 23 '12 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
2
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...
0
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...
5
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...
5
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...
1
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...
6
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...
5
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,...
1
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...
24
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.