This documentation is archived and is not being maintained.

Performing Tasks with My.Application, My.Computer, and My.User 

The three central My objects that provide access to information and commonly used functionality are My.Application Object, My.Computer Object, and My.User Object. You can use these objects to access information that is related to the current application, the computer that the application is installed on, or the current user of the application, respectively.

My.Application, My.Computer, and My.User

The following examples demonstrate how information can be retrieved using My.

' Displays a message box that shows the full command line for the
' application.
Dim args As String = ""
For Each arg As String In My.Application.CommandLineArgs
    args &= arg & " "

' Gets a list of subfolders in a folder
My.Computer.FileSystem.GetDirectories _
(My.Computer.FileSystem.SpecialDirectories.MyDocuments, True, "*Logs*")

In addition to retrieving information, the members exposed through these three objects also allow you to execute methods related to that object. For instance, you can access a variety of methods to manipulate files or update the registry through My.Computer.

File I/O is significantly easier and faster with My, which includes a variety of methods and properties for manipulating files, directories, and drives. The TextFieldParser Object allows you to read from large structured files that have delimited or fixed-width fields. This example opens the TextFieldParser reader and uses it to read from C:\TestFolder1\test1.txt.

Dim reader As Microsoft.VisualBasic.FileIO.TextFieldParser
reader = My.Computer.FileSystem.OpenTextFieldParser _
reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
reader.Delimiters = New String() {","}
Dim currentRow As String()
While Not reader.EndOfData
      currentRow = reader.ReadFields()
      Dim currentField As String
        For Each currentField In currentRow
        Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
          MsgBox("Line " & ex.Message & _
          "is not valid and will be skipped.")
    End Try
End While

My.Application allows you to change the culture for your application. The following example demonstrates how this method can be called.

' Changes the current culture for the application to Jamaican English.

See Also