ReadIniFile Blues

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

ReadIniFile Blues

Post by fightcancer » Tue Feb 20, 2007 2:01 pm

My macro can read from the INI file, but when it loops it loses the power to ReadIniFile. What would prevent my macro from being able to read from the INI file? In fact, after looping it can't read from this INI or a copy of the same INI at a different path. I'm clueless.

Here's the troublesome line of code.

Code: Select all

ReadIniFile>iniPath,%BuyOrder%,Line,BuyOrderLine
Length>BuyOrderLine,Len
The following line...

Code: Select all

MessageModal>BuyOrder: %BuyOrder%, BuyOrderLine: %BuyOrderLine%, Len: %Len%
...returns the following info:
BuyOrder: ship, BuyOrderLine: , Len: 0

I've also tried substituting the variable with the path...

Code: Select all

ReadIniFile>c:\test.ini,%BuyOrder%,Line,BuyOrderLine
...And it yields the same result.

Again, the macro will work the first time, but fails on the second iteration of the loop. So the first time, the MessageModal returns:
BuyOrder: ship, BuyOrderLine: 1, Len: 1

Any ideas?

(The entire macro is presently 730 lines with subroutines. So I'll refrain from posting it now in hopes that someone can point out some glaring syntax error. :) )

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 20, 2007 2:25 pm

The BuyOrder or Line variables are probably being set to a value that doesn't exist in the INI file. Debugging will find the problem. Cannot help without seeing the code or debugging it for you but you should be able to find the problem if you step through with the debugger yourself and watch the variables being assigned.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Tue Feb 20, 2007 3:18 pm

Thanks for the fast response! This may be the info you need. Here's the INI's layout. For each BuyOrder (item), I have a section. Under each section I have an entry called "Line" which stores the line number of the item.

[Ship]
Line=1

[Module]
Line=1
Line2=1

The first time around, the macro can read the entry "Line" under the Ship section. On the second iteration, the macro cannot read the entry "Line" under the Module section. However, when I adjust the macro to read the entry "Line2" on the second iteration (Module section), it reads the entry fine.

I guess there's some kind of INI etiquette that says you can't use the same entry in different sections. In that case I'll have to do away with using sections and just rename all my entries to "%BuyOrder%_Line".

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 20, 2007 3:29 pm

No, it has nothing to do with your INI file. You CAN have multiple entry names of the same name as long as they are unique to the section.

The problem is your script. I guarantee it. You are probably setting Line to some value, e.g. 1. Then when you refer to Line in the ReadINiFile it is looking for an entry called "1", not "Line". Look at your variable names. Step through with the debugger and watch the values. Look closely.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Tue Feb 20, 2007 4:14 pm

You're probably right. I'll debug later when I get home. Thanks again!

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Wed Feb 21, 2007 3:04 am

You guessed it! It was a variable naming issue.

The Culprit:

Code: Select all

ReadLn>file_names_%file_names_count%,k,line
So when the macro encountered this code:

Code: Select all

ReadIniFile>%EVEiniPath%,%BuyOrder%,Line,BuyOrderLine
...I was hosed.

The issue was that the second bit appears in the macro before The Culprit. That's why the issue only appeared on the second iteration and not on the first--because by the second iteration, the variable "line" had already been redefined using the ReadLn command.

FYI, one **BREAKPOINT** just before the error let me view the snapshot I needed to diagnose. Thanks for pointing me in the right direction!

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Sun Feb 25, 2007 4:47 pm

FYI, the line

Code: Select all

ReadLn>file_names_%file_names_count%,k,LineResult
...no longer works for me. It's as if MS can no longer interpret file_names_%file_names_count%. So I have to use something like:

Code: Select all

ReadLn>file_names_1,k,LineResult

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Feb 25, 2007 4:55 pm

Do this:

Let>thisFileName=file_names_%file_names_count%
ReadLn>thisFileName,k,LineResult
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Sun Feb 25, 2007 6:00 pm

Thanks!

(I just wanted to FYI you because I got that line from somewhere on here. It may be in the sample scripts, but I'm not sure.)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts