Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OLEDrag & Drop from the desktop

Posted on 1998-10-29
7
Medium Priority
?
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 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