Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find text inside existing files
#1
I basicaly want to create a folowing workflow:
1. Copy some text that is inside clipboard into a text file
2. and than make macro check for specific words inside it. Something like: if word "example" can be found in file example.txt -> do something

Maby a bit noobish but i'm just starting to learn this awesome software.
Thank's
#2
try doing it in a variable rather than a text file.
Macro Macro2
Code:
Copy      Help
_s.getclip
out find(_s "test string")
An old blog on QM coding and automation.

The Macro Hook
#3
Thank's for the fast responce, i try to do it . Dow id realy could use use a file based database of sort's.
At leest that's what i used so far.
Bdw how would you make an: if variable/clipbard has some text than do something, else do something else?
Thank's again
#4
Macro Macro2
Code:
Copy      Help
_s.getclip
_i=find(_s "test string")
if _i>-1
,out "_s contains string"
else
,out "_s doesn't contain string"
An old blog on QM coding and automation.

The Macro Hook
#5
That worked great Big Grin
Thank you!
#6
What type of database or file is best for you? QM supports most databases, also SQLite, CSV, XML, Excel and raw files.
#7
Gintaras Wrote:What type of database or file is best for you? QM supports most databases, also SQLite, CSV, XML, Excel and raw files.

I usualy used plain *.txt and Excel files to contain and keep information that get's used and changed (well some are static) during macro execution.

For example: when doing automatic price checking/shoping/selling. I have a static database containing a list of items that im interested in. And they come up for sale at a certan time (for example) on a web site. So macro copies the text from a screan, than check's if the name of the item is in the file/excel sheet and that if found it acts upon it. Buy/sell, change my sell price ect. automaticaly based on parameters i have set. I also have separate files containing the previous price information for every item and a file that is used to store current price, corrected pice and so on..
I used simpler automation software before but this one has soo much more potential and speed, wich is esential for me. In i realy im doing my best to wrap my head around all the comand's and raw code and make it work. So every advice is more than wellcome Smile
#8
What is text file format? A simple list, or a table, maybe CSV?
#9
A simple example. Finds selected text in txt file containing simple list.
Macro Macro1646
Code:
Copy      Help
str sSel.getsel; err ret ;;get selected text

str sData.getfile("$documents$\my file.txt") ;;get file data
str sItem
foreach sItem sData ;;for each line
,if sItem~sSel ;;compare
,,out "found"
,,break
#10
Just a simple list. So if it exists it continues and than checks which one is it and moves on. If it's not there or if it is on the "blacklist" it abort's futher action's.
#11
Gintaras Wrote:A simple example. Finds selected text in txt file containing simple list.
Macro Macro1646
Code:
Copy      Help
str sSel.getsel; err ret ;;get selected text

str sData.getfile("$documents$\my file.txt") ;;get file data
str sItem
foreach sItem sData ;;for each line
,if sItem~sSel ;;compare
,,out "found"
,,break

This actualy look's exactly like the workflow im looking for Smile
Thank's a lot ken! Can't believe how fast you came up with it 8)
#12
I created a function for this. Will need less code if using in several places.
Function FindItemInTextFile
Code:
Copy      Help
;/
function! $file_ $item

;Finds a line in a text file.
;Returns 1 if found, 0 if not.


str sData.getfile(file_)
if(!sData.len) ret
IStringMap m=CreateStringMap(1|2)
m.AddList(sData "[]")
if(m.Get(item)) ret 1

example
Macro Macro1649
Code:
Copy      Help
str s.getsel

int found=FindItemInTextFile("$desktop$\test\test.txt" s)
if found
,out "found"
else
,out "not found"
#13
Thank's to your examples and help i finaly got 1/3 of my macro up and running Smile 2/3 more to go!
A lot of code study and brainstorming was also nesesary but so far so good.

Now i have another dilema. Is it posible to somehow make macro check 2 or 3 "if conditions" to make a desition? This is what i'm trying to do:

if something is true
and
if comething else is also true
and
if something else is also true
than
do something
else
something else

Bdw im testing the beta version and the new keybord feature is awesome and user/beginer friendly. Gona stick to it Big Grin
#14
if found1 and found2 and found3
,out "all found"
else
,out "not all found"


if found1 or found2 or found3
,out "something found"
else
,out "not found"
#15
Thank's a lot for a quick responce, ill give it a go.
#16
Maby i should make a new tred named "help a noob" hehe but here is some more code that is giving me trouble. :oops:
What im trying to do here is make a loop that will break once it finds the image it's waiting for and repeat all actions from the begining if it doesen't in set amount of time. Right now the macro doesnot restart after 100s looking for the image (or maby it does :? ), it just gives me a time out error and stops - Error (RT) in first: wait timeout. . Maby im doing the code wrong?

Code:
Copy      Help
rep
    if(scan("first.bmp" 0 0 1 65)) ;;zuta nula
        2
        rig ;; getting the drop down menue
        2
        wait 10 S "second (2).bmp" 0 0 1|0x400 65  ;;
        2
        lef ;; click the image on the dropdown menue
        6
        if(wait( 100 S "third.bmp" 0 0 1|0x400 65)) break ;; here is the image he is waiting for 100s
#17
wait always throws error on timeout. Use err to handle it. Read in Help.

wait...
err continue ;;on error continue the loop
break


Forum Jump:


Users browsing this thread: 1 Guest(s)