Hi
On below code i am getting error 'Type Mismatch
Dim img As Image
Set img = LoadPicture("C:\image.jpg")
Thanks
Hi
On below code i am getting error 'Type Mismatch
Dim img As Image
Set img = LoadPicture("C:\image.jpg")
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sophia CarterPosted Mar 18, 2025, 11:01 AM
Hi there! It seems like you are encountering a 'Type Mismatch' error in your code snippet. The 'Type Mismatch' error typically occurs when there is an attempt to assign a value to a variable that is not compatible with the data type of the variable.
In your code snippet, you have declared 'img' as type 'Image', but the 'LoadPicture' function does not return an 'Image' data type. The 'LoadPicture' function returns a different type of data, often displayed directly on a form or control.
To resolve this error, you should use a compatible data type for storing the return value of the 'LoadPicture' function. One common approach is to use a variable of type 'StdPicture', which is a standard data type for visual basic representing images.
Here's an example of how you can adjust your code:
By changing the data type of 'img' to 'StdPicture', you should be able to avoid the 'Type Mismatch' error and successfully load the image from the specified file path.
I hope this explanation helps you understand and resolve the error. If you have any more questions or need further clarification, feel free to ask!