My.Application, My.Computer 및 My.User를 사용한 작업 수행(Visual Basic)

My 개체는 My.Application(ApplicationBase), My.Computer(Computer) 및 My.User(User)의 세 가지 중앙 개체 중 하나로, 이를 통해 정보 및 일반적으로 사용되는 기능에 액세스할 수 있습니다. 이러한 개체를 사용하여 현재 애플리케이션, 애플리케이션이 설치된 컴퓨터 또는 애플리케이션의 현재 사용자와 관련된 정보에 액세스할 수 있습니다.

My.Application, My.Computer 및 My.User

다음 예제에서는 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 & " "
Next
MsgBox(args)
' Gets a list of subfolders in a folder
My.Computer.FileSystem.GetDirectories(
  My.Computer.FileSystem.SpecialDirectories.MyDocuments, True, "*Logs*")

정보를 검색하는 것 외에도, 이러한 세 가지 개체를 통해 노출된 멤버를 사용하여 해당 개체와 관련된 메서드를 실행할 수도 있습니다. 예를 들어 다양한 메서드에 액세스하여 파일을 조작하거나 My.Computer를 통해 레지스트리를 업데이트할 수 있습니다.

파일 I/O는 파일, 디렉터리 및 드라이브 조작을 위한 다양한 메서드 및 속성을 포함하는 My를 통해 훨씬 쉽고 빠르게 수행할 수 있습니다. TextFieldParser 개체를 사용하면 구분되거나 고정 너비 필드가 있는 크고 구조화된 파일에서 읽을 수 있습니다. 이 예제에서는 TextFieldParserreader를 열고 이를 사용하여 C:\TestFolder1\test1.txt에서 읽습니다.

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

My.Application을 사용하면 애플리케이션의 문화권을 변경할 수 있습니다. 다음 예제에서는 이 메서드를 호출할 수 있는 방법을 보여줍니다.

' Changes the current culture for the application to Jamaican English.
My.Application.ChangeCulture("en-JM")

참고 항목