Hi
On below code i am getting error 'Type Mismatch
Code
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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sophia CarterRank #4,018 · 371 reputationPosted Mar 18, 2025, 7:01 AM EDT
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:
Dim img As StdPicture Set img = LoadPicture("C:\image.jpg")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!