qq270037265 发表于 2013-10-13 19:35:25

一个简单的生肖查询算法,求高手精简优化,便可做成UDF了

;十二生肖
Global $sx=[["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"],["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]]
Global $nf=["1900","1901","1902","1903","1904","1905","1906","1907","1908","1909","1910","1911"]
Dim $a
$a=InputBox("输入","输入4位年份(如1999)",""," M4",15,15)
If @error=1 Then exit
       
Select
        Case StringIsInt ($a)=0 Or $a<1900 Or $a>2103;好像超过2103会不准
MsgBox(16,"提示","输入错误或超出范围~!")
Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case $a=$nf
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
        Case Mod(($a-$nf),12)=0
                MsgBox (64,"生肖",$a&"年生属"&$sx&$sx&"年")
       
        EndSelect

afan 发表于 2013-10-13 20:15:31

Local $y = 2013
MsgBox(0, $y, _SX($y))

Func _SX($YEAR)
        Local $iYEAR = 1900
        If $YEAR < $iYEAR Then Return SetError(1)
        Local $sData = '子鼠丑牛寅虎卯兔辰龙巳蛇午马未羊申猴酉鸡戌狗亥猪'
        Local $aData = StringRegExp($sData, '..', 3)
        Return $aData
EndFunc   ;==>_SX

weeks1 发表于 2013-10-14 09:14:07

谢谢学习、、、、

e10614083 发表于 2013-10-14 21:39:24

这种问题也需要拿出来讨论么。。。。

e10614083 发表于 2013-10-14 21:40:02

回复 1# qq270037265


    从你这代码一眼看出编码新手。。

hzxymkb 发表于 2013-10-14 22:01:28

回复 4# e10614083


    多理解一下,谁没有新手过!

东风破 发表于 2013-10-14 22:10:49

支持一下,多多学习哈。

huangwei 发表于 2013-10-19 21:20:54

谢谢学习、、、、

kfsyosf 发表于 2013-10-22 14:04:57

看看看看看看看看看看

snailyyy 发表于 2013-10-25 12:24:27

貌似写的恨得很多的样子~~~
页: [1]
查看完整版本: 一个简单的生肖查询算法,求高手精简优化,便可做成UDF了