|
-
Nov 28th, 2005, 06:55 AM
#1
Thread Starter
Addicted Member
[RESOLVED] What is wrong with this code?
VB Code:
Dim imagearray(4) As Image
Set imagearray(0) = LoadPicture(App.Path & "\images\10.bmp")
VB6 claims the second line to be a "type mismatch". Any ideas?
-
Nov 28th, 2005, 07:41 AM
#2
Hyperactive Member
Re: What is wrong with this code?
Try this code
VB Code:
Private Sub Command1_Click()
Dim imagearray(4) As StdPicture
Set imagearray(0) = LoadPicture("C:\test.gif")
Image1.Picture = imagearray(0)
End Sub
When your dreams come true.
On error resume pulling hair out.
-
Nov 28th, 2005, 08:13 AM
#3
Frenzied Member
Re: What is wrong with this code?
Image is a 'property' used by StdPicture, picturebox (which is also a stdPic), etc. It's not a stand alone object.
However things like this would work but aren't really beneficial.
VB Code:
Dim ImgData as Image
Dim stdPic as stdPicture
stdPic = LoadPicture("C:\Test.gif")
set imgData = stdPic.Image
-
Nov 28th, 2005, 08:50 AM
#4
Thread Starter
Addicted Member
Re: What is wrong with this code?
Ok, that seems to be working, but now this:
VB Code:
Public Sub pict()
Dim i, imagearray(4)
card(0).Picture = imagearray(0)
End Sub
The second to last line causes an error of "object required". Any reason why?
-
Nov 28th, 2005, 09:35 AM
#5
Re: What is wrong with this code?
 Originally Posted by ajames
Ok, that seems to be working, but now this:
VB Code:
Public Sub pict()
Dim i, imagearray(4)
card(0).Picture = imagearray(0)
End Sub
The second to last line causes an error of "object required". Any reason why?
It's cause you declared it as a variant. And on top of that, you even forgot to load an image. Try this:
VB Code:
Public Sub pict()
Dim i As Long, imagearray(4) [b]As StdPicture[/b]
[b]Set imagearray(0) = LoadPicture("C:\test.gif")[/b]
card(0).Picture = imagearray(0)
End Sub
-
Nov 28th, 2005, 09:37 AM
#6
Frenzied Member
Re: What is wrong with this code?
try set? (set card(0).picture = etc)
Edit: Jacob rules
-
Nov 28th, 2005, 02:24 PM
#7
Thread Starter
Addicted Member
Re: What is wrong with this code?
that one seems to work (jacob), but i seem to have to dim "imagearray" in each sub I need to use it in. Is there a fix for that?
-
Nov 28th, 2005, 02:31 PM
#8
Frenzied Member
Re: What is wrong with this code?
make 'm public? (in other words, use Private or public above all your sub/function codes)
VB Code:
'1st line:
Option explicit
Public ImageArray() etc etc.
Private sub Form_Load etc. etc etc
-
Nov 28th, 2005, 02:39 PM
#9
Thread Starter
Addicted Member
Re: What is wrong with this code?
 Originally Posted by Devion
When I use this, it renders most of the code as "invalid outside procedures" (even "set" and "app.path")
-
Nov 28th, 2005, 02:43 PM
#10
Frenzied Member
Re: What is wrong with this code?
Err.. only the variables should be declared outside subs.. not code itself..
-
Nov 28th, 2005, 02:48 PM
#11
Thread Starter
Addicted Member
Re: What is wrong with this code?
I changed it to "Public Sub imageArray()", but now when i try to do "pic.picture=imageArray(0)" it says "invalid number of arguments or invalid property assignment".
I tried consulting help, but, as we all know, the microsoft help files never seem to tell you what to do, but instead tell you exactly what the error message says but with slightly altered words...
-
Nov 28th, 2005, 02:51 PM
#12
Frenzied Member
Re: What is wrong with this code?
I think you are looking at it from a weird angle ...
ImageArray() is an array.. not a sub.
VB Code:
Private i As Long, imagearray(4) As StdPicture
Public Sub pict()
Set imagearray(0) = LoadPicture("C:\test.gif")
card(0).Picture = imagearray(0)
End Sub
This would allow ImageArray to be public within the form or module (not outside) and also I would be public within the form or module.
If you would change private to public you could access those variables from different forms or modules.
-
Nov 28th, 2005, 03:03 PM
#13
Thread Starter
Addicted Member
Re: What is wrong with this code?
Thanks! It works! At last! rep points for you then
-
Nov 28th, 2005, 03:21 PM
#14
Re: [RESOLVED] What is wrong with this code?
One thing you should know about arrays. When you declare it like this
VB Code:
Private ImageArray() As StdPicture
It has no elements. 0 wouldn't even count either. So what you do is that after you declare it like so, you ReDim it within a sub or function:
VB Code:
Private ImageArray() As StdPicture
Private Sub Form_Activate()
ReDim ImageArray(100) As StdPicture
End Sub
Use ReDim Preserve if you want to keep the current values that are contained within an array, otherwise just using ReDim will erase them. This technique comes in handy if you have an unknown number of elements in your array.
-
Nov 28th, 2005, 03:25 PM
#15
Fanatic Member
Re: [RESOLVED] What is wrong with this code?
Thanks jacob for the redim preserve, never used that. I havent had to but that is a cool thing to know!
-
Nov 28th, 2005, 03:46 PM
#16
Frenzied Member
Re: [RESOLVED] What is wrong with this code?
You'll learn something everyday. oh! and thnx for the rep point. =)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|