Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are misusing the IIf function. <strong>Syntax, IIf(expr, truepart, falsepart)</strong>. Your statement checks for a backslash and if the last character is "\", sets your variable to an empty string. But the false part sets the variable to "\" if it is not the last character in your path. For example, if App.Path = <em>C:\MyApplication</em> your IIF function would set strBackSlash = "\" and strEmpFileName will be <em>C:\MyApplication\\SOURCE\SWA.exe</em>.For your code you want to use a regular <strong>If</strong> statement to replace the backslash character with an empty string, then use the hard-coded backslash when you build the path.</p> <pre><code>strAppPath = App.Path If(Right$(strAppPath, 1) = "\" Then strAppPath = Left$(strAppPath, Len(strAppPath) - 1) End Id strEmpFileName = strAppPath &amp; "\SOURCE\SWA.exe" </code></pre> <p>The full <a href="http://msdn.microsoft.com/en-us/library/aa445024%28v=vs.60%29.aspx" rel="nofollow">MSDN documentation is here</a>.</p> <p>Also, getting the application path is something that is done a lot. I suggest you write your own function to do this and add it to a project .bas file. Then you call the function from where ever you need it and the returned path format, (with or without the trailing backslash) is consistent. My personal function makes sure I have a trailing backslash.</p> <pre><code>Public Function AppPath() As String Dim sAppPath As String sAppPath = App.Path If Right$(sAppPath, 1) &lt;&gt; "\" Then 'check that I'm not in the root sAppPath = sAppPath &amp; "\" End If AppPath = sAppPath End Function </code></pre> <p><em>useage:</em> <code>strEmpFileName = AppPath() &amp; "SOURCE\SWA.exe"</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload