Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag Drop to a desktop icon 1

Status
Not open for further replies.

MattSTech

Programmer
Joined
Apr 10, 2003
Messages
333
Location
US
Hello all,

Having an issue with dragging a text file from a location on the desktop to a text editing app on the desktop. I have code in the load statement to handle associated files double clicked that are opened with this app. The error is a "referenced memory can not be read" error, it opens the program but crashes immediately. Is there a different event that is fired other than the form_load when a file is dropped on an executable or shortcut to executable?
Thanks much
Matt
 

That depends upon how your program is designed. If you have a sub main that is where the program starts. I am not sure of what may be wrong but I can give a guess, and that guess would be you trying to tell the edit control (text rtb) to show text before it is loaded. Its just a guess.

Good Luck

 
The program does in fact use a sub main as the load procedure. The code is posted below. I can't imagine that it would load any differently when an associated file is double clicked than when that same associated file is dropped on the exe, however it obviously does. I will try to move the FireOpener sub ahead in the lineup a bit more. Thanks for the help.

Sub Main()
On Error GoTo ErrHandler
If App.PrevInstance = True Then End

Load frmSplash
frmSplash.Show
'frmSplash loads info from database
Load mdiMain
mdiMain.Show

End Sub

Private Sub MDIForm_Load()

ChDir App.Path
ReDim Document(1)'Initializes the Document Form Array, Shows the first Document
ReDim FState(1)
Document(1).Tag = 1

FireOpener
FState(1).Dirty = False

End Sub

Sub FireOpener()
Dim cmd as String, StrBuff as String
Dim tFile as Long

cmd = Command$

If Len(Trim(cmd)) <= 0 Then
Exit Sub
Else
tFile = FreeFile
Open cmd for Binary Access Read As #tFile
StrBuff = Space(LOF(tFile))
Get #tFile, , StrBuff
Close #tFile
Document(1).txtText.Text = StrBuff
Document(1).Caption = cmd
StrBuff = ""
cmd = ""
End If
End Sub





 
I have narrowed it down to this line.

Open cmd for Binary Access Read As #tFile

Actual error is:

Run-Time error '52'
Bad file name or number

cmd is a valid path as it is the file dropped on the exe. and #tFile is = to Freefile

Any thoughts?

Thanks

Matt
 
i think this may be similar to a problem ive had in the past.

the argument you are passing to the open statement is

"pathtofile/filename.xyz" and not

pathtofile/filename.xyz

just to test try sticking this line in above the open statement

cmd = Mid(cmd, 2, Len(cmd) - 2)

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
 
Thanks a ton, you got me on the right track. I actually had to strip out the Quotes all together as the
cmd = Mid(cmd,2,Len(cmd) -2) caused the program to error out when the associated file was double clicked. but when dropped on the exe it worked perfectly (opposite from the initial error.

cmd = Replace(cmd, Chr(34), "") Solved it.

Thanks again so much for the help.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top