我想判断下面的语句中的某个值是否为0,是就不显示,下面的代码的格式是"距xxx还有:xx天xx时xx分xx秒
我不知道如何用一句代码来判断里面的所有为0的值,是0不让他显示,比如天数为0,就显示"距xxx还有:xx时xx分xx秒,其他为0也一样去掉 Label1.Caption = "距" & Label2.Caption & "还有:" & Int(dTimeNow) & "天" & xh & "时" & xm & "分" & xs & "秒"

解决方案 »

  1.   


    if int(dtimenow)<>0 and cint(xh)<>0 and cint(xm)<>0 and cint(xs)<>0 then
    Label1.Caption = "距" & Label2.Caption & "还有:" & Int(dTimeNow) & "天" & xh & "时" & xm & "分" & xs & "秒"
    end if 
      

  2.   

    楼主试一下这样的代码吧:
    Dim strTemp$strTemp = "距" & Label2.Caption & "还有:"
    If (Int(dTimeNow) > 0) Then strTemp = strTemp & Int(dTimeNow) & "天"
    If (xh > 0) Then strTemp = strTemp & xh & "时"
    If (xm > 0) Then strTemp = strTemp & xm & "分"
    If (xs > 0) Then strTemp = strTemp & xs & "秒"
    Label1.Caption = strTemp
      

  3.   

    Label1.Caption = "距" & Label2.Caption & "还有:" & iif(Int(dTimeNow) >0, Int(dTimeNow) & "天","")  & iif(xh>0, xh & "分", "") & iif(xs>0, xs & "秒", "")
      

  4.   

    Private Sub Command1_Click()'xh = 0: xm = 2: xs = 3: dtimenow = 12If Int(dtimenow) <> 0 And CInt(xh) <> 0 And CInt(xm) <> 0 And CInt(xs) <> 0 Then
     Label1.Caption = "距" & Label2.Caption & "还有:" & Int(dtimenow) & "天" & xh & "时" & xm & "分" & xs & "秒" ElseIf Int(dtimenow) = 0 And CInt(xh) <> 0 And CInt(xm) <> 0 And CInt(xs) <> 0 Then
     Label1.Caption = "距" & Label2.Caption & "还有:" & xh & "时" & xm & "分" & xs & "秒"
     
     ElseIf CInt(xh) = 0 And Int(dtimenow) <> 0 And CInt(xm) <> 0 And CInt(xs) <> 0 Then
      Label1.Caption = "距" & Label2.Caption & "还有:" & Int(dtimenow) & "天" & "时" & xm & "分" & xs & "秒"
     '.................还有自己写End IfEnd Sub