Solved

Drag & Drop

Posted on 2001-06-21
9
226 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
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.

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA saving file message display 5 67
using Access 8 68
MS Date Picker 64 bit 32 bit issue 12 55
Visual Studio 2005 text editor 10 39
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

803 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