WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Display Contents of a Text File

 Keywords: Display Contents of a Text File 


#DefineSubRoutine FileChange()
   si = document.getElementById("FilePicker").options.selectedIndex
   ThisFile = document.getElementById("FilePicker").options(si).innerText
   ;message(si, ThisFile)
   If FileExist(ThisFile)
      document.getElementById("FileContents").innerText = FileGet(ThisFile)
      document.getElementById("FileContents").style.border = ".25mm solid black"
   Else
      document.getElementById("FileContents").style.border = ""
      document.getElementById("FileContents").innerText = ""
   EndIf
   Return
#EndSubRoutine

#DefineSubRoutine Main(Proc_Handle,Proc_Message,Proc_ID, Proc_EventInfo, reserved)
   ;DialogprocOptions Constants
   MSG_INIT = 0                ; The one-time initialization
   MSG_TIMER = 1                ; Timer event
   MSG_BUTTONPUSHED = 2        ; Button press.
   ; New options for DialogObject
   DLGOBJECT_ADDEVENT   = 1 ;DialogObject add event
   DLGOBJECT_REMOVEVENT = 2 ;DialogObject remove event
   DLGOBJECT_GETOBJECT  = 3 ;DialogObject get reference to object
   DLGOBJECT_GETPICTURE = 4 ;DialogObject get a picture object
   ; New callback message
   MSG_COMEVENT         = 14 ;COM control event fired
   ;
   Switch Proc_Message
   Case MSG_INIT
      document = DialogObject(Proc_Handle, 003, DLGOBJECT_GETOBJECT)
      document.open()
      document.writeln("<h2>Please select a file to display</h2>")
      document.writeln(`<select id="FilePicker">`)
      document.writeln("<option>Pick a File</option>")
      dafiles = FileItemize(".\File-*.txt")
      For x = 1 To ItemCount(dafiles, @TAB)
         ThisFile = ItemExtract(x, dafiles, @TAB)
         document.writeln("<option>%ThisFile%</option>")
      Next
      document.writeln("</select><br><br><label for='FileContents'></label>")
      document.writeln(`<div style="padding:2mm;display:pre;" id="FileContents"></div>`)
      document.close()
      document.body.style.overflow = "hidden"
      document.body.style.border   = ".25mm solid black"
      document.body.style.backgroundcolor = "lightsteelblue"
      DialogObject(Proc_Handle, 003, DLGOBJECT_ADDEVENT,  "onclick", 1)      ;setup a MSG_COMEVENT
      DialogProcOptions(Proc_Handle, MSG_BUTTONPUSHED, 1)
      DialogProcOptions(Proc_Handle, 1002, 4)
      FP = document.getElementById("FilePicker")
      ObjectEventAdd(FP, "onchange", "FileChange")

;      DialogProcOptions(Proc_Handle, 1, 500)   ; setup a MSG_TIMER
      Return(-1)
      Break
   Case MSG_BUTTONPUSHED
;         blank...
      Break
   Case MSG_COMEVENT
      ; Test in case more events or COM controls are added later
      If Proc_EventInfo.identifier == 1 && Proc_ID  == 003
         ; Get event source object associated with the event
;         Element = document.parentWindow.event.srcElement
;         Element = 0
      EndIf
      Break
   EndSwitch       ; Proc_Message
   Return(-1)      ; Do default processing
#EndSubRoutine   ; End of Dialog Callback ExamProc

;   first build some test files...
For x = 1 To 3
   fileContents = ""
   fname = StrCat("File-%x%.txt")
   fileLine = "This is file #%x%"
   For y = 1 To 5
      fileContents = ItemInsert(fileLine, -1, fileContents, @LF)
   Next
   FilePut(fname, fileContents)
Next

MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`MSHTML Test`
MyDialogX= -1
MyDialogY= -1
MyDialogWidth=247
MyDialogHeight=289
MyDialogNumControls=003
MyDialogProcedure=`Main`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`

MyDialog001=`011,267,036,012,PUSHBUTTON,DEFAULT,"OK",1,1,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`193,267,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`005,009,232,252,COMCONTROL,DEFAULT,"mshtml:",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

Article ID:   W17742
Filename:   Display Contents of a Text File.txt
File Created: 2009:04:17:10:58:54
Last Updated: 2009:04:17:10:58:54