3

Here is some code which shows the problem I am having:

Sub main()
    Dim V() As Long, x As Integer, temp As Long

    x = 5

    ReDim V(1 To x)

    V(4) = 0.65
    temp = V(4)

    MsgBox (temp) ' Returns value of 1
End Sub

I would like the variable temp to take in value: 0.65, but it always shows a value of 1. I am not sure what I am missing. Any help is greatly appreciated.

2 Answers 2

2

You have declared Dim V() As Long. This means it takes in only integers. Change it to Double.

Sign up to request clarification or add additional context in comments.

Comments

0

temp & V are Long integers so cannot represent floating point numbers like 0.65, simply change their type to Double which can.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.