teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

誤った回答をしていたので、修正

2017/07/20 02:17

投稿

motuo
motuo

スコア3027

answer CHANGED
@@ -1,40 +1,58 @@
1
1
  ちょっと興味がわいたので下記の処理を作ってみました。
2
+
3
+ > **↓↓ここが嘘でしたごめんなさい**
4
+
2
5
  結果、全ての処理においてメッセージボックスが表示されましたね。
3
6
  というわけで、ほぼ等価と言って良いかと思います。
7
+
8
+ > **↑↑ここが嘘でしたごめんなさい**
9
+
10
+ nothingを除いて、""とString.emptyはほぼ等価と言って良いでしょう。
4
11
  ただ、書き方としてはプロジェクト内で統一したいですね。
5
12
 
6
13
  ```
7
- Dim test1 As String = ""
14
+ Dim test1 As String = ""
8
- Dim test2 As String = String.Empty
15
+ Dim test2 As String = String.Empty
9
- Dim test3 As String = Nothing
16
+ Dim test3 As String = Nothing
10
17
 
11
- If test1 = "" Then
18
+ If test1 = "" Then
12
- MsgBox("test1は空白")
19
+ MsgBox("test1は空白")
13
- End If
20
+ End If
14
- If test2 = "" Then
21
+ If test2 = "" Then
15
- MsgBox("test2は空白")
22
+ MsgBox("test2は空白")
16
- End If
23
+ End If
17
- If test3 = "" Then
24
+ If test3 = "" Then
18
- MsgBox("test3は空白")
25
+ MsgBox("test3は空白")
19
- End If
26
+ End If
20
27
 
21
- If test1 = String.Empty Then
28
+ If test1 = String.Empty Then
22
- MsgBox("test1はempty")
29
+ MsgBox("test1はempty")
23
- End If
30
+ End If
24
- If test2 = String.Empty Then
31
+ If test2 = String.Empty Then
25
- MsgBox("test2はempty")
32
+ MsgBox("test2はempty")
26
- End If
33
+ End If
27
- If test3 = String.Empty Then
34
+ If test3 = String.Empty Then
28
- MsgBox("test3はempty")
35
+ MsgBox("test3はempty")
29
- End If
36
+ End If
30
37
 
31
- If test1 = Nothing Then
38
+ If test1 = Nothing Then
32
- MsgBox("test1はnothing")
39
+ MsgBox("test1はnothing")
33
- End If
40
+ End If
34
- If test2 = Nothing Then
41
+ If test2 = Nothing Then
35
- MsgBox("test2はnothing")
42
+ MsgBox("test2はnothing")
36
- End If
43
+ End If
37
- If test3 = Nothing Then
44
+ If test3 = Nothing Then
38
- MsgBox("test3はnothing")
45
+ MsgBox("test3はnothing")
39
- End If
46
+ End If
47
+
48
+ 'この時には、test3のみが判定の対象になる!!
49
+ If IsNothing(test1) Then
50
+ MsgBox("test1はnothing")
51
+ End If
52
+ If IsNothing(test2) Then
53
+ MsgBox("test2はnothing")
54
+ End If
55
+ If IsNothing(test3) Then
56
+ MsgBox("test3はnothing")
57
+ End If
40
58
  ```