Changing "Missing Values" results

Howdy all,

I’m working on adding more goodies to my XTab application, but am running into a slight problem. For testing purposes, I created a tab file (an xml file) with some missing values, to see how the app would handle it. (Crash, Error, ect)
Well, it loads it just fine, but in the text fields, it displays , which is obviously not very good for the UI.

So, enter my script. This bit is meant to check to see if a particular variable returns a missing value, and if so, replace it with “Unknown”. However, it doesn’t appear to be picking up on that at all. I previously had a log function right before the repeat, to see exactly what was being returned, which did return a missing value.

on loadtab()
	try
		tell application "System Events" to tell contents of XML file tabfile
			set {songtitle, songartist, songalbum, tabber, difficulty, tabs} to value of XML elements of XML element "Tab"
		end tell
		repeat with i in {songtitle, songartist, songalbum, tabber, difficulty, tabs}
			if i = missing value then
				log "got missing value" --Lets see if it picked up the value
				set item i to "Unknown"
			end if
		end repeat
		tell window "XTab"
			set contents of text field "songfield" to songtitle
			set contents of text field "artistfield" to songartist
			set contents of text field "albumfield" to songalbum
			set contents of text field "tabber" to tabber
			set contents of text field "difficulty" to difficulty
			set contents of text view "tabs" of scroll view "tabscroll" to tabs
		end tell
	end try
end loadtab

As far as I know, this SHOULD work. However, the log is never triggering, so my script doesn’t appear to be picking up on the missing value. Any ideas?

Thanks!
-Parrot

set item i to "Unknown"

What is item i referring to? (item i of what?)

Also, that list you’re referring doesn’t exist after the repeat loop is finished.

Edit: Also, in your code, i is a reference to an item, not a number.

Edit: How about this?

tell application "System Events" to tell XML file tabFile
	set xmlValues to value of XML elements
end tell

count xmlValues
repeat with i from 1 to result
	if item i of xmlValues is missing value then set item i of xmlValues to "Unknown"
end repeat

xmlValues

Thanks! That’s got all that working.

I’m still curious how I should reference these, though. (I could be missing something. I’m not familliar with that final xmlValues used by itself at the end of the code) I need to have the individual results set to a variable so that I can use them later in the script (I.E play track songTitle in iTunes)

My goal is
1- set the value of each individual xml element to a variable
2- check and see if any of these variables are missing values. If so, replace the value of that variable with “Unknown”
3- set the contents of each text field to their respective variable

I’d presume there is a way to do that with your script, but I’ve still got a lot to learn, so it’s escaping me at the moment :stuck_out_tongue:

is it along the lines of


set fieldsList to {"SongTitle", "SongArtist", "SongAlbum", "Tabber", "Difficulty", "Tabs"}
repeat with i from 1 to result
 if item i of xmlValues is missing value then set item i of xmlValues to "Unknown"
set contents of text field (item i of list fieldsList) to (item i of list xmlValues)
end repeat

However, that doesn’t work. It doesn’t error, but it doesn’t work, either. (It also never sets the value to a variable, but this is kinda coming off the top of my head :P)

Any further help is much appreciated :stuck_out_tongue: This is proving to be trickier than I thought :stuck_out_tongue:
Thanks!
-Parrot

The only problem I see is that you don’t have a complete reference to the text field. Try something like this:

tell application "System Events" to tell XML file tabFile
	set xmlValues to value of XML elements
end tell

set fieldsList to {"SongTitle", "SongArtist", "SongAlbum", "Tabber", "Difficulty", "Tabs"}
count fieldsList

repeat with i from 1 to result
	if item i of xmlValues is missing value then set item i of xmlValues to "Unknown"
	tell text field (item i of list fieldsList) of window "main" to set contents to (item i of list xmlValues)
end repeat

Note: I use tell text field just because I prefer to read it that way; This should work too:

set contents of text field (item i of list fieldsList) of window "main" to (item i of list xmlValues)