AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Build vocabulary by AHK,

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Musa



Joined: 31 Aug 2006
Posts: 9

PostPosted: Fri Sep 01, 2006 7:47 pm    Post subject: Build vocabulary by AHK, Reply with quote

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
View user's profile Send private message
Roland



Joined: 08 Jun 2006
Posts: 244

PostPosted: Fri Sep 01, 2006 10:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Musa



Joined: 31 Aug 2006
Posts: 9

PostPosted: Fri Sep 01, 2006 10:53 pm    Post subject: Reply with quote

Great, "Less code and more efficient"

Thank you very much Roland..... I learned something effective...
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Sat Sep 02, 2006 8:58 pm    Post subject: Re: Build vocabulary by AHK, Reply with quote

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! Very Happy

Regards, Smile
_________________
Back to top
View user's profile Send private message
Musa



Joined: 31 Aug 2006
Posts: 9

PostPosted: Sun Sep 03, 2006 1:31 am    Post subject: Reply with quote

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
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Sun Sep 03, 2006 8:19 am    Post subject: Reply with quote

Dear Musa.Biralo, Smile

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, Smile

PS: Nested loops are wonderful things. Once you get used to them you simply cannot stop Wink. But you need to practise it!
_________________
Back to top
View user's profile Send private message
Musa



Joined: 31 Aug 2006
Posts: 9

PostPosted: Sun Sep 03, 2006 6:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Sun Sep 03, 2006 6:11 pm    Post subject: Reply with quote

Musa wrote:
Now, i am looking Rolling Eyes 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, Smile
_________________
Back to top
View user's profile Send private message
Musa



Joined: 31 Aug 2006
Posts: 9

PostPosted: Sun Sep 03, 2006 7:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Sun Sep 03, 2006 7:21 pm    Post subject: Reply with quote

The Online Plain Text English Dictionary

Here is some code that will assist you in downloading it:
http://www.autohotkey.com/forum/viewtopic.php?p=71941#71941

Wish you all the best! Very Happy

Regards, Smile
_________________
Back to top
View user's profile Send private message
Musa



Joined: 31 Aug 2006
Posts: 9

PostPosted: Sun Sep 03, 2006 7:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Sun Sep 03, 2006 8:40 pm    Post subject: Reply with quote

Dear musa.biralo, Smile

Quote:
My learning curve is pointing me the GUI commands


I am happy about it! Very Happy

By the way .. you do not have to type musa.biralo for every post! Just edit your profile..

Regards, Smile
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group