Results 1 to 6 of 6

Thread: Solved: VBA function procedure homework help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Oct 2012
    Location
    WV
    Posts
    10
    Location

    Solved: VBA function procedure homework help

    [VBA][/VBA]I need help with an assignment I've been working on. I feel like I'm completely lost on this. It's driving me crazy.

    The assignment states:

    "Create a VBA function procedure called R_K to evaluate the Redlich-Kwong equation of state given in problem 11 on page 327 (attached jpg). Note that there is confusion in the text between v (lowercase) and V (uppercase). All instances should be v, with units of L/mole. Do not use the values of T and v given in the problem statement; those should be a function arguments so the user can choose values. Remember that a function procedure must be stored in a standard module in order to be executed from the Excel worksheet."

    The instructor is a little off his rocker and over half the class has dropped so far (9 weeks in). Any help would be greatly appreciated!!

    This is my code plus I have a chart for the data in excel:

    [VBA]Option Explicit
    Type CompoundData
    compound As String
    ctemp As Double
    cpres As Double
    End Type
    Sub temp_press_data()
    Dim RK(4) As CompoundData
    RK(1).compound = "Methane"
    RK(1).ctemp = 190.6
    RK(1).cpres = 45.4
    RK(2).compound = "Ethylene"
    RK(2).ctemp = 282.4
    RK(2).cpres = 49.7
    RK(3).compound = "Nitrogen"
    RK(3).ctemp = 126.2
    RK(3).cpres = 33.5
    RK(4).compound = "Water (vapor)"
    RK(4).ctemp = 647.1
    RK(4).cpres = 217.6
    Call R_K
    End Sub
    Public Function R_K()
    Dim R As Double, T As Double, P As Double, V As Double, a As Double, b As Double, x As Integer
    Dim RK(4) As CompoundData
    x = InputBox("Please select a compound from the chart")
    T = InputBox("Please enter temperature (K)")
    V = InputBox("Please enter volume (L)")
    R = 0.08205
    If x = 1 Then
    a = 0.427 * (((R ^ (2)) * (RK(1).ctemp ^ (2.5)) / (RK(1).cpres)))
    b = 0.0866 * R * ((RK(1).ctemp) / (RK(1).cpres))
    P = ((R * T) / (V - b)) - ((a) / (V * (V + b) * Sqr(T)))
    ElseIf x = 2 Then
    a = 0.427 * (((R ^ (2)) * (RK(2).ctemp ^ (2.5)) / (RK(2).cpres)))
    b = 0.0866 * R * ((RK(2).ctemp) / (RK(2).cpres))
    P = ((R * T) / (V - b)) - ((a) / (V * (V + b) * Sqr(T)))
    ElseIf x = 3 Then
    a = 0.427 * (((R ^ (2)) * (RK(3).ctemp ^ (2.5)) / (RK(3).cpres)))
    b = 0.0866 * R * ((RK(3).ctemp) / (RK(3).cpres))
    P = ((R * T) / (V - b)) - ((a) / (V * (V + b) * Sqr(T)))
    Else
    a = 0.427 * (((R ^ (2)) * (RK(4).ctemp ^ (2.5)) / (RK(4).cpres)))
    b = 0.0866 * R * ((RK(4).ctemp) / (RK(4).cpres))
    P = ((R * T) / (V - b)) - ((a) / (V * (V + b) * Sqr(T)))
    End If
    End Function
    [/VBA]
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •