RayT
asked on
My Not Working
The following code is throwing an error
Const f As String = my.Computer.FileSystem.SpecialDirectories.MyDocuments
It is saying my is not declared.
How do I fix this?
Microsoft Visual Studio Professional 2019
Version 16.10.3
VisualStudio.16.Release/16.10.3+31424.327
Microsoft .NET Framework
Version 4.8.03752
Const f As String = my.Computer.FileSystem.SpecialDirectories.MyDocuments
It is saying my is not declared.
How do I fix this?
Microsoft Visual Studio Professional 2019
Version 16.10.3
VisualStudio.16.Release/16.10.3+31424.327
Microsoft .NET Framework
Version 4.8.03752
Do you require me instead of my
No
You need to write My
It is case sensitive
https://www.w3computing.com/vb2008/using-computer-filesystem-component/
You need to write My
It is case sensitive
https://www.w3computing.com/vb2008/using-computer-filesystem-component/
Yes try Dim
You cannot declare a constant like that
It should be Dim as it's a variable
Const is always a fixed value like
Const x = 300
You cannot declare a constant like that
It should be Dim as it's a variable
Const is always a fixed value like
Const x = 300
ASKER
This didi not work
Dim f As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
I check another project. It's shows that My is { } Namespace
How do I get this Namespce into this application?
Dim f As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
I check another project. It's shows that My is { } Namespace
How do I get this Namespce into this application?
Again: Are you writing a VB.Net app? What kind of project (winforms, wpf, ...)?
Which framework are you targeting?
Which framework are you targeting?
You want to ensure that you have imported the Microsoft.VisualBasic namespace.
HTH,
-saige-
HTH,
-saige-
ASKER
It's a VB.NET App and I'm using Framework 4.8
can you provide the exact error? what type of project is it?
ASKER
Dim x As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
Dim y As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
My. does not work. It showing My is not declared. It may be inaccessible due to its protection level.
My workaround is the 2nd one. It works. However, I prefer using the 1st one.
Dim y As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
My. does not work. It showing My is not declared. It may be inaccessible due to its protection level.
My workaround is the 2nd one. It works. However, I prefer using the 1st one.
again: what type of project is it?
have you tried targeting the 4.7.2 framework? (which framework is your other project targeting)?
have you tried targeting the 4.7.2 framework? (which framework is your other project targeting)?
I really suspect that you are using a project type that is incompatible with the My Namespace.
If you create a demo Windows Forms project, the My Namespace will be automatically created for you as shown here:
If you create a demo Windows Forms project, the My Namespace will be automatically created for you as shown here:
As I stated, ensure that you have a reference to Microsoft.VisualBasic and have imported the namespace.
-saige-
-saige-
ASKER
Yeah :( I upraded to the recommended 4.8 and it broke things. Do you think i should go back to 4.7.2?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The property, My.Computer.FileSystem.SpecialDirectories.MyDocuments, is available in .NET Framework 4.8.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.fileio.specialdirectories.mydocuments?view=netframework-4.8#microsoft-visualbasic-fileio-specialdirectories-mydocuments
As I stated before, add a reference to Microsoft.VisualBasic and ensure that you have it imported.
-saige-
https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.fileio.specialdirectories.mydocuments?view=netframework-4.8#microsoft-visualbasic-fileio-specialdirectories-mydocuments
As I stated before, add a reference to Microsoft.VisualBasic and ensure that you have it imported.
-saige-
ASKER
I may go back to 4.8 for now until I can find out the difference between
SpecialDirectories.MyDocuments Property (Microsoft.VisualBasic.FileIO) | Microsoft Docs
Product | Versions |
---|---|
.NET | 5.0, 6.0 Preview 3 |
.NET Core | 3.0, 3.1 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
SpecialDirectories.MyDocuments Property (Microsoft.VisualBasic.FileIO) | Microsoft Docs
ASKER
ASKER
ASKER
Much thanks to all!