Solved

Drag & Drop

Posted on 2001-06-21
9
228 Views
Last Modified: 2010-05-02
Hi All,

  I would like to drag a text file onto a text box.(content of text file).I wonder how..


Thank U very Much
w.







0
Comment
Question by:wzm
  • 5
  • 3
9 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6216738
Hi wzm, the easier way is use the Rich Text Box Control rather than Text Box Control:

Private Sub Form_Load()
    RichTextBox1.OLEDragMode = rtfOLEDragManual
    RichTextBox1.OLEDropMode = rtfOLEDropManual
End Sub

Private Sub RichTextBox1_OLEDragDrop(Data As RichTextLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    RichTextBox1.LoadFile Data.Files(1)
End Sub
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6216780
Hi!

Do this:

Download...
http://www.vb-helper.com/Howto/oledrop.zip
Description: Process files dragged onto a form (2K)

Use this code for the textbox instead.  The only problem is that you'll have to figure whatever 2 OLE dragdrop properties that you'll have to set.  I think it's Manual then Automatic.

Load the file upon getting the filepath.

That's it!

glass cookie : )

PS. I assume you know how to load a text file.
0
 

Author Comment

by:wzm
ID: 6217347
Glass Cookie - Nop I don't know (load a text file) - Please
share with me, Thanks
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:wzm
ID: 6217375
Glass Cookie - Nop I don't know (load a text file) - Please
share with me, Thanks
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6220965
OK... code coming up... (gimmie a few min...)
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6220971
Here's the code...

Dim F As Integer
F = FreeFile
Open "C:\MyFile.txt" For Input As #F
MyTextbox.Text = Input(LOF(1), 1)
Close F
End If

where "C:\MyFile.txt" is the filepath of your file, MyTextbox is the dstination textbox to stuff all the text to and you can replace it with some other control like Label1.Caption or just a string.

That's it!

glass cookie : )

PS. Happy programming : )
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6220989
Here's how the code should be:

Text1 > OLEDragMode set to 1 - Automatic, OLEDropmode set to 1 - Manual

Private Sub MyTextbox_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim txt As String
Dim fname As Variant

For Each fname In Data.Files
txt = txt & fname & vbCrLf
Next fname
'MsgBox txt '-Show filepath

Dim F As Integer
F = FreeFile
Open txt For Input As #F
MyTextbox.Text = Input(LOF(1), 1)
Close F
End If

' Indicate we did nothing with the files.
Effect = vbDropEffectNone

End Sub
0
 
LVL 8

Accepted Solution

by:
glass_cookie earned 50 total points
ID: 6220991
If you're accepting my ans, please try to give an 'A' as much as possible : )
0
 

Author Comment

by:wzm
ID: 6222968
You Deserved it Guru.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

792 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