Suppressing msg error "wrong string value" or "maybe too large for the field"

447
3
10-30-2012 05:00 AM
LeandroNovaes
New Contributor
Hi everyone, this is my first post here, but I am an enthusiast of ESRI Forums since Arcgis 3.x! :cool:

I am doing some calculations with some shapefiles, but sometimes I am receiving the annoying message: [ATTACH=CONFIG]18833[/ATTACH], showing the error message "value may be too large for the field" or "trying to add a string to a number field".

Ok, the destination field type is 'DATE' and I know that the results COULD BE COME in string. Because of that, I wrote an "else" in the codeblock (bellow) to avoid this kind of error, but isn't working!

[INDENT]Dim MyCode
If [DATEFIELD] <> "STRING TEXT" Then
MyCode = [DATEFIELD]
Else
MyCode = null
End if[/INDENT]

Anyone knows how to prevent this warning messages or can help to improve my simples codeblock to avoid that messages?
Tags (2)
0 Kudos
3 Replies
KevinDunlop
Occasional Contributor III
Try

Dim MyCode
If TypeOf [DATEFIELD] Is Not String Then
MyCode = [DATEFIELD]
Else
MyCode = null
End if

You might need to do:

Dim MyCode
If TypeOf [DATEFIELD].value Is Not String Then
MyCode = [DATEFIELD]
Else
MyCode = null
End if
0 Kudos
LeandroNovaes
New Contributor
I am sorry but this code won't work.

In my particularly case, I have to transfer part of string field Left ([TEXTFIELD],10) to a date field type [DATEFIELD].

For example:
[INDENT][TEXTFIELD] Line 1 = "10/10/2012 - Date of Pay Stuff"
[TEXTFIELD] Line 2 = "Uncompleted"[/INDENT]

Codeblock:
[INDENT]Dim MyCode
If [TEXTFIELD] <> "Uncompleted" Then
MyCode = Left ([TEXTFIELD],10)
Else
MyCode = null
End if
[/INDENT]

Result:
[INDENT]Line 1: 10/10/2012
Line 2: > msg error <[/INDENT]
0 Kudos
MarcinGasior
Occasional Contributor III
I've run exactly the same code as you and get no error. Look at the screenshot:
[ATTACH=CONFIG]18878[/ATTACH]

What ArcGIS wersion and which service pack are you using. I've seen some problems with 'null' in ArcGIS 10 pre-sp4 configurations.

Btw, you can try with Python code. Here's an example which works for me:
Codeblock:
def calDate(text):
  if text <> "Uncompleted":
    return text[:10]
  else:
    return None

Datefield =
calDate(!TEXTFIELD!)
0 Kudos