嘿,我有以下代码:
Dim validFileTypes As String() = {".bmp", ".gif", ".png", ".jpg", ".jpeg", ".tif"}
For x = 0 To NumberOfBoxes - 1
With myTxtData(x)
If Not Fields("customField" & z).Value.Equals(DBNull.Value) Then
If InStr(Fields("customField" & z).Value, "@") <> 0 Then
'Lower case the email address
.Text = StrConv(Fields("customField" & z).Value, VbStrConv.Lowercase)
ElseIf InStr(StrConv(Fields("customField" & z).Value, VbStrConv.Lowercase), ".jpg") <> 0 Then
'It contains an image!
Else
.Text = StrConv(Fields("customField" & z).Value, VbStrConv.ProperCase)
End If
etc etc.....
而不是我这样检查:
ElseIf InStr(StrConv(Fields("customField" & z).Value, VbStrConv.Lowercase), ".jpg") <> 0
OR InStr(StrConv(Fields("customField" & z).Value, VbStrConv.Lowercase), ".png") <> 0
OR InStr(StrConv(Fields("customField" & z).Value, VbStrConv.Lowercase), ".gif") <> 0
...etc...
我如何使用我定义的validFileTypes来做同样的事情,但代码更少?