Contributed by Sam Cox.
It is important to know that files themselves are never “dropped” onto Neobook or any other application. Filenames, yes, but not the actual files. All applications that accept dropped files receive the path/name of the file and then do loads of processing including a) verifying that the path/name exist, b) that the path/name make sense to the program (e.g., correct file extension), c) checking file permissions, d) passing the path/name to a subroutine or plug-in or external program to manipulate the data in the file.
There are two ways to drop file names onto NB5 pubs:
1) Drop one or more path/names onto the pub’s EXE file in Explorer or a Desktop icon in which case Windows runs the pub and presents the filenames to the pub on the command line. You can access the filenames via NB’s [CommandLine] variable with [#13] delimiters.
2) Drop one or more path/names onto a running pub’s TextEntry object in which case the filenames are available via the object’s variable. The pub can be “notified” of the arrival of the filenames by way of code in the Text Changed section.
In either case, the pub gets the fully qualified filenames which it must process. The processing might involve looking at the filename’s extension and calling an appropriate external program, an internal NB command, or a plug-in’s command to process the file.
This sample consists of a single TextEntry object with variable [TextEntry1] and this code in Text Changed:
Code:
.disable to prevent drops while processing
.change color to indicate disabled
DisableObject “[self]”
SetObjectFill “[self]” “Red” “Solid” “False”
.copy then clear input variable for cosmetic reasons
SetVar “[Incoming]” “[TextEntry1]”
SetVar “[TextEntry1]” “”
Gosub “ParseIncoming”
Gosub “Dispatch”
.done processing so allow more drops
.change color back to indicate enabled
SetObjectFill “[self]” “Silver” “Solid” “False”
EnableObject “[self]”
In BOOK PROPERTIES ACTIONS SUBROUTINES:
Code:
arseIncoming
StrParse “[Incoming]” “[#13][#10]” “[Filename]” “[Count]”
Return
ispatch
Loop “1″ “[Count]” “[n]”
ExtractFileExt “[Filename[n]]” “[Extension]”
.MODIFY THE FOLLOWING LINE AS REQ’D
SearchStr “|[Extension]|” “|.txt|.zip|.exe|.bob|” “[pos]”
If “[pos]” “>” “0″
SetVar “[Filename]” “[Filename[n]]”
Gosub “Do[Extension]”
Else
Alertbox “EEK” “Can’t handle file|[Filename[n]]”
Endif
EndLoop
Return
o.TXT
Alertbox “PROCESSING” “Processing TXT file|[Filename]”
Return
o.ZIP
Alertbox “PROCESSING” “Processing ZIP file|[Filename]”
Return
o.EXE
Alertbox “PROCESSING” “Processing EXE file|[Filename]”
Return
o.BOB
Alertbox “PROCESSING” “Processing BOB file|[Filename]”
Return
Modify the “Do” subroutines to suit your needs, and edit the indicated line in the “Dispatch” subroutine.
Run the pub and drop one or several files at once on the TextEntry box. Watch the Alertboxes (one for each file dropped) appear in sequence.
The key to this working smoothly is that the drop object’s Text Changed code is called just once when file names are delivered. If, on the other hand, you were to type into the object, the Text Change code is called once for each character typed! When dropping or pasting text into a TextEntry object, the Text Changed code is triggered just once.
———————————————
What is Neobook?
Without ANY programming knowledge, you too can create and compile great full featured Windows Software, presentations, e-books, e-zines, catalogs and much more!
Simply put, it is a programming environment that allows you to create, compile and distribute royalty free applications of any kind. From beginners to advanced programmers, NeoBook RAD5 Pro has something for everybody. Try it free!
More Info
Download 30 day free trial
Buy Now for 10% off