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.
Announcement
Collapse
No announcement yet.
Help with VBASIC!
Collapse
X
-
Originally posted by loinburger View PostI 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
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
-
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
<p style="font-size:1024px">HTML is disabled in signatures </p>
Comment
-
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
-
Originally posted by Sava View PostThis isn't a [civil] thread, so alby, go eat your own ****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
-
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
-
Doing that would probably drive him crazy.
I just consider proper indentation one of those small habits that makes life easier for everyoneWith 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
-
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
-
Originally posted by BlackCat View PostDoing that would probably drive him crazy.
I just consider proper indentation one of those small habits that makes life easier for everyoneTamsin (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
-
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
Comment