title: Controlling Program Flow Between VB and C++
body: <p>I have a program that runs from VB/Excel and executes a C++ program in the middle of it.  I have two (I think related) questions:</p>
  
  <ol>
  <li><p>I capture the return value from the C++ program when it executes, but the number I get isn't zero (it's a 4-digit integer value instead, sample values I've received are 8156, 5844, 6100, 5528).  I am certain the program exits normally with code 0, but I think VB is getting its value before the C++ program has completed its execution - would that explain why I am not getting a value of zero, and how I can get the final, correct return value from my C++ program?</p></li>
  <li><p>[Probably as a solution to #1] How can I make the VB program "pause" until the C++ model has completed its execution?  I need to do some additional VB work (output configuration based on the C++ model run) once the model is complete</p></li>
  </ol>
  
  <p>Here is my VB code for how the model call.  I am running a full-compiled C++ program through the windows shell.</p>
  
  <pre><code>'---------------------------------------------------------
  ' SECTION III - RUN THE MODEL AS C++ EXECUTABLE
  '---------------------------------------------------------
  Dim ModelDirectoryPath As String
  Dim ModelExecutableName As String
  Dim ModelFullString As String
  Dim ret As Long
  
  ModelDirectoryPath = Range("ModelFilePath").value
  ModelExecutableName = Range("ModelFileName").value
  ModelFullString = ModelDirectoryPath &amp; ModelExecutableName
  
  ' Call the model to run
  Application.StatusBar = "Running C Model..."
  ModelFullString = ModelFullString &amp; " " &amp; ScenarioCounter &amp; " " &amp; NumDeals _
                &amp; " " &amp; ModelRunTimeStamp
  ret = Shell(ModelFullString)
  
  ' Add error checking based on return value
  ' This is where I want to do some checks on the return value and then start more VB code
  </code></pre>