|
-
May 28th, 2009, 02:03 AM
#1
Thread Starter
Member
(Help) Dir Function in Module..
hello guys..
i tried this code in my module
Code:
Public Const sPath As String = Dir("C:\Sample.txt", vbNormal Or vbHidden)
and got this error:
Constant Expression Required
what should i do.?
thnx in advance..
Last edited by TRENDcafe; May 28th, 2009 at 02:06 AM.
-
May 28th, 2009, 03:11 AM
#2
Re: (Help) Dir Function in Module..
You just need to modify it like this.
Code:
Public sPath As String
SPath = Dir("C:\Sample.txt", vbNormal Or vbHidden)
-
May 28th, 2009, 05:21 AM
#3
Re: (Help) Dir Function in Module..
as you call it sPath, note the return from dir is filename only
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 28th, 2009, 05:33 AM
#4
Re: (Help) Dir Function in Module..
I suspect you are using VB.NET and not VB6. Is that an accurate supposition?
-
May 28th, 2009, 07:27 AM
#5
Re: (Help) Dir Function in Module..
If "c:\sample.txt" file will always be there then you can define your constant like this:
Code:
Public Const SAMPLE_FILE As String = "C:\Sample.txt"
Change scope to Private if you want to declare it in the form.
-
May 28th, 2009, 08:00 AM
#6
Re: (Help) Dir Function in Module..
Dir("C:\Sample.txt", vbNormal Or vbHidden) will not be constant hence you cannot use it in your constant declaration.
-
May 28th, 2009, 09:40 AM
#7
Thread Starter
Member
Re: (Help) Dir Function in Module..
wow.. thank to all of u guys...
@dee-u: thnx for ur reply sir,, ah so it means i cannot use that as a constant?
@westconn1: thnx u sir,, yup i am aware of that..hehehe
@Hack:i am using VB6 sir,,i just trying to make that as constant but i think i cant.
@RhinoBull: nope the "C:\sample.txt" may be there but its hidden, thats why i use Dir to check sir..hehe
@dee-u: thank u sir,, its clear to me now..hehehe
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|