Announcement

Collapse
No announcement yet.

Help with VBASIC!

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

  • #16
    Now I remember what was a problem. Z needs to be defined for each subsequent sub. So having each sub have Z = 10, means it doesn't progress. If I don't define Z for each subroutine, it will not run.
    "Flutie was better than Kelly, Elway, Esiason and Cunningham." - Ben Kenobi
    "I have nothing against Wilson, but he's nowhere near the same calibre of QB as Flutie. Flutie threw for 5k+ yards in the CFL." -Ben Kenobi

    Comment


    • #17
      Originally posted by loinburger View Post
      I just noticed that you're referencing Z inside of the A/B/C subroutines, but your Z from the test subroutine isn't visible there - I have no idea what your program is using there, probably some global variable floating around somewhere. Two options to fix this:

      1. Pass in Z as a parameter to the subroutines
      2. Turn the A/B/C subroutines into functions that return their string (e.g. "Execute A"), then have the test subroutine call the function and use the returned string in the assignment
      I never opened the developer tab in Excel until two business days ago. It sounds like those things would be good ideas but I have no idea what the syntax is for stuff like that.

      The Z is just the 10th row on an excel spreadsheet after some headers, a button, etc.
      "Flutie was better than Kelly, Elway, Esiason and Cunningham." - Ben Kenobi
      "I have nothing against Wilson, but he's nowhere near the same calibre of QB as Flutie. Flutie threw for 5k+ yards in the CFL." -Ben Kenobi

      Comment


      • #18
        Code:
        Sub test()
        
        Z = 10
        Do Until IsEmpty(Cells(Z, 1))
            If Cells(Z, 2) = "A" Then
                Call A(Z)
            ElseIf Cells(Z, 2) = "B" Then
                Call B(Z)
            ElseIf Cells(Z, 2) = "C" Then
                Call C(Z)
            End If
        Z = Z + 1
        Loop
        
        End Sub
        
        Sub A(Z As Integer)
              Cells(Z, 3) = "Execute A"
        End Sub
        
        Sub B(Z As Integer)
              Cells(Z, 3) = "Execute B"
        End Sub
        
        Sub C(Z As Integer)
              Cells(Z, 3) = "Execute C"
        End Sub
        I haven't used VB in about ten years, but the syntax should be something like that
        <p style="font-size:1024px">HTML is disabled in signatures </p>

        Comment


        • #19
          "ByRef Argument Type Mismatch" on the Z on Call A(Z)
          "Flutie was better than Kelly, Elway, Esiason and Cunningham." - Ben Kenobi
          "I have nothing against Wilson, but he's nowhere near the same calibre of QB as Flutie. Flutie threw for 5k+ yards in the CFL." -Ben Kenobi

          Comment


          • #20
            Change the three instances of "Z As Integer" to "ByVal Z As Integer" - apparently VBA passes by reference by default
            <p style="font-size:1024px">HTML is disabled in signatures </p>

            Comment


            • #21
              That worked. Thank you. It'll be a lot easier to manipulate now. Having 8 different sets of conditional actions nested into a single subroutine was ridiculous and I had only covered Spots, Forwards, and Hedges!

              Now since the Hedges are going to run either the spot procedures (depending on currency type) or the forwards (depending on currency type) depending on whether the settle date minus trade date <= 3, I would like to have a subroutine for hedges then do either the spot or the forward subroutines.

              This seems to work:

              Code:
              Sub test()
              
              Z = 10
              Do Until IsEmpty(Cells(Z, 1))
                  If Cells(Z, 2) = "Spot" Then
                      Call Spot(Z)
                  ElseIf Cells(Z, 2) = "Forward" Then
                      Call Forward(Z)
                  ElseIf Cells(Z, 2) = "Hedge" Then
                      Call Hedge(Z)
                  End If
              Z = Z + 1
              Loop
              
              End Sub
              
              Sub Spot(ByVal Z As Integer)
                    Cells(Z, 3) = "Execute Spot"
              End Sub
              
              Sub Forward(ByVal Z As Integer)
                    Cells(Z, 3) = "Execute Forward"
              End Sub
              
              Sub Hedge(ByVal Z As Integer)
                  If Cells(Z, 4) = "3" Then
                      Call Spot(Z)
                  Else
                      Call Forward(Z)
                  End If
              End Sub
              "Flutie was better than Kelly, Elway, Esiason and Cunningham." - Ben Kenobi
              "I have nothing against Wilson, but he's nowhere near the same calibre of QB as Flutie. Flutie threw for 5k+ yards in the CFL." -Ben Kenobi

              Comment


              • #22
                This isn't a [civil] thread, so alby, go eat your own ****

                Sent from my XT1254 using Tapatalk
                To us, it is the BEAST.

                Comment


                • #23
                  Originally posted by Sava View Post
                  This isn't a [civil] thread, so alby, go eat your own ****
                  And get your indentations fixed
                  With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

                  Steven Weinberg

                  Comment


                  • #24
                    Relax. It's not like he's scripting in Python.
                    “It is no use trying to 'see through' first principles. If you see through everything, then everything is transparent. But a wholly transparent world is an invisible world. To 'see through' all things is the same as not to see.”

                    ― C.S. Lewis, The Abolition of Man

                    Comment


                    • #25
                      Doing that would probably drive him crazy.

                      I just consider proper indentation one of those small habits that makes life easier for everyone
                      With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

                      Steven Weinberg

                      Comment


                      • #26
                        I do too, but requiring it as part of the language is a bit much for me.
                        “It is no use trying to 'see through' first principles. If you see through everything, then everything is transparent. But a wholly transparent world is an invisible world. To 'see through' all things is the same as not to see.”

                        ― C.S. Lewis, The Abolition of Man

                        Comment


                        • #27
                          It's far from the biggest problem I have with python. Granted I like python but it loses a lot of its charm when your project starts to involve more than maybe 3 people.
                          If there is no sound in space, how come you can hear the lasers?
                          ){ :|:& };:

                          Comment


                          • #28
                            Originally posted by BlackCat View Post
                            Doing that would probably drive him crazy.

                            I just consider proper indentation one of those small habits that makes life easier for everyone
                            Indentation is the Alpha and Omega for proper readability ... especially for longer functions/classes
                            Tamsin (Lost Girl): "I am the Harbinger of Death. I arrive on winds of blessed air. Air that you no longer deserve."
                            Tamsin (Lost Girl): "He has fallen in battle and I must take him to the Einherjar in Valhalla"

                            Comment


                            • #29
                              Given Albie's penchant for sharing potentially classified information, I half expected the code he was going to post was related to missile guidance systems or Stuxnet or some such.
                              One day Canada will rule the world, and then we'll all be sorry.

                              Comment


                              • #30
                                Considering his security clearance level he probably have
                                With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

                                Steven Weinberg

                                Comment

                                Working...
                                X