Results 1 to 6 of 6

Thread: App.Path in module constant

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    App.Path in module constant

    Hi i'm noob to VB. I'm trying to use app.path in a constant in a form like:

    Const d_Svt = App.Path

    It obviously doesn't work but how can i make that const the apps path?

    Any help great thanks



    VB Code:
    1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    3. <assemblyIdentity
    4.     version="1.0.0.0"
    5.     processorArchitecture="X86"
    6.     name="1234.exe"
    7.     type="win32"
    8. />
    9. <description>A Description</description>
    10. <dependency>
    11.     <dependentAssembly>
    12.         <assemblyIdentity
    13.             type="win32"
    14.             name="Microsoft.Windows.Common-Controls"
    15.             version="6.0.0.0"
    16.             processorArchitecture="X86"
    17.             publicKeyToken="6595b64144ccf1df"
    18.             language="*"
    19.         />
    20.     </dependentAssembly>
    21. </dependency>
    22. </assembly>
    Last edited by BefunMunkToloGen; Apr 29th, 2005 at 11:01 AM.

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: App.Path in module constant

    i dont get it, the apps path is constant....

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: App.Path in module constant

    I have a constant in a module I want to change from "C:\Program Files\" to app.path. How can I do this?

    Thanks

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: App.Path in module constant

    You can't make a constant out of something that is essentially a variable like App.Path since it's value may change with each installation. You can however create a variable, set it equal to App.Path (once) and use it just like you would a constant.

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: App.Path in module constant

    You cannot change a CONSTANT. Once it is defined, it is static. You also cannot set the app.path to a constant. You must use a string.

    This is what I use to let my program know where the app.path is:
    VB Code:
    1. Public Function GetAppPath() As String
    2.    Dim strPath As String
    3.    strPath = App.Path
    4.    If Right$(strPath, 1) <> "\" Then
    5.       strPath = strPath & "\"
    6.    End If
    7.    GetAppPath = strPath
    8. End Function

    I call it once and then refer to the global string.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: App.Path in module constant

    You can simplify that

    VB Code:
    1. Public Function GetAppPath() As String
    2.  
    3.    If Right$(App.Path, 1) <> "\" Then
    4.       GetAppPath = App.Path & "\"
    5.    Else
    6.       GetAppPath = App.Path
    7.    End If
    8.  
    9. End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width