2011-12-21 113 views
9

这段小小的代码应该启动并给我正确的变量 ,但无论变量“numericDay”中的变量“后缀”是否为 “th”。我不明白为什么它不会改变时numericDay的”值改变 都是字符串变量Visual Basic 6.0病例声明

Select Case numericDay 
      Case numericDay = "1" Or "21" Or "31" 
       suffix = "st" 
      Case numericDay = "2" Or "22" 
       suffix = "nd" 
      Case numericDay = "3" Or "23" 
       suffix = "rd" 
      Case Else 
      suffix = "th" 

    End Select 
+0

什么'numericDay'? – SLaks 2011-12-21 18:29:46

+0

@Slaks他们都是字符串变量。我以为我打了那个,但我认为我的原始问题已经缩小到规模。不管和不用担心,由于nybbler的回答,我已经看到了我的语法错误。 – 2011-12-21 18:48:12

回答

26

你写你的选择不正确尝试以下方法:。

Select Case numericDay 
      Case "1", "21", "31" 
       suffix = "st" 
      Case "2", "22" 
       suffix = "nd" 
      Case "3", "23" 
       suffix = "rd" 
      Case Else 
       suffix = "th" 
    End Select 

对于未来的参考:http://www.vb6.us/tutorials/learn-if-else-and-select-statements-vb6

+0

非常感谢你:) – 2011-12-21 18:45:58

+3

+1以供将来参考,你也可以尝试手动http://msdn.microsoft.com/en-us/library/aa266274(v=VS.60).aspx – MarkJ 2011-12-22 18:29:33

6

根据the msdn你应该写这样的:

Select Case numericDay 
     Case "1", "21", "31" 
      suffix = "st" 
     Case "2", "22" 
      suffix = "nd" 
     Case "3", "23" 
      suffix = "rd" 
     Case Else 
     suffix = "th" 
End Select 
3

"2" Or "22"将执行一个字节或2和22,这对应于22.