none
VBA Excel Arrays; declaration, assignment and initiation

    Question

  • Hello

    Can anybody help me with that piece of code?

    I would like to get the following array: (N2, 126.2, 0.313), but a run time error is popups ("subscript out of range").

    Thanks in advanced,

    Avi

    Option Explicit
    Option Base 1
    Private x As Variant
    Sub Viscosity_Calc()
    
    Dim A(1, 1, 1) As Variant
    Dim Gas_matrix As Variant
    Dim Gas_type As Variant
    Dim Critical_Temp As Variant
    Dim Critical_Density As Variant
    
    Gas_type = Array("N2", "Ar", "O2", "Air") 'Gas List
    
    Critical_Temp = Array(126.2, 150.6, 154.5, 132.5) '[K] Temp. at critical point
    
    Critical_Density = Array(0.313, 0.531, 0.436, 0.316) '[g/ml] Density at critical point
    
    Gas_matrix = Array(Gas_type, Critical_Temp, Critical_Density)
    
    
    A(1, 1, 1) = Array(Gas_matrix((1), (1), (1)))
    End Sub
    


    Avi Reches

    Thursday, April 26, 2012 4:21 PM

Answers

  • On Thu, 26 Apr 2012 16:21:08 +0000, Reches wrote:
     
    >
    >
    >Hello
    >
    >Can anybody help me with that piece of code?
    >
    >I would like to get the following array: (N2, 126.2, 0.313), but a run time error is popups ("subscript out of range").
    >
    >Thanks in advanced,
    >
    >Avi Option Explicit
    >Option Base 1
    >Private x As Variant
    >Sub Viscosity_Calc()
    >
    >Dim A(1, 1, 1) As Variant
    >Dim Gas_matrix As Variant
    >Dim Gas_type As Variant
    >Dim Critical_Temp As Variant
    >Dim Critical_Density As Variant
    >
    >Gas_type = Array("N2", "Ar", "O2", "Air") 'Gas List
    >
    >Critical_Temp = Array(126.2, 150.6, 154.5, 132.5) '[K] Temp. at critical point
    >
    >Critical_Density = Array(0.313, 0.531, 0.436, 0.316) '[g/ml] Density at critical point
    >
    >Gas_matrix = Array(Gas_type, Critical_Temp, Critical_Density)
    >
    >
    >A(1, 1, 1) = Array(Gas_matrix((1), (1), (1)))
    >End Sub
    >
    >
    >
    >
    >
    >
    >Avi Reches
     
     
    A(1, 1, 1) = Array(Gas_matrix(1)(1), Gas_matrix(1)(1), Gas_matrix(1)(1))
     
     

    Ron
    • Marked as answer by Reches Friday, April 27, 2012 10:16 PM
    Friday, April 27, 2012 9:33 AM

All replies

  • try asking in the vba forum:

    http://social.msdn.microsoft.com/forums/en/isvvba/threads


    thanks for any help

    Thursday, April 26, 2012 10:50 PM
  • On Thu, 26 Apr 2012 16:21:08 +0000, Reches wrote:
     
    >
    >
    >Hello
    >
    >Can anybody help me with that piece of code?
    >
    >I would like to get the following array: (N2, 126.2, 0.313), but a run time error is popups ("subscript out of range").
    >
    >Thanks in advanced,
    >
    >Avi Option Explicit
    >Option Base 1
    >Private x As Variant
    >Sub Viscosity_Calc()
    >
    >Dim A(1, 1, 1) As Variant
    >Dim Gas_matrix As Variant
    >Dim Gas_type As Variant
    >Dim Critical_Temp As Variant
    >Dim Critical_Density As Variant
    >
    >Gas_type = Array("N2", "Ar", "O2", "Air") 'Gas List
    >
    >Critical_Temp = Array(126.2, 150.6, 154.5, 132.5) '[K] Temp. at critical point
    >
    >Critical_Density = Array(0.313, 0.531, 0.436, 0.316) '[g/ml] Density at critical point
    >
    >Gas_matrix = Array(Gas_type, Critical_Temp, Critical_Density)
    >
    >
    >A(1, 1, 1) = Array(Gas_matrix((1), (1), (1)))
    >End Sub
    >
    >
    >
    >
    >
    >
    >Avi Reches
     
     
    A(1, 1, 1) = Array(Gas_matrix(1)(1), Gas_matrix(1)(1), Gas_matrix(1)(1))
     
     

    Ron
    • Marked as answer by Reches Friday, April 27, 2012 10:16 PM
    Friday, April 27, 2012 9:33 AM
  • Thanks Ron.

    Reches

    Saturday, April 28, 2012 5:31 AM
  • On Sat, 28 Apr 2012 05:31:11 +0000, Reches wrote:
     
    >Thanks Ron.
    >
    >
     
    You're welcome.  Glad to help.
     

    Ron
    Saturday, April 28, 2012 11:04 AM