Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA - Getting values from dynamic array - does not show real number

Tags:

arrays

excel

vba

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.

like image 744
user1130306 Avatar asked Feb 09 '26 15:02

user1130306


1 Answers

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

like image 180
Abbas Avatar answered Feb 12 '26 15:02

Abbas