cast issue

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,

Pow wants doubles but i and j are integers :

Math.Pow(i, j)

i've tried directcast(i, double) but it says Directcast operand must
have a reference type but Integer is a value type.
How can I overcome this ?

thx
 
Sam,

One way is to use VB's convert to double function:

Math.Pow(CDbl(i), CDbl(j))

Kerry Moorman
 
Math.Pow(CDbl(2), CDbl(i))

This does not work : option strict on disallows implicit conversions
from Double to Long
 
Sam,

It sounds like you are trying to assign the result from Math.Pow to a long.
With option strict on, you will need to convert the result to a long:

Dim i As Integer = 2
Dim j As Integer = 2
Dim k As Long

k = CLng(Math.Pow(CDbl(i), CDbl(j)))

Kerry Moorman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top