我使用的是microsoft visual basic 6.5和Excel
TxtMMM
是String prompt keyyed in by user. In this case i hardcoded it as an example
but it(
TxtMMM)可以是“Jan”,“JAN”,“jAn”或“jan”等中的任何一种
我的问题是,如何在检查时查看条件以检查TxtMMM
,忽略区分大小写?
例如,如果用户输入TxtMMM
然后它将返回"01"
sub casesense()
Dim TxtMMM as String
Dim sTxtMMM as String
TxtMMM = "Jan"
If TxtMMM = "JAN" Then
sTxtMMM = "01"
csd = 1
ElseIf TxtMMM = "FEB" Then
sTxtMMM = "02"
csd = 1
.....
End If
End sub
答案 0 :(得分:5)
而不是12步Select
为什么不
Dim TxtMMM As String
TxtMMM = "Jan"
MsgBox Format(Month(DateValue("1/" & TxtMMM & "/2013")), "00")
csd = 1
答案 1 :(得分:2)
很简单。只需使用UCase将TxtMM首先转换为大写,然后比较:
If UCase(TxtMMM) = "JAN" Then
sTxtMMM = "01"
csd = 1
ElseIf UCase(TxtMMM) = "FEB" Then
sTxtMMM = "02"
csd = 1
.....
End If