title: VBA: const parameter for a Sub - avoiding modification of the value of an argument passed by value
body: <p>I mean to pass a parameter to a VBA <code>Sub</code>, ensuring that it is not modified. I would do that in C as <code>void mysub( const int i );</code>.</p>
  
  <p>What is the recommended (i.e., simplest, most portable, etc.) way of achieving the same in VBA, if any?</p>
  
  <p><strong>The question is about item 3 below. There is an accepted answer, but the question is open to alternatives (there is likely no last word on this).</strong></p>
  
  <p><strong>EDIT</strong>
  Clarification of the equivalence in functionality VBA vs. C, needed as per answers and comments:</p>
  
  <ol>
  <li><p><strong>Passing by reference</strong>. <br>
  <em>In VBA</em>, <code>Sub mysub(i as Integer)</code> (the default, or <code>Sub mysub(ByRef i as Integer)</code>), which takes arguments by reference without "asking for permission" from the caller (who uses <code>Call mysub(j)</code>), has no exact equivalent in C.<br>
  <em>In C</em>, the closest would be <code>void mysub(int * i);</code>. But in C one would have to complement this with a call as <code>mysub(&amp;j);</code>, i.e., it is also up to the caller for this to work.<br>
  The <code>Sub</code> can modify the value of "the variable" (<code>i</code>, in VBA; <code>*i</code>, in C) inside the called <code>Sub</code>. If it does, it automatically modifies the value in the caller.</p></li>
  <li><p><strong>Passing by value</strong>. <br>
  <em>In VBA</em>, <code>Sub mysub(ByVal i as Integer)</code>, which takes arguments by value from the caller (who uses <code>Call mysub(j)</code>, without even knowing whether <code>mysub</code> takes <code>ByVal</code> or <code>ByRef</code>), corresponds to <br>
  <em>In C</em>, <code>void mysub(int i);</code>. <br>
  The <code>Sub</code> can modify the value of "the variable" (<code>i</code>, in VBA or C) inside the called <code>Sub</code>. If it does, it does not affect the value in the caller.</p></li>
  <li><p><strong>Passing by value, qualifying with <code>const</code></strong>. <br>
  <em>In C</em>, <code>void mysub(const int i);</code>. <br>
  The <code>Sub</code> cannot modify the value of "the variable" (<code>i</code>, in C) inside the called <code>Sub</code>. Of course, nothing happens to the value in the caller either. <br></p></li>
  </ol>