Reputation: 405
I have this code to const the Current Path :
Option Explicit
Const CurPath As String = App.Path 'not working and higlight ".Path" for error.
Private Sub Form_Load() 'just for test with Label1 Caption
Label1.Caption = CurPath
End Sub
i don't know whats wrong but it does'nt work, but i want to set constant for current path to use in many SUB and Function
, any suggestion?
NOTE: i want this const stay in the Form and NOT in Module, and once again, i want this in const
, because another const need this too.
Upvotes: 0
Views: 2302
Reputation: 9726
I know you said you didn't want your Const in a module, but I would suggest using a method in a module. Placing a public method in a module makes it available to all the forms, and other modules of your application. Below is a function I wrote and added to a module that contains common methods that I use often. Whenever I begin a new project I automatically add this module.
Public Function AppPath() As String
Dim sAppPath As String
sAppPath = App.Path
If Right$(sAppPath, 1) <> "\" Then 'check that I'm not in the root
sAppPath = sAppPath & "\"
End If
AppPath = sAppPath
End Function
To use:
Private Sub Form_Load() 'just for test with Label1 Caption
Label1.Caption = AppPath
End Sub
Upvotes: 2