Error: Disallows implicit conversions from Double to Integer

I’m not sure why I’m getting this error message. They all appear to be Integers. I don’t know why it’s saying there is a double. Here is the full error message.

Error compiling code - error BC30512: Option Strict On disallows implicit conversions from 'Double to ‘Integer’ at line 3

  1. StatusMessage = MessageArray(0)

  2. Dim two As Integer = 2

  3. Dim len As Integer = StatusMessage.Length / two

  4. StatusMessage = StatusMessage.Substring(0, len)

I’m using invoke code method. I have imported into the invoke code method, an array of string, and All I’m trying to do is cut the string in half. The string I’m trying to cut in half is located in the zero index of the array. StatusMessage.Length should return an Integer. I’ve declared two as an Integer, and also len. Where or what’s up with the double… I’m not seeing any doubles.

1 Like

Anytime you do a division, it gives back a Double type. Since len is an Integer, you just need to convert the division to an integer.

len = CInt( StatusMessage.Length / two )

Keep in mind, however, that doing this will drop the decimal off. So, if dividing is 1.5, Cint(1.5) = 1, not 2
To round it up, you need to use Math.Round() I think, then also convert that to an integer with CInt()

Hope I was clear in explaining that.

Regards.

5 Likes

Thank you Clayton! I was wracking my brain… Like these are all Integers! Where is this double coming from!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.