Modify

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#1237 closed Bug (No Bug)

IniRead always return strings

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: 3.3.0.0 Severity: None
Keywords: Cc:

Description

Hello,

IniRead will always return strings:

$a = IniRead('','','',1)
If IsNumber($a) Then MsgBox(0,'DEBUG','TRUE') ; false
If IsString($a) Then MsgBox(0,'DEBUG','TRUE') ; true

Also it would be _very_ useful if a failed IniRead don't would only return the default-value; it also should set @error. Only so you could different it surely from a sucess IniRead

Attachments (0)

Change History (7)

comment:1 Changed 14 years ago by xelotiac@…

The bug-report was mine, forgotten to mentioned it.

comment:2 Changed 14 years ago by Valik

  • Resolution set to No Bug
  • Status changed from new to closed

There's no bug here and the behavior is not going to be changed.

comment:3 Changed 14 years ago by xelotiac@…

Can you give an explanation, please?

IniRead returns the digit 1 to the variable. Proofing it with IsNumber / IsInt() etc. says you, that the value of the variable is not a number. But obviously, the 1 without quotation mark is defenitely a number in my point of view.

comment:4 Changed 14 years ago by Valik

Explanation of what? Why your code sucks? You want to know if IniRead() is successful?

Local Const $sIniReadFailed = "INIREAD_FAILED_UNIQUE_STRING_WOO"
Local $s = IniRead("", "", "", $sIniReadFailed)
If $s = $sIniReadFailed Then 
    MsgBox(0, "", "IniRead() really failed.")
    $s = "My real default value"
EndIf

Problem solved. Otherwise, I do not have any problems with the way IniRead() is implemented nor with how the default parameter functions.

The function works fine and the behavior you claim to want is trivial to implement as I've demonstrated. I don't really see where further discussion or explanation is necessary.

comment:5 Changed 14 years ago by xelotiac@…

At last that IP Block is expired, so I only recently answer now.

That with the Failed IniRead was only a Feature Request by me. Unfortunately your code wouldn't solve the problem (special function for automatic IniReading, IniWriting decision). This is another story, we finished I think.

Instead, I wanted a explanation, why in your opinion the IniRead Return value type is not a bug? Like I demonstrated in my last post, I can't understand this, because IniRead should return a digit, but IsNumber() etc. doesn't recognize it.

Thank you for hurry replying and suffering my crappy English :)

comment:6 follow-up: Changed 14 years ago by danielkza

It was never supposed to return a number. You get the data untouched and it's your job to convert it to whatever datatype you need/want. Automatic conversions would be unpredictable (you can't know what type to expect), and would lead to redundant code: if you want a string in all cases, you'd end up with two conversions instead of none.

Therefore, the more reasonable choice, in my view, is let the programmer take care of it. If you want an int., check the result of StringIsInt(). If you want a float, checking for an empty string and using Number() should suffice.

Valik, please correct me if I misunderstood it in any way.

comment:7 in reply to: ↑ 6 Changed 14 years ago by Valik

Replying to danielkza:

Valik, please correct me if I misunderstood it in any way.

You're not quite right. This is about the return value on failure when the 4th parameter is returned. In the example above the 4th parameter is passed in as a number but is converted to a string when returned. That means the data was touched. However, IniRead() always returns a string and the touching of the data is to ensure the function matches the description.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.