Announcement

Collapse
No announcement yet.

Can somone help explain why my VB program won't compile?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can somone help explain why my VB program won't compile?

    Hi all,

    I just figured I'd see if anyone here can help before I email my professor. I'm trying to follow the in-class example for the Excel based Visual Basic program I was given in class to try and figure out how to do the HW due next week.

    The problem is the class example the professor gave that I copied won't compile. I double checked to make sure I followed what was typed, and as far as I can tell, it is correct. However, the problem lies in that when I click to compile, it says:

    Compile Error:
    Invalid outside procedure

    The program is:

    Module1 - 1

    Function rhs(temp, ps)
    rhs = 23.75 - 0.25 * temp + 0.75 * Sqr(ps)
    End Function
    Sub rk4(temp, ps, dt)
    k1 = dt * rhs(temp, ps)
    k2 = dt * rhs(temp + k1 / 2, ps)
    k3 = dt * rhs(temp + k2 / 2, ps)
    k4 = dt * rhs(temp + k3, ps)
    temp = temp + (k1 + 2 * k2 + 2 * k3 + k4) / 6
    End Sub
    Sub main()
    steps = [b5]
    dt = [b6]
    ps = [b8]
    t = [a13]
    [a13].Select
    For i = 1 To steps
    t = t + dt
    Call rk4(temp, ps, dt)
    templin = 110 + 0.3 * (ps - 25) * (1 - Exp(-t / 4))
    ActiveCell.Offset(i, 0).Value = t
    ActiveCell.Offset(i, 1).Value = temp
    ActiveCell.Offset(i, 2).Value = templin
    Next
    End Sub


    I have all the variables specified on the Excel worksheet. Can anyone see what I'm missing?

    Thanks in advance.

    #2
    ah yes, visual basic.

    i remember taking Qbasic my freshman year in highschool, and was thinking about taking VB

    i remember my biggest problem was subroutines. make sure those are all correct.

    other than that. good luck with it bro.

    Claire - '92 Mercedes-Benz 500E - AMG&Bilstein Treatment - The Wolf in Sheep's clothing.

    Alice - '97 BMW 540i6 - Dinan Tuned. - Low Profile Weekend Warrior.

    Felicia - '11 Ford Fusion - Luxury Package - Daily.. daily.. ugh.


    Originally posted by JoshM
    Okay to do: "I'm sorry I broke your mailbox, here's $100.
    NOT okay to do: "I'm sorry I fucked your sister, here's $100.

    Comment


      #3
      I cant find anything wrong, but I only know C and C++
      To-Do List for Today
      Be Awesome

      Comment


        #4
        re: our aim convo


        - 1993 Accord LX - White sedan (sold)
        - 1993 Accord EX - White sedan (wrecked)
        - 1991 Accord EX - White sedan (sold)
        - 1990 Accord EX - Grey sedan (sold)
        - 1993 Accord EX - White sedan (sold)
        - 1992 Accord EX - White coupe (sold)
        - 1993 Accord EX - Grey coupe (stolen)
        - 1993 Accord SE - Gold coupe (sold)
        Current cars:
        - 2005 Subaru Legacy GT Wagon - Daily driver
        - 2004 Chevrolet Express AWD - Camper conversion

        Comment


          #5
          Back to life.

          I had to use the program mentioned above as the basis for a new program. I got the first one working fine with the help of Mike, but now I get "Invalid procedure call or argument." I have highlighted in red the line in question.

          Thanks

          Function rhs(height, valve)
          rhs = 0.125 - (0.25 * valve * Sqr(height))
          End Function
          Sub rk4(height, valve, dt)
          k1 = dt * rhs(height, valve)
          k2 = dt * rhs(height + k1 / 2, valve)
          k3 = dt * rhs(height + k2 / 2, valve)
          k4 = dt * rhs(height + k3, valve)
          height = height + (k1 + (2 * k2) + (2 * k3) + k4) / 6
          End Sub
          Sub main()
          steps = [b5]
          dt = [b6]
          valve = [b8]
          t = [a13]
          height = [b13]
          [a13].Select
          For i = 1 To steps
          t = t + dt
          Call rk4(height, valve, dt)
          ActiveCell.Offset(i, 0).Value = t
          ActiveCell.Offset(i, 1).Value = height
          Next
          End Sub

          Comment


            #6
            id try and help but i all i know is C++, and basic shit at that
            I <3 G60.

            0.5mm Oversized Stainless valves and bronze guides available. Pm me please.

            Comment


              #7
              Bump, it's the line in red that's messing it up.

              Comment

              Working...
              X