Jump to content
Sign in to follow this  

Editing scripts in notepad

Recommended Posts


Okay, a bit complex, but I've been looking into AutoIT for the entire day now, and decided to ask for pointers how to solve this.

I have to work with capturefiles that contain alarms. I reuse those alarms a lot, and I have to change the id's of the alarms every time I wish to reuse them. That costs me a lot of time, and I'd like to automate that.

The alarmfile roughly looks like this:

Alarmfield = "Averybadalarm-code"

Alarmdate = "12112008150519"

AlarmId = 1982

AlarmReason = "Some reason why it failed"

AlarmCause = "Voltageoverload and some more"

And some more lines. It's about the AlarmId-field.

I have a capturefile with about 40 alarms. I have to update the alarms to a different ID every time, or the program I use them on won't recognise them as different.

What I do now: See the last alarm's ID (for instance 1982), go the the first and renumber all of them from 1983 and onwards. That takes time.

What I want is a script that does this:

- Find the last alarm and read the ID value -> store that in a var.

- Find the first alarm

- Find the alarm-ID line

- Set the alarm-ID to the var-value + 1

- Find the next alarm and make sure it is one higher than the previous alarm so they are continuously numbered.

- Save the file

I want it to work regardless of editor. So I open my capturefile in Notapad++, set the cursor in the editing field and start the script. It should just go through the capture file and change stuff. The I add a ctrl-s just so it's saved and I can then get back to testing in no-time! :mellow:

Anyone any ideas?

Share this post

Link to post
Share on other sites

I don't think somebody's going to write you a whole script... what you can do is look at string managment and StringRegExp and do the job... it's quite a simple job

best regards :mellow:

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post

Link to post
Share on other sites

@VinWij: torels is right, this forum is about helping YOU do it. What you have is a nice basic project to learn with, so start coding and come back for specific help to get it done.

Check out the various functions for getting data from the control, like ControlGetText(), and for string operations, like StringReplace() (or even StringRegExp() if you already know RegExp from another language).

It's a good time to learn!


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

I was asking for ideas, not scripts. I am definitly planning to use this challenge to learn more about AutoIT, but some basic pointers about the direction I have to go to are nice.

Using the functions you mentioned will probably get me somewhere, and if I run into errors or things I cannot explain, I'll ask again. Exactly as PsaltyDS suggests! :mellow:

I have no programming experience whatsoever, but I am probably smart enough to figure this out. :( And I will ask questions here.

Thanks for the pointers. I'll see where they get me tomorrow.

Share this post

Link to post
Share on other sites

I think you should forget about the editor and read the file line by line in AutoIt. When you encounter a line starting with AlarmID , parse it and replace the number. Write every line out in a temp file. When you have done all off the lines determine if you want to replace the original with the new file.

From the top off my head, untested just something to work from (I might have parameters and keywords wrong. Use the help file..:mellow: ):

Func ReplaceAlarmIDs($filename)
    Local $linetext, $lastAlarmID = 1000, $tempFile = "C:\tempAlarmFile.tmp"
    If NOT fileExists($filename) Then
        ;Error msg
        While NOT @error
            If StringInString("AlarmID", $linetext) Then
                $linetext = MyNewAlarmID($linetext, $lastAlarmID)
            FileWriteLine($tempFile, $linetext)
       Return $tempFile
Func MyNewAlarmID($str, ByRef $lastAlarmID)
    ;Parse $str and replace AlarmID, then Increment AlarmID
    ;This is the quick and dirty approach
    $lastAlarmID += 1
    Return "AlarmID=" & $lastAlarmID

Local $file = ReplaceAlarmIDs("c:\TheAlarmFile.txt")
If Not @error Then
    FileMove($file, "C:\TheAlarmFile.txt")

You Could obviously have a similar approach on stuff you get from the clipboard.

Happy coding..:(

Share this post

Link to post
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
Sign in to follow this