Click to See Complete Forum and Search --> : Using My.Computer


jcb1269
08-24-2007, 02:08 PM
I'm trying to use my.computer.Filesystem in a class and "my" is erroring out saying it isn't declared. I'm having a brain issue at the moment, what do I have to add to allow me to use this?

Public Class Test

With My.Computer.FileSystem

End With

End Class


Thanks all

jb

Phil Weber
08-24-2007, 03:17 PM
Are you using VS 2005? I just created a new console application in VS 2005, and when I typed "My." I got IntelliSense without having to do anything special to make it work.

jcb1269
08-24-2007, 04:25 PM
I'm tying to use it in a class. Are you doing this?

Thanks for you help

jb

Phil Weber
08-24-2007, 04:58 PM
Yes, works fine, but it must be inside a method:

Public Class MyClass

My.<IntelliSense does not work here>

Public Sub MyMethod()
My.<IntelliSense works here>
End Sub

End Class

jcb1269
08-28-2007, 03:22 PM
This is some of what I'm doing:

With My.Computer.FileSystem
If .GetFileInfo(file1).Length = .GetFileInfo(file2).Length Then
......
end if

End With

My in this piece is underlined and says "Name My is not declared". Is there an Import statement I'm missing maybe? Still having this issue!

Thanks again for the help Phil.

jb

Phil Weber
08-28-2007, 03:53 PM
Please try the following steps:

1. Open VS 2005
2. Create a new VB Windows or Console application
3. In Solution Explorer, right-click on the project and add a new class
4. Add the following code to the new class:

Public Class Class1
Public Shared Function Test() As String
Return My.Computer.FileSystem.CurrentDirectory()
End Function
End Class

5. Test the code by adding the following line to the main program:

Console.WriteLine(Class1.Test)
' - or -
' MessageBox.Show(Class1.Test)

jcb1269
08-29-2007, 09:26 AM
It worked fine doing it your way. I added my class the new project and it worked fine. Must be something in the way I created the other project, not sure.....

Like always, thank you for you help!!! :)

jb