Hello all,

I am very new to visual basic, I started codeing at the beginning of this semester so bare with me.

Main goal of this post:
Create an array for a table of properties of my gas
Have my program read a temperature value input by the user
Find the values below it and above it (if the temperature given does not fall on a temperature in my chart)
Interpolate to find a value under my specific volume colomn.

I will post my code so far and my table for carbon dioxide.

Private Sub Command1_Click()
Dim x1 As Double
Dim x2 As Double
Dim y1 As Double
Dim y2 As Double
Dim zt As Variant
Dim zv As Variant
Dim a As Double
Dim b As Double
Dim c As Double
Dim d As Double
Dim ab As Double
Dim abc As Double




x1 = Text1.Text
zt = Text2.Text
x2 = Text3.Text
'these x,y,z variables cordinate with the order on the form
y1 = Text4.Text
zv = Text5.Text
y2 = Text6.Text


If zv = "" Then
'to find specific volume
    For i = 0 To 36
    If Abs(carbondioxidetemp(i, 0) - zt) < 1 Then
        'trying to find the value above and below the given value on my array
        x1 = carbondioxide(i, 0)
        a = zt - x1
        b = x2 - x1
        c = y2 - y1
        ab = a / b
        abc = ab * c
        zv = abc + y1
    Text5.Text = zv
    Else
    Loop
Else
'to find temperature
    a = zv - y1
    b = y2 - y1
    c = x2 - x1
    ab = a / b
    abc = ab * c
    zt = abc + x1
    Text2.Text = zt
End If
End Sub

I have stored my array of table values in a module but nothing works.

Public carbondioxidetemp(i, i) As Double 'celsius
Public carbondioxidevap(i, i) As Double '(m^3/kg)

'Carbon dioxide temperature column (celsius)
carbondioxidetemp(0, 0) = -20
carbondioxidetemp(1, 0) = -19
carbondioxidetemp(2, 0) = -18
carbondioxidetemp(3, 0) = -17
carbondioxidetemp(4, 0) = -16
carbondioxidetemp(5, 0) = -15
carbondioxidetemp(6, 0) = -14
carbondioxidetemp(7, 0) = -12
carbondioxidetemp(8, 0) = -10
carbondioxidetemp(9, 0) = -8
carbondioxidetemp(10, 0) = -6
carbondioxidetemp(11, 0) = -4
carbondioxidetemp(12, 0) = -2
carbondioxidetemp(13, 0) = 0
carbondioxidetemp(14, 0) = 2
carbondioxidetemp(15, 0) = 4
carbondioxidetemp(16, 0) = 5
carbondioxidetemp(17, 0) = 7
carbondioxidetemp(18, 0) = 9
carbondioxidetemp(19, 0) = 11
carbondioxidetemp(20, 0) = 13
carbondioxidetemp(21, 0) = 15
carbondioxidetemp(23, 0) = 17
carbondioxidetemp(24, 0) = 19
carbondioxidetemp(25, 0) = 20
carbondioxidetemp(26, 0) = 21
carbondioxidetemp(27, 0) = 22
carbondioxidetemp(28, 0) = 23
carbondioxidetemp(29, 0) = 24
carbondioxidetemp(30, 0) = 25
carbondioxidetemp(31, 0) = 26
carbondioxidetemp(32, 0) = 27
carbondioxidetemp(33, 0) = 28
carbondioxidetemp(34, 0) = 29
carbondioxidetemp(35, 0) = 30
carbondioxidetemp(36, 0) = 30.978



'Carbon Dioxide Specific Volume as a vapor column (m^3/kg)
carbondioxidevap(0, 1) = 0.019343
carbondioxidevap(1, 1) = 0.018726
carbondioxidevap(2, 1) = 0.018131
carbondioxidevap(3, 1) = 0.017557
carbondioxidevap(4, 1) = 0.017002
carbondioxidevap(5, 1) = 0.016467
carbondioxidevap(6, 1) = 0.01595
carbondioxidevap(7, 1) = 0.014967
carbondioxidevap(8, 1) = 0.014048
carbondioxidevap(9, 1) = 0.013188
carbondioxidevap(10, 1) = 0.012381
carbondioxidevap(12, 1) = 0.011624
carbondioxidevap(13, 1) = 0.010911
carbondioxidevap(14, 1) = 0.010241
carbondioxidevap(15, 1) = 0.009609
carbondioxidevap(16, 1) = 0.009011
carbondioxidevap(17, 1) = 0.008724
carbondioxidevap(18, 1) = 0.008174
carbondioxidevap(19, 1) = 0.007651
carbondioxidevap(20, 1) = 0.007153
carbondioxidevap(21, 1) = 0.006677
carbondioxidevap(23, 1) = 0.006222
carbondioxidevap(24, 1) = 0.005783
carbondioxidevap(25, 1) = 0.005358
carbondioxidevap(26, 1) = 0.005149
carbondioxidevap(27, 1) = 0.004943
carbondioxidevap(28, 1) = 0.004738
carbondioxidevap(29, 1) = 0.004533
carbondioxidevap(30, 1) = 0.004327
carbondioxidevap(31, 1) = 0.00412
carbondioxidevap(32, 1) = 0.003908
carbondioxidevap(33, 1) = 0.00369
carbondioxidevap(34, 1) = 0.003459
carbondioxidevap(35, 1) = 0.003205
carbondioxidevap(36, 1) = 0.002898
carbondioxidevap(37, 1) = 0.002139

I will be watching this post carefully so let me know if I need to give anymore info or if I am not clear on anything. Thanks in advance

I have also found this if it helps.

The formula for interpolation is straight forward, assuming your values are in X(i) in sorted order and Y(i) corresponds to X(i), Y(i) = Y(i-1) + (X(i) - X(i-1))*(Y(i+1) - Y(i-1))/(X(i+1) - X(i-1)), where the values of both X and Y are known at i-1 and i+1.

Member Avatar for Lee Chetwynd

I don't really know anything about the temperature of carbon dioxide :-)
I'm not sure you need 2 dimensional arrays from what I could tell you are only using one of the dimensions. You seem to be trying to declare them with a variable (i) as well, unless I'm missing something I don't think this is possible. Does this compile? You either need to declare the array with a value for the number of elements in brackets or empty brackets and then use redim.

I think that maybe you could have declared the arrays like this:

Public carbondioxidevap(37) As Double

instead of:

Public carbondioxidevap(i, i) As Double

Also on line 32 I think you have a typo as you are refering to an array (carbondioxide) that is not declared.

When you are getting the values from the text boxes it would probably be a good idea to add some validation as in its current state a non numeric entry will crash the program.

Try and provide any error messages you get if you are still struggling.

Member Avatar for Lee Chetwynd

You are also missing an endif.

@ Lee

Hey man thanks alot for responding. I have decided to go another route on this project and am not sure of I can close this thread. But... I relized after I posted that I didnt need a 2D array. I am now takeing a very different route.

@administrators

you can close this thread. It was a poorly attempted question and only supports my claim at being new to programming.

Thanks for the help

Member Avatar for Lee Chetwynd

No worries. We all start somewhere.

@ Lee

Hey man thanks alot for responding. I have decided to go another route on this project and am not sure of I can close this thread. But... I relized after I posted that I didnt need a 2D array. I am now takeing a very different route.

@administrators

you can close this thread. It was a poorly attempted question and only supports my claim at being new to programming.

Thanks for the help

Just mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.