Javrel

Field calculator problem splitting string, type mismatch

Discussion created by Javrel on Dec 6, 2011
Im using ARCGIS 9.3.1 so I think Im using VB rather than python but this seemed the most appropriate forum I could find

Im trying to split a string then build a statement converting the numbers to colours (S57 Data).

I keep getting a type mismatch error but Im unsure why, [colour] is a string field with values such as "6,2,6", "2,6,2", "2,6", "1", "5"
I cant seem to find the cause of my error I believe its falling over at the line with the split statement.

-----------------------------------------

Dim value, colarray(), tmp, count, colbuild

If instr([COLOUR],",") then
    msgbox [COLOUR]
    colarray = split([COLOUR],",")
    Count = 1
    For Each tmp In colarray
      If tmp = "1" THEN tmp = "White"
      If tmp = "2" THEN tmp = "black"
      If tmp = "3" THEN tmp = "red"
      If tmp = "4" THEN tmp = "green"
      If tmp = "5" THEN tmp = "blue"
      If tmp = "6" THEN tmp = "yellow"
      If tmp = "7" THEN tmp = "grey"
      If tmp = "8" THEN tmp = "brown"
      If tmp = "9" THEN tmp = "amber"
      If tmp = "10" THEN tmp = "voilet"
      If tmp = "11" THEN tmp = "orange"
      If tmp = "12" THEN tmp = "magenta"
      If tmp = "13" THEN tmp = "pink"
      If count = 1 then colbuild = tmp
      If count > 1 then colbuild = (colbuild+", "+tmp)
      count = count + 1
    Next
    value = colbuild
End If
If ([COLOUR] = "1") THEN Value = "White"
If ([COLOUR] = "2") THEN Value = "black"
If ([COLOUR] = "3") THEN Value = "red"
If ([COLOUR] = "4") THEN Value = "green"
If ([COLOUR] = "5") THEN Value = "blue"
If ([COLOUR] = "6") THEN Value = "yellow"
If ([COLOUR] = "7") THEN Value = "grey"
If ([COLOUR] = "8") THEN Value = "brown"
If ([COLOUR] = "9") THEN Value = "amber"
If ([COLOUR] = "10") THEN Value = "voilet"
If ([COLOUR] = "11") THEN Value = "orange"
If ([COLOUR] = "12") THEN Value = "megenta"
If ([COLOUR] = "13") THEN Value = "pink"

any help would be very appreciated as this has been bugging me all day.

Thanks

Outcomes