绝对的高手题 各位大大请进
那天有一个VB高手给我留下了这段代码,我始终看不明白!
他操作的过程:他创建了
两个文本框(复制一个得到两个)
三个标签
他没有对这几个文本框命名,也没有对这几个标签命名
只要一在两个文本框里输入东西
就会显现出结果.
这是怎么回事?
看看他的代码
为什么在第一个文本框里面输入的东西就是指”mymonth”
而在第二个文本框里输入的东西就是指 "myday "
他的代码中都没有特别说明哪个是哪个啊~
并且他又没有对控件命名~~~~~~~~~
高手留下的代码,估计很多人不会.
Function mystar(mymonth As Long, myday As Long) As String
Dim xinxin As String
If (mymonth = 1 And myday > = 20) Or (mymonth = 2 And myday <= 17) Then xinxin = "魔羯座 "
If (mymonth = 2 And myday > = 18) Or (mymonth = 3 And myday <= 12) Then xinxin = "水瓶座 "
If (mymonth = 3 And myday > = 13) Or (mymonth = 4 And myday <= 18) Then xinxin = "双鱼座 "
If (mymonth = 4 And myday > = 19) Or (mymonth = 5 And myday <= 13) Then xinxin = "牡羊座 "
If (mymonth = 5 And myday > = 14) Or (mymonth = 6 And myday <= 22) Then xinxin = "金牛座 "
If (mymonth = 6 And myday > = 23) Or (mymonth = 7 And myday <= 21) Then xinxin = "双子座 "
If (mymonth = 7 And myday > = 22) Or (mymonth = 8 And myday <= 10) Then xinxin = "巨蟹座 "
If (mymonth = 8 And myday > = 11) Or (mymonth = 9 And myday <= 16) Then xinxin = "狮子座 "
If (mymonth = 9 And myday > = 17) Or (mymonth = 10 And myday <= 31) Then xinxin = "处女座 "
If (mymonth = 11 And myday > = 1 And myday <= 23) Then xinxin = "天秤座 "
If (mymonth = 11 And myday > = 24 And myday <= 29) Then xinxin = "天蝎座 "
If (mymonth = 11 And myday = 30) Or (mymonth = 12 And myday <= 17) Then xinxin = "蛇夫座 "
If (mymonth = 12 And myday > = 19) Or (mymonth = 1 And myday <= 19) Then xinxin = "射手座 "
mystar = xinxin
End Function
Private Sub Command1_Click()
Label1.ForeColor = RGB(0, 0, 250)
End Sub
Private Sub Text1_Change(Index As Integer)
If CLng(Val(Text1(0).Text)) = 0 Or CLng(Val(Text1(1).Text)) = 0 Then
Label3.Caption = " "
Else
Label3.Caption = mystar(CLng(Val(Text1(0).Text)), CLng(Val(Text1(1).Text)))
End If
End Sub
[解决办法]
Text1(0).Text代表生日月份,Text1(1).Text代表生日日数,Label3(没看你建立label3,可代码里有)显示星座,显示星座的函数在Text1_Change中被运行,当然是一修改TextBox.Text的时候被触发~~~
Command1被点击效果是Label1的前景色变色—RGB(0,0,250)接近兰色
[解决办法]
mystar()传递的参数中第一个就是mymonth,即为CLng(Val(Text1(0).Text)),第二个同理……
Val()函数——把字符串类型转换为Double类型,字符串中可以有除数字外其他字符
Clng()函数——把表达式转换为长整型 Long,如果表达式为字符串,则其中不可以包含除数字外其他字符