Jump to content

Reading .ini files that update for text


Loraik
 Share

Recommended Posts

Hi I am trying to get a small script working for here at work. What I am trying to do is have a AutoIt script read a .ini file for certain words that might be entered and press the "Pause" keyboard key and issue a msg. box that says "This word has been found". The .ini file is always being updated so it needs to be looking through it all the time.

I just can't grasp how to use IniRead to get this done. After several days of looking at examples I am breaking down and asking for help.

If anyone could toss me some bones on how to get this to work I would appreciate it so very much. I did a search here on the forums but didn't see anything that fit what I was tryig to do.

Thanks in advance!

Link to comment
Share on other sites

  • Moderators

Do you have a non-working script for attempted failures to go off of?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

;Channel Word Finder

Func WordFinder()

$wordfind = IniReadSection("C:\semi\coded\a\optionalstacks.ini", "coded-")

If @error Then

MsgBox(4096, "", "Error occured, probably no INI file.")

Else

For $i = 1 To $wordfind[0][0]

MsgBox(48, "Channel Found!" & $wordfind[$i][0])

Send("{PAUSE}"); Pauses

Next

EndIf

EndFunc

Please don't laugh, I am not the best at this stuff. What I tried to do is take the example given on the AutoIt page and apply it to my solution.

The goal is to search the file "optionalstacks.ini" located in our C:\semi\coded\a\ directory looking for the code "coded-". When found it displays a msg box saying "Channel Found!" then hits the "Pause" key on the keyboard. At this point pressing the PAUSE key stops our system software and allows us to adjust. Then we click "OK" on the msg. box and it hits pause again and our software starts again reading the .ini file. Not sure how to tie the second PAUSE hit to the msg box.

Edited by Loraik
Link to comment
Share on other sites

  • Moderators

just a quick question...

Key/Section = [Key/Section Name] = [0]

Value = =Word Looking For [1]

So are you looking for the words in the brackets (the sections) are in the values under the brackets?

If it's a value, it would be:

MsgBox(48, "", "Channel Found!" & $wordfind[$i][1]) ; that just seems to make more sense... (P.S., your message box was missing a title, would throw you an error).

Do you have the variable of words to match? Are you manually putting them in, or are they in an array also?

This can be done with

$WhatWord = InputBox("Word Input", "Put the word you want to find", "", "", 80, 10)
IniWrite(@DesktopDir & "\optionalstacks.ini", "Words_to_find", "words", $WhatWord)

$wordfind = IniReadSection(@DesktopDir & "\optionalstacks.ini", "coded-")
$MyWordsToFind = IniReadSection(@DesktopDir & "\optionalstacks.ini", "Words_to_find")
For $i = 1 to $wordfind[0][0]
    For $a_i = 1 to $MyWordsToFind[0][0]
        If $wordfind[$i][1] = $MyWordsToFind[$a_i][1] Then
            Send("{Pause}")
            MsgBox(0, "Match Find", "We Found A Match: " & $wordfind[$i][1] & " and " & $MyWordsToFind[$a_i][1])
            Send("{Pause}")
        EndIf
    Next
Next

I figured you could change the directory location from @DeskTopDir, to your 'C:' directory.

Also, I attatched an ini as an example I used to test it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

just a quick question...

Key/Section = [Key/Section Name] = [0]

Value = =Word Looking For [1]

So are you looking for the words in the brackets (the sections) are in the values under the brackets?

If it's a value, it would be:

MsgBox(48, "", "Channel Found!" & $wordfind[$i][1]) ; that just seems to make more sense... (P.S., your message box was missing a title, would throw you an error).

Do you have the variable of words to match? Are you manually putting them in, or are they in an array also?

Thanks for your help I really appreciate it. The string of text I am searching for in the .ini file is actually "coded-". I wasn't exactly sure how to go about reconfiguring the example so I did a bunch of trial and error thus confusing the heck out of myself. We are not entering any text but rather our inhouse software is spitting code with a number into this .ini file everytime there is a misalignment so we need to recalibrate when that code is generated. There is always different stuff being pumped into this .ini file (updated every 30 seconds I think) so it has to beable to keep reading that .ini in the background until that "coded-" string pops up. A example of how it would appear in the .ini file would be

3459d,coded-00012,3460d,3461d,ect,ect.

Link to comment
Share on other sites

  • Moderators

you need to look at the string functions in the helpfile then... and use an array on the string file.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...