I am finishing my first winbacth file. I opened a file in a multiline edit box and would like to search the box for text using the data typed into the FindVariable1 Editbox. A sort of file find. IS there a function already written to do this? I haven't been able to find it. I played around with strscan, and other functions, but can't get it to work. Any help would greatly be appreciated. Here is what I have so far.
;load the main page first
main=fileget("C:\temp\testnotes.txt")
folder= "C:\temp"
filetoread = "C:\temp\testnotes.txt"
:buildscreen
JoesnotesFormat=`WWWDLGED,6.2`
JoesnotesCaption=`Joes Notes v 2.0 11/03/2017`
JoesnotesX=044
JoesnotesY=078
JoesnotesWidth=888
JoesnotesHeight=350
JoesnotesNumControls=009
JoesnotesProcedure=`DEFAULT`
JoesnotesFont=`DEFAULT`
JoesnotesTextColor=`DEFAULT`
JoesnotesBackground=`DEFAULT,DEFAULT`
JoesnotesConfig=0
Joesnotes001=`731,313,064,012,PUSHBUTTON,"PushButton_QUIT",DEFAULT,"QUIT",100,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Joesnotes002=`023,045,064,012,PUSHBUTTON,"PushButton_1",DEFAULT,"Avaya Router",1,2,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
Joesnotes003=`019,313,064,012,PUSHBUTTON,"PushButton_20",DEFAULT,"Save Changes",20,17,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Joesnotes004=`105,313,064,012,PUSHBUTTON,"PushButton_21",DEFAULT,"Open Notes Folder",21,18,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Joesnotes005=`175,313,064,012,PUSHBUTTON,"PushButton_22",DEFAULT,"Capture the path",22,19,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Joesnotes006=`819,073,064,012,VARYTEXT,"VaryText_1",mainscreen,DEFAULT,DEFAULT,180,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Joesnotes007=`035,069,770,220,MULTILINEBOX,"MultiLineBox_2",main,DEFAULT,DEFAULT,190,DEFAULT,"Microsoft Sans Serif|12288|40|34",DEFAULT,DEFAULT`
Joesnotes008=`525,025,036,012,PUSHBUTTON,"FindButton",DEFAULT,"Find",14,14,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Joesnotes009=`567,025,056,012,EDITBOX,"Findbox",FindVariable1,DEFAULT,DEFAULT,15,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ButtonPushed=Dialog("Joesnotes")
;when using case, the case number was created when I needed to give it a unique variable number in the DDL editor
;QUIT
If Buttonpushed == 100 then exit
; main webpage - This is the first web page that opens up
If Buttonpushed == 16 then goto openmain
;Avaya Router
If Buttonpushed == 1 then goto Avayarouter
;save changes that are on the current screen
If Buttonpushed == 20 then goto savechanges
;open the folder
If Buttonpushed == 21 then goto openfolder
;Button to find a varaible in text
If Buttonpushed == 14 then goto findtext
:Avayarouter
folder= "D:\mydata\mynotes\Avaya Router"
filetoread="D:\mydata\mynotes\Avaya router\Avayarouter.txt"
main=fileget("%filetoread%")
goto buildscreen
:openmain
folder= "C:\temp"
filetoread = "C:\temp\testnotes.txt"
main=fileget("%filetoread%")
goto buildscreen
:openfolder
run("explorer.exe",folder)
goto buildscreen
:savechanges
fileput(filetoread,main)
goto buildscreen
;routine to find text inside the main window
;I would like to highlight the occurrences of a string that I searched for
:findtext
Strscan(main, FindVariable1,startpos1,@FWD) ;definitely not working
If you retrieve the value from the editbox you could use StrIndex().
Jim
Jim,
I used some of the code in the forum to get my search to work. This will do until I find a better solution
:findtext
str="%findvariable%" ;I inputed something to look for
rep="<--> %findvariable%" ; when I find what I'm looking for put <--> and what that data I'm looking for because <--> is going to replace what I'm looking for
infile= "D:\mydata\mynotes\joesnotes.txt" ;data file
outfile="D:\mydata\mynotes\tempfiletoread.txt"
fs = FileSize( infile )
binbuf = binaryalloc( fs+10000 )
ret = BinaryRead( binbuf, infile ) ;read the file into a buffer
num = BinaryReplace( binbuf, str, rep ,0)
BinaryWrite( binbuf, outfile)
main=fileget("%outfile%")
To do that you could that but might find...
new_text = StrReplace(value_from_editbox,findvariable,"<-->")
Then
FilePut(outfile,New_text)
a bit easier.
Also, another suggestion, you should stop using % signs in that fashion. They can be tremendously useful at times but not in this situation and they can cause a bit of grief that is hard to find at times. Just use the variables directly like
main=fileget(outfile)
instead of
main=fileget("%outfile%")
I would also investigate the use of Dynamic Dialogs as time allows. This opens up many possibilities on the interface front.
There is an Introduction to Programming book on the Downloads page that uses WinBatch for its examples that you might find useful. It is pretty old so won't make use of newer features but might be helpful. Especially if you don't have a strong background in programming which, of course, I have no idea about. Would probably be informative to browse through even if you do to see how certain things are done in WinBatch and as you probably noticed, there are code samples under all the Help topics. I have found it useful to just browse through the Help File function list reading the brief descriptions so I have an idea of what is there. You have probably also noticed that the functions are grouped/named by type. So if you need a String function they all start with "Str", DateTime functions with "Time", etc.
...and welcome to the WinBatch family.
Jim
The "Introduction to Programming" book was updated in February of 2011 so it is admittedly old but not quite geriatric yet. And a lot of the basic concepts it explains are still as valid as they ever were so it is still a good recommendation to anyone willing to learn and wanting to improve.
Thanks Jim,
I modified my code as per your suggestions. Works great. two quick questions.
- Can I add get maximize/minimize/close menu bar to my winbatch file? The one that appears on all windows pages.
- Can I add color to text. For example
new_text = StrReplace(main,findvariable,"<-->") ; can the "<-->" have color like yellow?
Take a look at IntControl 49....another list of things to browse through.
No. Not within the editbox. At least not directly with WinBatch dialog functions. Not sure if that can be done via Windows APIs or not, but thinking not easily if at all.
If color is important you could add an Edit button and you could display a Browser control with the text formatted via HTML and when one clicks edit you could hide the browser and display the edit box and the reverse when clicking save. Would want to use a Dynamic Dialog for that operation.
Jim
Good to know on the update. I just found my print copy the other day :)
Jim
Quote from: td on November 09, 2017, 07:52:29 PM
The "Introduction to Programming" book was updated in February of 2011 so it is admittedly old but not quite geriatric yet. And a lot of the basic concepts it explains are still as valid as they ever were so it is still a good recommendation to anyone willing to learn and wanting to improve.