Can anybody tell me the correct syntax to rename a variable?
set conn_status to state of status as string
gives me as result a number from 0 to 10 - Works perfect!
now I want to write text instead of the number:
if conn_status = 0 then
conn_status = "Not Connected"
else if conn_status = 1 then
conn_status = "Dialing"
else if....
end if
set content of text field "status" of window "main" to conn_status
variables can only be set with the set or copy command.
you can do it like this:
if conn_status = 0 then
set conn_status_msg to "Not Connected"
else if conn_status = 1 then
set conn_status_msg to "Dialing"
else if....
end if
set content of text field "status" of window "main" to conn_status_msg
Model: G5 dual 2,5 GHz
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
perfect - in my applescript book is this option not described…
so we have two ways:
set conn_list to {"Not Connected", "Dialing", "Connecting", "Error", "Connected", "Disconnecting",...}
set conn_status to item (conn_status) of conn_list
this is very elegant - but if you have numbers: 0,2,4,5,7,8 then you have a problem - you have to enter
some entreas two times…
if conn_status = 0 then
set conn_status_msg to "Not Connected"
end if
I would prefer the list version.
For status numbers which are not available use an n/a entry
The first item in a list has the index 1, so you must add 1 to the number
set conn_list to {"Not Connected", "n/a", "Dialing", "n/a", "Connecting", "Error", "n/a", "Connected", "Disconnecting"}
set conn_status to item (conn_status + 1) of conn_list
Model: G5 dual 2,5 GHz
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
funny thing - compiling was fine but when building and running
I get an error message:
the variable conn_status_msg is not defined…
tell application "Internet Connect"
set conn_status to state fo status as string
if conn_status = 0 then
set conn_status_msg to "Not Connected"
else if conn_status = 1 then
set conn_status_msg to "Dialing"
end if
end tell
set content of text field "status" of window "main" to conn_status_msg