次の方法で共有


My.Application、My.Computer、および My.User でのタスクの実行 (Visual Basic)

情報や一般的に使用される機能へのアクセスを提供する 3 つの中心的な 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*")

情報を取得できるだけでなく、これらの 3 つのオブジェクトを介して公開されるメンバーは、そのオブジェクトに関連するメソッドを実行することもできます。 たとえば、My.Computer を利用すると、ファイルの操作やレジストリの更新を行うさまざまなメソッドにアクセスできます。

My には、ファイル、ディレクトリ、およびドライブを操作するさまざまなメソッドとプロパティが含まれており、これを使用するとファイル I/O が大幅に簡単かつ高速になります。 TextFieldParser オブジェクトを使用すると、区切り記号で区切られたフィールドや固定幅のフィールドを持つ大きな構造化ファイルからデータを読み取ることができます。 この例では、reader という TextFieldParser を開き、それを使用して 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")

参照

参照

ApplicationBase

Computer

User

概念

プロジェクトの種類に応じた My の機能 (Visual Basic)