VB icon

Simple ole drag and drop

Email
Submitted on: 1/5/2015 1:58:00 PM
By: Stewart MacFarlane (from psc cd)  
Level: Beginner
User Rating: By 11 Users
Compatibility: VB 5.0, VB 6.0
Views: 2482
 
     This demonstrates a simple drag and drop of a file from windows explorer into a text box then grab the filename and path (this is part of the code im using to make a map install program for quake2)
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Simple ole drag and drop
' Description:This demonstrates a simple drag and drop of a file from windows explorer into a text box then grab the filename and path (this is part of the code im using to make a map install program for quake2)
' By: Stewart MacFarlane (from psc cd)
'
' Inputs:a dropped file from windows explorer
'
' Returns:incorrect file type
'
' Assumes:you must create a textbox called text1 and make sure its big enough so its not too fiddly to drop a file onto. also make sure for text1 oledragmode and oledrop mode in the properties are set to manual
'
' Side Effects:none known
'**************************************

Private Sub text1_OLEDragDrop(Data As DataObject, Effect As Long _
, Button As Integer, Shift As Integer, X As Single, Y As Single)
' Prepare a variable (numfiles) and pass the number of files
' dropped onto text1 to this variable
Dim numFiles As Integer
 numFiles = Data.Files.Count
' an example how to trap 1 file (can be modified to trap as many
' or as little amount by changing the > 1 to > {new value}) then
' display a message box telling user the maximum allowed file drops)
' then exit the sub
If numFiles > 1 Then 
	MsgBox "Only allows 1 file at a time in beta version! Sorry!"_
	,vbOKOnly, "Ooops beta version"
	Exit Sub
end if
' check the attributes of the file being dropped and see if it is a
' directory, if it is then warn user that only files are valid to drop
' and exit the sub
If (GetAttr(Data.Files(1))) = vbDirectory Then
 MsgBox "Sorry this beta version only allows files not directories to be installed"
 Exit Sub
End If
' check the file is the correct file type (using its extension)
' if not then warn user and exit the sub
If LCase(Right(Data.Files(1), 3)) <> LCase("bsp") Then
 MsgBox "This file is not a quake 2 map (*.bsp)"
 Exit Sub
End If
' tell user the drag and drop was succesful
MsgBox Data.Files(1) + " installed"
' code here to install file
' or do what ever you need
' data.files(1) is a string holding the path and filename of the dropped file
' using a for..next loop you can control multiple files dropped at once
' replacing the 1 with the for..next variable and using numfiles to find out
' the maximum for..next value
End Sub


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.