Solved

OLEDrag & Drop from the desktop

Posted on 1998-10-29
7
158 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

863 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

18 Experts available now in Live!

Get 1:1 Help Now