|
hxwonepc
新手上路
积分 12
发帖 4
注册 2008-3-5
状态 离线
|
『楼 主』:
这个生肖查询能不能再用别的简洁方法VBS。
我第一次写的:
dim sr
sr=inputbox("请输入年份如:1983"&Chr(10)&Chr(13)&"查询范围1900-2103","生肖查询")
If IsNumeric(sr) And sr<>"" then
select case sr
case 1900,1912,1924,1936,1948,1960,1972,1984,1996,2008,2020,2032,2044,2056,2068,2080,2092
msgbox sr&"年生肖属:鼠,子年",,"生肖"
case 1901,1913,1925,1937,1949,1961,1973,1985,1997,2009,2021,2033,2045,2057,2069,2081,2093
msgbox sr&"年生肖属:牛,丑年",,"生肖"
case 1902,1914,1926,1938,1950,1962,1974,1986,1998,2010,2022,2034,2046,2058,2070,2082,2094
msgbox sr&"年生肖属:虎,寅年",,"生肖"
case 1903,1915,1927,1939,1951,1963,1975,1987,1999,2011,2023,2035,2047,2059,2071,2083,2095
msgbox sr&"年生肖属:兔,卯年",,"生肖"
case 1904,1916,1928,1940,1952,1964,1976,1988,2000,2012,2024,2036,2048,2060,2072,2084,2096
msgbox sr&"年生肖属:龙,辰年",,"生肖"
case 1905,1917,1929,1941,1953,1965,1977,1989,2001,2013,2025,2037,2049,2061,2073,2085,2097
msgbox sr&"年生肖属:蛇,巳年",,"生肖"
case 1906,1918,1930,1942,1954,1966,1978,1990,2002,2014,2026,2038,2050,2062,2074,2086,2098
msgbox sr&"年生肖属:马,午年",,"生肖"
case 1907,1919,1931,1943,1955,1967,1979,1991,2003,2015,2027,2039,2051,2063,2075,2087,2099
msgbox sr&"年生肖属:羊,未年",,"生肖"
case 1908,1920,1932,1944,1956,1968,1980,1992,2004,2016,2028,2040,2052,2064,2076,2088,2100
msgbox sr&"年生肖属:猴,申年",,"生肖"
case 1909,1921,1933,1945,1957,1969,1981,1993,2005,2017,2029,2041,2053,2065,2077,2089,2101
msgbox sr&"年生肖属:鸡,酉年",,"生肖"
case 1910,1922,1934,1946,1958,1970,1982,1994,2006,2018,2030,2042,2054,2066,2078,2090,2102
msgbox sr&"年生肖属:狗,戌年",,"生肖"
case 1911,1923,1935,1947,1959,1971,1983,1995,2007,2019,2031,2043,2055,2067,2079,2091,2103
msgbox sr&"年生肖属:猪,亥年",,"生肖"
case else
msgbox "输入错误格式",,"错误"
wscript.quit
end select
Else
MsgBox "不是数字!", 64, "错误信息..."
wscript.quit
End If
第二次的:
dim a
const b=1900
const c=1901
const d=1902
const e=1903
const f=1904
const g=1905
const h=1906
const i=1907
const j=1908
const k=1909
const l=1910
const m=1911
a=inputbox("输入年份","查询")
If IsNumeric(a) And a<>"" Then
If a>1899 and a<2104 Then
Select case a
case b
msgbox a&"年生肖属:鼠,子年",,"生肖"
case c
msgbox a&"年生肖属:牛,丑年",,"生肖"
case d
msgbox a&"年生肖属:虎,寅年",,"生肖"
case e
msgbox a&"年生肖属:兔,卯年",,"生肖"
case f
msgbox a&"年生肖属:龙,辰年",,"生肖"
case g
msgbox a&"年生肖属:蛇,巳年",,"生肖"
case h
msgbox a&"年生肖属:马,午年",,"生肖"
case i
msgbox a&"年生肖属:羊,未年",,"生肖"
case j
msgbox a&"年生肖属:猴,申年",,"生肖"
case k
msgbox a&"年生肖属:鸡,酉年",,"生肖"
case l
msgbox a&"年生肖属:狗,戌年",,"生肖"
case m
msgbox a&"年生肖属:猪,亥年",,"生肖"
case Else
If (a-b) Mod 12=0 Then
msgbox a&"年生肖属:鼠,子年",,"生肖"
ElseIf (a-c)Mod 12=0 then
msgbox a&"年生肖属:牛,丑年",,"生肖"
ElseIf (a-d)Mod 12=0 then
msgbox a&"年生肖属:虎,寅年",,"生肖"
ElseIf (a-e)Mod 12=0 then
msgbox a&"年生肖属:兔,卯年",,"生肖"
ElseIf (a-f)Mod 12=0 then
msgbox a&"年生肖属:龙,辰年",,"生肖"
ElseIf (a-g)Mod 12=0 then
msgbox a&"年生肖属:蛇,巳年",,"生肖"
ElseIf (a-h)Mod 12=0 then
msgbox a&"年生肖属:马,午年",,"生肖"
ElseIf (a-i)Mod 12=0 then
msgbox a&"年生肖属:羊,未年",,"生肖"
ElseIf (a-j)Mod 12=0 then
msgbox a&"年生肖属:猴,申年",,"生肖"
ElseIf (a-k)Mod 12=0 then
msgbox a&"年生肖属:鸡,酉年",,"生肖"
ElseIf (a-l)Mod 12=0then
msgbox a&"年生肖属:狗,戌年",,"生肖"
ElseIf (a-m)Mod 12=0 then
msgbox a&"年生肖属:猪,亥年",,"生肖"
End If
end Select
Else
MsgBox("超出范围")
End If
Else
MsgBox "不是数字!", 64, "错误信息..."
wscript.quit
End If
[ Last edited by hxwonepc on 2008-3-9 at 11:59 AM ]
|
|
2008-3-9 11:56 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
2 楼』:
Const StrCHNZod = "鼠子牛丑虎寅兔卯龙辰蛇巳马午羊未猴申鸡酉狗戌猪亥"
Dim QYear
Do
QYear = InputBox("请输入年份如:1983" & vbCrLf & "查询范围1900-?","生肖查询")
If QYear = "" Then Wscript.Quit
If IsNumeric(QYear) Then
If QYear >= 1900 Then Exit Do
End If
MsgBox "你输入的年份有误!",vbInformation,"错误"
Loop
StrCZ = Mid(StrCHNZod,((QYear - 1900) Mod 12) * 2 + 1,2)
MsgBox QYear & "年生肖属:" & StrCZ & "年",0,"生肖"
[ Last edited by slore on 2008-3-9 at 12:34 PM ]
|
|
2008-3-9 12:29 |
|
|
hxwonepc
新手上路
积分 12
发帖 4
注册 2008-3-5
状态 离线
|
|
2008-3-9 12:52 |
|
|
fastslz
铂金会员
DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第
4 楼』:
Array+Mod
aDate=inputbox("请输入年份如:","生肖查询",2008)
If IsNumeric(aDate) Then
ShengXiao = Array("猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊")
MsgBox ShengXiao(aDate Mod 12)
End If
|
第一高手 第二高手
我的小站
|
|
2008-3-9 13:15 |
|
|
fastslz
铂金会员
DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第
5 楼』:
就当代码练习,生肖+星座查询
aDate=inputbox("请输入年份如:","生肖星座查询","1971-07-16")
If IsDate(aDate) Then
aYear = Year(aDate)
ShengXiao = Array("猴申","鸡酉","狗戌","猪亥","鼠子","牛丑","虎寅","兔卯","龙辰","蛇巳","马午","羊未")
MyShengXiao = ShengXiao(aYear Mod 12)
aMon=Month(aDate)
aDay=Day(aDate)
If Len(aMon)<2 then aMon="0"&aMon
If Len(aDay)<2 then aDay="0"&aDay
XingZuo=aMon&aDay
Else
MsgBox "你输入的年份有误!" & vbCrLf &"格式:2000/1/1或00-1-1" , 4096 ,"日期格式错误" :Wscript.Quit
End If
If XingZuo < 0120 then
MyXingZuo="魔羯座"
ElseIf XingZuo < 0219 then
MyXingZuo="水瓶座"
ElseIf XingZuo < 0321 then
MyXingZuo="双鱼座"
ElseIf XingZuo < 0420 then
MyXingZuo="白羊座"
ElseIf XingZuo < 0521 then
MyXingZuo="金牛座"
ElseIf XingZuo < 0622 then
MyXingZuo="双子座"
ElseIf XingZuo < 0723 then
MyXingZuo="巨蟹座"
ElseIf XingZuo < 0823 then
MyXingZuo="狮子座"
ElseIf XingZuo < 0923 then
MyXingZuo="处女座"
ElseIf XingZuo < 1024 then
MyXingZuo="天秤座"
ElseIf XingZuo < 1122 then
MyXingZuo="天蝎座"
ElseIf XingZuo < 1222 then
MyXingZuo="射手座"
ElseIf XingZuo > 1221 then
MyXingZuo="魔羯座"
End If
MsgBox "年龄:" & Year(Date)-aYear & vbCrLf & "生肖:" & MyShengXiao & vbCrLf & "星座:" & MyXingZuo ,4096 [ Last edited by fastslz on 2008-3-9 at 03:18 PM ]
|
第一高手 第二高手
我的小站
|
|
2008-3-9 14:32 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
6 楼』:
aDate = InputBox("请输入年份如:","生肖星座查询","1971" & "-" & "07" & "-" & "16")
生日?
又不是特殊符号?直接
aDate = InputBox("请输入年份如:","生肖星座查询","1971-07-16")
就可以啊
|
|
2008-3-9 14:58 |
|
|
xmi
初级用户
积分 125
发帖 56
注册 2008-2-20
状态 离线
|
『第
7 楼』:
学习中....
"MsgBox "生肖:" & MyShengXiao & vbCrLf & "星座:" & MyXingZuo ,4096" -->请问4096有何用?
和如何懚藏全黑的那个视窗?
|
|
2008-3-9 14:58 |
|
|
fastslz
铂金会员
DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第
8 楼』:
是本人的生日
aDate = InputBox("请输入年份如:","生肖星座查询","1971" & "-" & "07" & "-" & "16")
先前犯了个少""的低级错误,之后也没改过来
|
第一高手 第二高手
我的小站
|
|
2008-3-9 15:11 |
|
|
fastslz
铂金会员
DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
|
2008-3-9 15:15 |
|
|
fastslz
铂金会员
DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
|
2008-3-9 15:33 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
11 楼』:
顺便也简化下吧
Const StrCHNZod = "猴申鸡酉狗戌猪亥鼠子牛丑虎寅兔卯龙辰蛇巳马午羊未"
Const StrTC = "魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯"
Const StrTCD = "201921202122232323242222"
Do
aDate = InputBox("请输入年份如:","生肖星座查询","1987-10-11")
If aDate = "" Then Wscript.Quit
If IsDate(aDate) Then Exit Do
MsgBox "你输入的年份有误!",vbCritical,"错误"
Loop
aYear = Year(aDate):aMon = Month(aDate):aDay = Day(aDate)
StrCZ = Mid(StrCHNZod,(aYear Mod 12) * 2 + 1,2)
If Not aDay < CInt(Mid(StrTCD,aMon * 2 - 1,2)) Then aMon = aMon + 1
StrTCon = Mid(StrTC,aMon * 2 - 1,2)
MsgBox "年龄:" & Year(Date) - aYear & vbCrLf & "生肖:" & StrCZ & vbCrLf & "星座:" & StrTCon,vbInformation,"结果"
|
|
2008-3-9 15:43 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
12 楼』:
郁闷~专门在文本里对齐了,居然。。预览还是歪的
Quote: | Originally posted by xmi at 2008-3-9 14:58:
学习中....
"MsgBox "生肖:" & MyShengXiao & vbCrLf & "星座:" & MyXingZuo ,4096" -->请问4096有何用?
和如何懚藏全黑的那个视窗? |
|
MsgBox 参数常数 值 描述
vbOKOnly 0 只有 OK 按钮(缺省值)
vbOKCancel 1 OK 和 Cancel 按钮
vbAbortRetryIgnore 2 Abort、Retry,和 Ignore 按钮
vbYesNoCancel 3 Yes、No,和 Cancel 按钮
vbYesNo 4 Yes 和 No 按钮
vbRetryCancel 5 Retry 和 Cancel 按钮
vbCritical 16 关键消息
vbQuestion 32 警告询问
vbExclamation 48 警告消息
vbInformation 64 通知消息
vbDefaultButton1 0 第一个按钮是缺省的(缺省值)
vbDefaultButton2 256 第二个按钮是缺省的
vbDefaultButton3 512 第三个按钮是缺省的
vbDefaultButton4 768 第四个按钮是缺省的
vbApplicationModal 0 应用程序形态的消息框(缺省值)
vbSystemModal 4096 系统强制返回的消息框
vbMsgBoxHelpButton 16384 添加Help按钮到消息框
VbMsgBoxSetForeground 65536 指定消息框窗口作为前景窗口
vbMsgBoxRight 524288 文本是右对齐的
vbMsgBoxRtlReading 1048576 指定在希伯来语和阿拉伯语系统中,文本应当显示为从右到左读
MsgBox 返回值常数 值描述
vbOK 1 按下 OK 按钮
vbCancel 2 按下 Cancel 按钮
vbAbort 3 按下 Abort 按钮
vbRetry 4 按下 Retry 按钮
vbIgnore 5 按下 Ignore 按钮
vbYes 6 按下 Yes 按钮
vbNo 7 按下 No 按钮
Quote: | Originally posted by fastslz at 2008-3-9 15:33:
slore兄代码用什么着色的? |
|
好像以前说过啊。。。自己写的着色。。。
字体修改了下,排版终于齐了。。。
[ Last edited by slore on 2008-3-9 at 03:56 PM ]
|
|
2008-3-9 15:55 |
|
|