Type mismatch

Hello,

I got error message when I run the coding below, score is a number list, holding the value like this “0” “3” “-1”, sometime hotding the value like this 0 3 -1.

I 'd apprecaite for any help.

Thanks

Linda

If Isnumeric(score(i+1)) Then

		If score(i+1)<0 Then

			minid = doc.GetItemValue(strd)(0)

		End If

	Else

		If score(i+1)<>"" Then

			If Cint(score(i+1))<0 Then

				minid = doc.GetItemValue(strd)(0)

			End If

		End If

	End If

Subject: Type mismatch

The first tip I would suggest is to make sure your code stores values consistently. Either store numbers as numbers (preferable) or store them always as text (knowing that if you need to do math operations on them, you will need to convert them to numbers).

Next,

IsNumeric is not really a valid test for what you are trying to accomplish. From Designer Help:

=========================================

The IsNumeric function returns TRUE (-1) if the value of expr is a numeric value or can be converted to a numeric value. The following values are numeric:

Integer

Long

Single

Double

Currency

Date/Time

EMPTY

String (if interpretable as number)

OLE error

Boolean (TRUE, FALSE)

=========================================

What you can do is always apply CInt() to any value - if already an integer, it won’t matter and if String (unless “”), it will be converted to a number (at least within your scenario).

So, I would first check if the CStr() is “” and if not, apply CInt().

That should solve the problem. Sorry I can’t help further because I could quite understand what your code was supposed to be doing - I’m offering suggestions on how to compare numbers and strings only.

Subject: RE: Type mismatch

Hi Cesar, Your suggestions are really halpful. I just chnaged the coding as you said, if the CStr() is “” and if not, apply CInt().

But there is an another error message “Subscript out of rang”,

Do you have any ideas about it? I am a really lowly developer.

Many thanks for your kindness.

Linda

Subject: RE: Type mismatch

Subscript out of range errors occur when you try to index into an array using an index value not contained within the array.

I would guess that your i+1 is causing that - somehow by adding one, you are trying to access an array element beyond the highest numbered element.

You should look into help for UBound function to see if that can help you resolve the problem. Again, not really sure what the code is trying to do here so I can be of little help for the logic part.

Subject: RE: Type mismatch

Hi Cesar, Indeed, there are many i+1 in the coding to retrieve items from array, I will check that.

Many many thanks for your valuable helps and kindness.

Linda :slight_smile: