Problems with error checking

Hi:

So I’m trying to replicate in ApplescriptObjC a folder generator utility that I made in Applescript Studio several years ago.

I set up the new interface and got that working


script AppDelegate
	property parent : class "NSObject"
    
    --IBOutlets
    property studioDept : missing value
    property existingClient : missing value
    property newClient : missing value
    property sapNumber : missing value
    property workOrder : missing value
    
    property client : missing value
    
    property testView : missing value
    
  
    
    
    on setWindowValueFields_(sender)
        set studioDeptValue to (studioDept's selectedCell()'s |title|())
        set existingClientValue to existingClient's stringValue()
        set newClientValue to newClient's stringValue()
        set sapNumberValue to sapNumber's stringValue()
        set workOrderValue to workOrder's stringValue()
        set concatentedString to current application's NSString's stringWithFormat_("%@%@%@%@%@", studioDeptValue, existingClientValue, newClientValue, sapNumberValue, workOrderValue)
        testView's setString_(concatentedString)
        testhandler(studioDeptValue)
    end setWindowValueFields_
   
    
        if existingClientValue is not equal to "" and newClientValue is equal to "" then
            set client to existingClientValue
        else if existingClientValue is equal to "" and newClientValue is equal to "" then
            set cleitn to newClientValue
        else
            display dialog "Something is wrong with your client selection."
        end if
    
  end script

When I hit the interface button, my little testView window displays all the values that were successfully copied from the button matrix and the text fields. But then I want to do a quick error check that the user hasn’t both selected an existing client from the pulldown AND typed in a new client name in the newClient field. I then when a little display dialog to alert them if they have a problem, allowing them to fix it and hit the interface button again.

Not exactly sure how to position my if then else statement to do the test and get the display dialog to pop up. Right now I hit generate and all the script does is fill in my testView and then just stops. Could someone point out what I need to do to accomplish what I’m attempting?

Thanks.

What I can see right now is that you are calling a method (testhandler) with an argument and do not use a colon (actually a _ in ASOC), and also adding “my” in front of it helps sometimes.

Second, there is a few lines of code that are not within any method (“on … end”). This code will never be called as it is not within a method, it’s just “floating” around. Perhaps it’s the testhandler method?

Also, display dialog is not something that works very well under ASOC. In fact, I believe it doesn’t work at all. A simple workaround is to use the log command, like this:

log "Something is wrong with your client selection."

Here’s a revised script:

script AppDelegate
property parent : class "NSObject"

--IBOutlets
property studioDept : missing value
property existingClient : missing value
property newClient : missing value
property sapNumber : missing value
property workOrder : missing value

property client : missing value

property testView : missing value

on setWindowValueFields_(sender)
    set studioDeptValue to (studioDept's selectedCell()'s |title|())
    set existingClientValue to existingClient's stringValue()
    set newClientValue to newClient's stringValue()
    set sapNumberValue to sapNumber's stringValue()
    set workOrderValue to workOrder's stringValue()
    set concatentedString to current application's NSString's stringWithFormat_("%@%@%@%@%@", studioDeptValue, existingClientValue, newClientValue, sapNumberValue, workOrderValue)
    testView's setString_(concatentedString)
    my testhandler_(studioDeptValue)
end setWindowValueFields_

--What is this? It's not part of any method, it seems to float around, thus it cannot be called...
if existingClientValue is not equal to "" and newClientValue is equal to "" then
    set client to existingClientValue
else if existingClientValue is equal to "" and newClientValue is equal to "" then
    set client to newClientValue
else
    display dialog "Something is wrong with your client selection."
end if

end script

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

I think it will work if you just include that second block of code inside your setWindowValueFields_ method. The way you posted it, that block is just sitting outside of any methods, so it won’t get executed.

Ric

leonsimard,
Actually there’s nothing wrong with calling your own method with “testhandler(studioDeptValue)” if it’s in this same script – I usually use the underscore just to keep everything more consistent, but it’s not necessary if you’re not calling cocoa methods, and there’s no need to use “my” unless you’re updating a UI element.

Also, “display dialog” works fine in ASOC, I’m not sure where you got that idea.

Ric

@rdelmar: Really? Didn’t know that. And i got used to not using display dialog… this is perhaps from where I got this idea :-). Tx!