Back to Top

Monthly Archives: 10月 2016

VB.NET ファイルをゴミ箱に移動する

ファイルを削除するのではなく、ゴミ箱に移動する方法を記載します。

My機能を使用する方法

Dim sFilePath As String = "C:\work\myfile.txt"
 
 My.Computer.FileSystem.DeleteFile(sFilePath,
            FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)

 

FileIO.FileSystem クラスを使用する方法

Dim sFilePath As String = "C:\work\myfile.bak"

 FileIO.FileSystem.DeleteFile(sFilePath,
       FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)

 

VB.NET 文字列が空か調べる

文字列(String)が空の文字列かを調べるに方法にて説明します。

等値演算子による比較

Dim s As String = ""

If s Is Nothing Then
    MessageBox.Show("文字列はNULLです")
End If

If s = "" Then
    MessageBox.Show("文字列は空です")
End If

If s = String.Empty Then
    MessageBox.Show("文字列はEmptyです")
End If

 

 

Equals メソッドによる比較

Dim s As String = ""

If s.Equals("") Then
    MessageBox.Show("文字列は空です")
End If

If s.Equals(String.Empty) Then
    MessageBox.Show("文字列はEmptyです")
End If

 

 

Nothing (NULL) か比較

Dim s As String = ""

If s Is Nothing Then
    MessageBox.Show("文字列はNULLです")
End If

※文字列は

Dim s As String

Dim s As String = “”

Dim s As String = Nothing

※以上3つとも値がことなりますので注意