Solved

OLEDrag & Drop from the desktop

Posted on 1998-10-29
7
157 Views
Last Modified: 2010-04-30
I'm using the following function to OLEdrag and drop picture files(filenames) from the desktop or Windows Explorer into a picturebox:

Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
      Picture1.Picture = LoadPicture(Data.Files(1))
End Sub

When the file dropped isn't a valid picturebox format, I receive the Invalid Picture error. Can anyone complete my code so that any file with invalid format is rejected from being dropped?
0
Comment
Question by:slobstar
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:fguerreiro_inix
ID: 1442310
Use Data.GetFormat() function.

Hope this helps
Regards

0
 
LVL 1

Author Comment

by:slobstar
ID: 1442311
Thanks "fguerreiro_inix" but this was acctually the way my function really looked like:

Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Data.GetFormat(15) Then
      Picture1.Picture = LoadPicture(Data.Files(1))
   End If
End Sub

It doesn't matter if I use the GetFormat function or not, if I try to drop a .txt file it will still give me an error. Maybe I use the GetFormat function incorrect, please be more specific :)
0
 
LVL 15

Expert Comment

by:ameba
ID: 1442312
You must use error handling

On error goto droperr ' enable error handling

' now your function body
    If Data.GetFormat(15) Then
      Picture1.Picture = LoadPicture(Data.Files(1))
   End If

'  now add this:
   Exit Sub

droperr:
   ' report problem and Name of your file
   msgbox error,, "Cannot load " & Data.Files(1)
   Exit sub
End Sub
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:slobstar
ID: 1442313
Thanks "ameba" that works, but I want the "droperr" to just reject invalid files, without displaying any error message at all.
0
 
LVL 15

Expert Comment

by:ameba
ID: 1442314
I am not sure, it is interesting problem. Hm (thinking)...
Perhaps comment out or delete line with msgbox statement.
0
 
LVL 1

Author Comment

by:slobstar
ID: 1442315
Perfectomundo!!! Just put your comment in the "answer" and the points is yours. Thanks alot /Johan
0
 
LVL 15

Accepted Solution

by:
ameba earned 50 total points
ID: 1442316
You must use error handling!

On error goto droperr ' enable error handling

' now your function body
    If Data.GetFormat(15) Then
      Picture1.Picture = LoadPicture(Data.Files(1))
   End If

'  now add this:
   Exit Sub

droperr:
   ' report problem and Name of your file
   msgbox error,, "Cannot load " & Data.Files(1)
   Exit sub
End Sub

If you don't want to report error, comment out the msgbox statement.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now