Solved

OLEDrag & Drop from the desktop

Posted on 1998-10-29
7
160 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

810 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