Pregunta

In this particular code I'm trying to test if a double meets a certain condition. This double is generated by converting an input from a recordset (which should be a string) to a double.

Below is the code in question:

Do Until SampleTable.EOF
If (isCancer(convertValuetoNumeric(SampleTable![Value]))) Then
    'Some stuff done here
    '...
End If

I get an "Compile Error: Type Mismatch" error with my convertValuetoNumeric method highlighted. Now the input is highly normalized so I know that any string passed to the convert method will return as a double. I believe the error is from either the fact that the argument passed to convertValuetoNumeric is already a double or because that calling data from the table is return a RecordSet object and not a String as I am expecting.

Below is the conversion code:

Function convertValuetoNumeric(ICD As String) As Double
 If IsNumeric(ICD) Then
     convertValuetoNumeric = CDbl(ICD)
 Else
     convertValuetoNumeric = CDbl(Replace(ICD, "V", "99")) 'Replace V with 99 and convert
 End If
 End Function

The input would either be a double (e.g. 1000.5) or a double with a V preceding it (e.g. V100000.5). The program would either return the variable as a double unchanged or with as a double with a 99 at the front of it. No input would ever break those two scenarios.

EDIT: Even changing the method signature of convertValuetoNumeric() to accept a variable of type Variant instead of String does nothing to fix the error.

¿Fue útil?

Solución

Why not use Variant ICD that will be valid in both VBA and VBScript:

Function convertValuetoNumeric(ByVal ICD) As Double
  If IsNumeric(ICD) Then
     convertValuetoNumeric = CDbl(ICD)
  Else
    convertValuetoNumeric = CDbl(Replace(ICD, "V", "99")) 'Replace V with 99 and convert
  End If
End Function

And in the call:

Do Until SampleTable.EOF
  If (isCancer(convertValuetoNumeric(SampleTable![Value].Value))) Then
      'Some stuff done here
      '...
  End If
....

I suppose that [Value] is the column name.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top