找回密码
 加入
搜索
查看: 1046|回复: 1

额,谁会把这段VB转换为AU3,这是关于星座的

[复制链接]
发表于 2009-9-4 17:57:00 | 显示全部楼层 |阅读模式
Private Sub Command1_Click()
  Dim str1 As String, d1 As Date, i As Integer, xz
  xz = Array("白羊座", 3, 21, 4, 20, "金牛座", 4, 21, 5, 20, "双子座", 5, 21, 6, 21, _
"巨蟹座", 6, 22, 7, 22, "狮子座", 7, 23, 8, 22, "处女座", 8, 23, 9, 22, _
"天秤座", 9, 23, 10, 22, "天蝎座", 10, 23, 11, 21, "射手座", 11, 22, 12, 21, _
"摩羯座", 12, 22, 12, 31, "摩羯座", 1, 1, 1, 19, "水瓶座", 1, 20, 2, 18, _
"双鱼座", 2, 19, 3, 20)
  str1 = txtMonth & "-" & txtDay
  If IsDate(str1) Then
    'd1 = CDate(str1)
    For i = 0 To UBound(xz) Step 5
      If Val(txtMonth) >= xz(i + 1) And Val(txtDay) >= xz(i + 2) _
      And Val(txtMonth) <= xz(i + 3) And Val(txtDay) <= xz(i + 4) Then
        MsgBox "你查询的" & str1 & "的星座" & xz(i), vbOKOnly, "星座查询"
        Exit For
      End If
    Next i
  Else
    MsgBox "你输入的数据" & str1 & "不是日期!", vbOKOnly, "星座查询"
  End If
End Sub
发表于 2009-9-5 02:32:00 | 显示全部楼层
本帖最后由 caodongchun 于 2009-9-5 03:05 编辑

要结果不看过程,用到一个udf,语句更简练!
2000年的意义在于包含润2月

#include<date.au3>
$txtMonth = 3
$txtDay = 21
$xz = ('白羊座|3/21|4/20|金牛座|4/21|5/20|双子座|5/21|6/21|' & _
                '巨蟹座|6/22|7/22|狮子座|7/23|8/22|处女座|8/23|9/22|天秤座' & _
                '|9/23|10/22|天蝎座|10/23|11/21|射手座|11/22|12/21|摩羯座|12/' & _
                '22|12/31|摩羯座|1/1|1/19|水瓶座|1/20|2/18|双鱼座|2/19|3/20')
$xz = StringSplit($xz, '|')
$str = $txtMonth & "/" & $txtDay
$str1 = 2000 & '/' & $str
If Not _DateIsValid($str1) Then Exit
For $i = 1 To UBound($xz) Step 3
        If _DateDiff('d', $str1, 2000 & '/' & $xz[$i + 1] ) _
                <= 0 And _DateDiff('d', $str1, 2000 & '/' & $xz[$i + 2]) >= 0 Then
                MsgBox(64, '', "你查询的" & StringReplace($str , '/' , '月') & "日的星座:" & $xz[$i])
                Exit
        EndIf
Next

评分

参与人数 1金钱 +100 贡献 +35 收起 理由
kn007 + 100 + 35 非常好,虽然还不是非常简洁,记得有个简洁 ...

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-22 21:29 , Processed in 0.077605 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表