VB6 claims the second line to be a "type mismatch". Any ideas?VB Code:
Dim imagearray(4) As Image Set imagearray(0) = LoadPicture(App.Path & "\images\10.bmp")
Printable View
VB6 claims the second line to be a "type mismatch". Any ideas?VB Code:
Dim imagearray(4) As Image Set imagearray(0) = LoadPicture(App.Path & "\images\10.bmp")
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
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
Ok, that seems to be working, but now this:
The second to last line causes an error of "object required". Any reason why?VB Code:
Public Sub pict() Dim i, imagearray(4) card(0).Picture = imagearray(0) End Sub
It's cause you declared it as a variant. And on top of that, you even forgot to load an image. Try this:Quote:
Originally Posted by ajames
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
try set? (set card(0).picture = etc)
Edit: Jacob rules ;)
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?
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
When I use this, it renders most of the code as "invalid outside procedures" (even "set" and "app.path")Quote:
Originally Posted by Devion
Err.. only the variables should be declared outside subs.. not code itself..
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...
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.
Thanks! It works! At last! rep points for you then
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. ;)
Thanks jacob for the redim preserve, never used that. I havent had to but that is a cool thing to know!
You'll learn something everyday. oh! and thnx for the rep point. =)