Microsoft Visual Basic 6.5忽略大小写

时间:2013-04-26 05:13:54

标签: excel vba excel-vba

我使用的是microsoft visual basic 6.5和Excel

TxtMMMString prompt keyyed in by user. In this case i hardcoded it as an example but it( TxtMMM)可以是“Jan”,“JAN”,“jAn”或“jan”等中的任何一种

我的问题是,如何在检查时查看条件以检查TxtMMM忽略区分大小写

例如,如果用户输入TxtMMM

  • JAN
  • JAN

然后它将返回"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

2 个答案:

答案 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