 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Musa
Joined: 31 Aug 2006 Posts: 9
|
Posted: Fri Sep 01, 2006 7:47 pm Post subject: Build vocabulary by AHK, |
|
|
Hi,
This is my very first try, (sorry if it's useless)
Following code display first and second line from a ".txt" file as a balloon message which are basically a word and its meaning. My text file looks like
a
meaning of a
b
meaning of b
c
meaning of c
d
meaning of d
e
meaning of e
and i saved the file as "New Text Doc.txt" inside "C:\New Folder". (can be changed)
Once i run it, I get the meanign of my word at certain interval !!!
Please write some comments (constructive and distructive both) As i am new i want to improve my skill and you guys can help me on that. Thanks
| Code: |
i = -1 ;difficult word counter
j = 0 ;meaning counter
Loop
{
i += 2 ;jumps to next difficult word
j +=2 ;jumps to next meaning
loop, 3 ;repeats the same word 3 times
{
FileReadLine, line, C:\New Folder\New Text Doc.txt, %i% ;reads the difficult word
FileReadLine, line1, C:\New Folder\New Text Doc.txt, %j% ;reads the meaning
if ErrorLevel <> 0
break
TrayTip, %line%,%line1%,,1 ;display the balloon message
SetTimer, RemoveTrayTip, 3000 ;displays for 3 sec
sleep 10000 ;displaying interval between difficult words 10 sec
}
}
RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return
|
|
|
| Back to top |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 244
|
Posted: Fri Sep 01, 2006 10:08 pm Post subject: |
|
|
Nicely done. Only thing I'd do differently is read the lines only once, and get rid of i and j, like this:
| Code: | Loop {
FileReadLine, line, file.txt, % a_index
FileReadLine, line1, file.txt, % a_index+1
If ( errorLevel )
break
Loop 3 {
TrayTip, %line%,%line1%,,1
SetTimer, RemoveTrayTip, 3000
Sleep 10000
}
}
RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return |
|
|
| Back to top |
|
 |
Musa
Joined: 31 Aug 2006 Posts: 9
|
Posted: Fri Sep 01, 2006 10:53 pm Post subject: |
|
|
Great, "Less code and more efficient"
Thank you very much Roland..... I learned something effective... |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Sat Sep 02, 2006 8:58 pm Post subject: Re: Build vocabulary by AHK, |
|
|
| Musa wrote: | | Please write some comments (constructive and distructive both) As i am new i want to improve my skill and you guys can help me on that. |
Nice coding! ..
Here is a variant of your code different in three aspects:
- 1) The code reads a single line and splits it in to two parts.
The two-line retrieval method might suffer a drawback!
The display text would be corrupted if a single random line was deleted in the text file.
- 2) Uses just a timer not a loop.
This code can be easily absorbed into an existing always-running AHK script.
- 3) Runs Non-Stop.
The file will be read again from the beginning once the end is reached!
Here is a model of File.txt , a Pipe "|" delimited text file:
Chris|Chris Mallet
PhiLho|Phillipe Lhoste
Laszlo|Laszlo Hars
Veovis|Michael Peters
Goyyah|A.N.Suresh Kumar
Here is the Code:
| Code: | #Persistent
SetTimer, TrayTipDisplay, 10
Return
TrayTipDisplay:
SetTimer, TrayTipDisplay, OFF
FileReadLine, Line, File.txt, % Index
If (ErrorLevel!=0) {
Index=1
SetTimer, TrayTipDisplay, 10
Exit
}
StringSplit, L, Line, |
TrayTip, %L1%, %L2%,, 1
Sleep, 3000
TrayTip
Index++
SetTimer, TrayTipDisplay, 7000
Return |
Just giving you some ideas...
... Happy Scripting!
Regards,  _________________
 |
|
| Back to top |
|
 |
Musa
Joined: 31 Aug 2006 Posts: 9
|
Posted: Sun Sep 03, 2006 1:31 am Post subject: |
|
|
Thanks Goyyah,
Got excited to see the same kind of thing but in nice and different way.
I played with you code learned something new...then i tried to fix my code, try to go to the beginning of the file once it reached to the end....You know what i got failure, failure and failure....
actually there are two reasons of my failure... First, i am new and second i can not see what’s happening when the program runs...I mean watch window and breakpoint and things like that....(i normally write macro and alisp, vlisp routine and both of them have text editor and debugging tools....Wonder if AHK has any....
Finally, if you have time and you like to, will you please direct me how can i direct my first code, to go to the beginning of the file if end reached.
Musa.Biralo |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Sun Sep 03, 2006 8:19 am Post subject: |
|
|
Dear Musa.Biralo,
| You wrote: | i tried to fix my code, try to go to the beginning of the file once it reached to the end....You know what i got failure, failure and failure....
..... will you please direct me how can i direct my first code, to go to the beginning of the file if end reached. |
Sure! Following code is the mod of your original code presented in the title post.
| Code: | i = -1 ;difficult word counter
j = 0 ;meaning counter
Loop {
Loop {
i += 2 ; jumps to next difficult word
j +=2 ; jumps to next meaning
Loop, 3 { ; this loop repeats the same word 3 times
; reads the difficult word
FileReadLine, line, C:\New Folder\New Text Doc.txt, %i%
; reads the meaning
FileReadLine, line1, C:\New Folder\New Text Doc.txt, %j%
If ErrorLevel <> 0
Break
TrayTip, %line%,%line1%,,1 ;display the balloon message
SetTimer, RemoveTrayTip, 3000 ; displays for 3 sec
Sleep 10000 ; displaying interval between
; difficult words 10 sec
}
If ErrorLevel <> 0
Break
}
i = -1 ;difficult word counter
j = 0 ;meaning counter
}
RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
Return |
I have highlighted the Inclusions in Blue colour! Some slight beautification
would also be seen. Watch for the curly braces .. You will understand which loop - "starts where" and "ends where"!
I hope this was useful!
Regards,
PS: Nested loops are wonderful things. Once you get used to them you simply cannot stop . But you need to practise it! _________________
 |
|
| Back to top |
|
 |
Musa
Joined: 31 Aug 2006 Posts: 9
|
Posted: Sun Sep 03, 2006 6:02 pm Post subject: |
|
|
Goyaah! You are the man!!!
Now i understand.....
Thank you VERY much for you time....and the highlighting of the text to make me clear....I appreciate it.
Now, i am looking:roll: for the dictionary database so that we don't have to put the words in the txt file. then........... "desire tends to ∞"
musa.biralo |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Sun Sep 03, 2006 6:11 pm Post subject: |
|
|
| Musa wrote: | Now, i am looking for the dictionary database so that we don't have to put the words in the txt file. |
I do not get this part correctly .. Do you want a pointer on where you can
find a text based dictionary?
Regards,  _________________
 |
|
| Back to top |
|
 |
Musa
Joined: 31 Aug 2006 Posts: 9
|
Posted: Sun Sep 03, 2006 7:16 pm Post subject: |
|
|
Goyyah! amazed by your quick response…I like to thank you from bottom of my heart.
I have one in my computer but it contains lots of other ascii code and unreadable text…and I have to get rid of those then make a clean word and its meaning file…
Man! If I got the text based dictionary ( I mean words and its meaning in one file) that will be fabulous, marvelous, miraculous, wondrous…….
Do you have any idea……can I get the word and its meaning in one file.. if so, where can I find that.….(I will pray for such file) and i will be forever indebted.
Musa.Biralo |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
|
| Back to top |
|
 |
Musa
Joined: 31 Aug 2006 Posts: 9
|
Posted: Sun Sep 03, 2006 7:43 pm Post subject: |
|
|
i don't know how should i thank you......
Now my next learning step is the GUI commands......With your help i got (for now) what i was looking for ......My learning curve is pointing me the GUI commands....
Thank you for being so prompt...YOU ARE AMAZINGLY GREAT. MY DUE RESPECT IS WITH YOU AND WITH AHK FAMILY.
musa.biralo |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Sun Sep 03, 2006 8:40 pm Post subject: |
|
|
Dear musa.biralo,
| Quote: | | My learning curve is pointing me the GUI commands |
I am happy about it!
By the way .. you do not have to type musa.biralo for every post! Just edit your profile..
Regards,  _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|