Error handling question...

: Yeah, I’m sure I’ve seen this sort of thing before, I just can’t find
: anything about it now! I’ve tried doing it myself but haven’t been able to
: manage it yet. The only way I could think of was to create a list of the
: string lengths, then create a string of the list of strings, get the
: offset of the required string in this list and somehow, using the string
: lengths list, get the offset from there!? Maybe…
: Well, I know what I mean anyway! :slight_smile:
: I may have another go at it…
: Cheers,
: Juerg

Eureka!

This getting-the-index technique only works if all the text strings in the subject list are the same length, which might apply for your error codes:

property theCodes : {"101", "102", "103"}
property theMsgs : {"I'm the message for error #101", "for error #102", "for 103"}

set theKey to text returned of (display dialog "Enter error code" default answer "")
set codeText to theCodes as text
set theIndex to (((offset of theKey in codeText) - 1) / 3) + 1
if theIndex is not less than 1 then
        display dialog (item theIndex of theMsgs)
else
        display dialog "Message not found"
end if

Marc K. Myers
Marc@AppleScriptsToGo.com
AppleScriptsToGo
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[5/24/02 1:37:13 PM]

: Hey Marc!

: I thought this one had died! :slight_smile:

: Thanks for the code though - I finally arrived at a solution almost identical
: to yours and it seems to be working just fine at moment! (Famous last
: words :wink:

: Cheers,

: Juerg

This was one of those wake-up-at-three-in-the-morning-with-the-answer situations. If my subconscious thought it was important enough to wake me up about, I figured I ought to post it.
Marc “I can do this in my sleep!” Myers
[5/27/02 7:04:03 PM]

Hey Marc!
I thought this one had died! :slight_smile:
Thanks for the code though - I finally arrived at a solution almost identical to yours and it seems to be working just fine at moment! (Famous last words :wink:
Cheers,
Juerg