以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]文本框显示百分比,代码出错。(已解决)  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=13471)

--  作者:yyzlxc
--  发布时间:2011/10/13 12:38:00
--  [求助]文本框显示百分比,代码出错。(已解决)

一段代码,在窗口的文本框显示数量及百分比,打开项目出错,如何解决,请各位老师指教。谢谢!!

 

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目176.table

 

 

代码如下:

 

劳动报酬_DataColChanged

\'在册人数
Select Case  e.DataCol.Name
    Case "本单位"
        If Forms("劳动报酬").Opened Then
            Forms("劳动报酬").Controls("TextBox1").value = DataTables("劳动报酬").compute("Count([单位])","姓名 <> \'""\'")
        End If
End Select
\'评定等级
Select Case  e.DataCol.Name
    Case "评定等级"
        If Forms("劳动报酬").Opened Then
            Forms("劳动报酬").Controls("TextBox2").value = DataTables("劳动报酬").compute("Count([单位])","评定等级 = \'A\'")
            Forms("劳动报酬").Controls("TextBox3").value = DataTables("劳动报酬").compute("Count([单位])","评定等级 = \'B\'")
            Forms("劳动报酬").Controls("TextBox4").value = DataTables("劳动报酬").compute("Count([单位])","评定等级 = \'C\'")
            Forms("劳动报酬").Controls("TextBox5").value = DataTables("劳动报酬").compute("Count([单位])","评定等级 = \'D\'")
        End If
End Select
\'百分比
Dim zc As Integer = CInt(Forms("劳动报酬").Controls("TextBox1").Text)  \'在册
Dim a As Integer =  CInt(Forms("劳动报酬").Controls("TextBox2").Text)  \'A
Dim b As Integer =  CInt(Forms("劳动报酬").Controls("TextBox3").Text)  \'B
Dim c As Integer =  CInt(Forms("劳动报酬").Controls("TextBox4").Text)  \'C
Dim d As Integer =  CInt(Forms("劳动报酬").Controls("TextBox5").Text)  \'D
Dim ab As Double = IIf(a=0,0,a/zc*100)
Dim bb As Double = IIf(b=0,0,b/zc*100)
Dim cb As Double = IIf(c=0,0,c/zc*100)
Dim db As Double = IIf(d=0,0,d/zc*100)
Forms("劳动报酬").Controls("TextBox6").Value = ab
Forms("劳动报酬").Controls("TextBox6").Value = Math.Round(ab,2)
Forms("劳动报酬").Controls("TextBox7").Value = bb
Forms("劳动报酬").Controls("TextBox7").Value = Math.Round(bb,2)
Forms("劳动报酬").Controls("TextBox8").Value = cb
Forms("劳动报酬").Controls("TextBox8").Value = Math.Round(cb,2)
Forms("劳动报酬").Controls("TextBox9").Value = db
Forms("劳动报酬").Controls("TextBox9").Value = Math.Round(db,2)

 

 

出错如图:

 

 


图片点击可在新窗口打开查看此主题相关图片如下:i.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2011-10-13 13:47:41编辑过]

--  作者:mr725
--  发布时间:2011/10/13 13:05:00
--  
若 Forms("劳动报酬").Controls("TextBox2").value 为空时,其值为空字符"",而不是0,字符参与计算当然不行。
--  作者:yyzlxc
--  发布时间:2011/10/13 13:09:00
--  
谢谢mr725老师的回复,如何改代码,请mr725老师指教,谢谢!!
--  作者:czy
--  发布时间:2011/10/13 13:34:00
--  
将代码中所有text改成Value
--  作者:czy
--  发布时间:2011/10/13 13:40:00
--  

一楼的代码看着好像也不对劲,这样试试:

 

If Forms("劳动报酬").Opened Then
    Forms("劳动报酬").Controls("TextBox1").value = DataTables("劳动报酬").compute("Count([单位])","姓名 Is Not Null")
    Select Case  e.DataCol.Name
        Case "评定等级"
            If Forms("劳动报酬").Opened Then
                Forms("劳动报酬").Controls("TextBox2").value = DataTables("劳动报酬").compute("Count([单位])","评定等级 = \'A\'")
                Forms("劳动报酬").Controls("TextBox3").value = DataTables("劳动报酬").compute("Count([单位])","评定等级 = \'B\'")
                Forms("劳动报酬").Controls("TextBox4").value = DataTables("劳动报酬").compute("Count([单位])","评定等级 = \'C\'")
                Forms("劳动报酬").Controls("TextBox5").value = DataTables("劳动报酬").compute("Count([单位])","评定等级 = \'D\'")
            End If
    End Select
    \'百分比
    Dim zc As Integer = CInt(Forms("劳动报酬").Controls("TextBox1").Value)  \'在册
    If zc > 0 Then
        Dim a As Integer =  CInt(Forms("劳动报酬").Controls("TextBox2").Value)  \'A
        Dim b As Integer =  CInt(Forms("劳动报酬").Controls("TextBox3").Value)  \'B
        Dim c As Integer =  CInt(Forms("劳动报酬").Controls("TextBox4").Value)  \'C
        Dim d As Integer =  CInt(Forms("劳动报酬").Controls("TextBox5").Value)  \'D
        Dim ab As Double = IIf(a=0,0,a/zc*100)
        Dim bb As Double = IIf(b=0,0,b/zc*100)
        Dim cb As Double = IIf(c=0,0,c/zc*100)
        Dim db As Double = IIf(d=0,0,d/zc*100)
        Forms("劳动报酬").Controls("TextBox6").Value = Math.Round(ab,2)
        Forms("劳动报酬").Controls("TextBox7").Value = Math.Round(bb,2)
        Forms("劳动报酬").Controls("TextBox8").Value = Math.Round(cb,2)
        Forms("劳动报酬").Controls("TextBox9").Value = Math.Round(db,2)
    End If
End If


--  作者:yyzlxc
--  发布时间:2011/10/13 13:47:00
--  
谢谢czy老师的帮助,问题解决了,再次衷心感谢!!
--  作者:yangming
--  发布时间:2011/10/13 13:51:00
--  

text, 改成:value

 

Dim zc As Integer = CInt(Forms("劳动报酬").Controls("TextBox1").value)  \'在册
Dim a As Integer =  CInt(Forms("劳动报酬").Controls("TextBox2").value)  \'A
Dim b As Integer =  CInt(Forms("劳动报酬").Controls("TextBox3").value)  \'B
Dim c As Integer =  CInt(Forms("劳动报酬").Controls("TextBox4").value)  \'C
Dim d As Integer =  CInt(Forms("劳动报酬").Controls("TextBox5").value)  \'D


--  作者:don
--  发布时间:2011/10/13 15:10:00
--  
Select Case  e.DataCol.Name
    Case "评定等级"
        If e.DataRow.Isnull("单位")  OrElse e.DataRow.Isnull("姓名") Then
            Messagebox.show("单位或姓名列没输入!","提示")
            Return
        End If
        With  Forms("劳动报酬")
            If .Opened Then
                Dim dt As  DataTable = DataTables("劳动报酬")
                Dim zc,a,b,c,d As Integer
                zc =  dt.compute("Count([单位])","姓名 Is Not Null")
                .Controls("TextBox1").value =  zc              
                Dim Ls As Integer() ={a,b,c,d}
                Dim Ls1 As Integer() ={2,3,4,5}
                Dim Ls2 As String() ={"A","B","C","D"}
                For i As Integer = 0 To Ls.Length - 1
                    Ls(i) = dt.compute("Count([单位])","评定等级 = \'" & Ls2(i) & "\'")
                    .Controls("TextBox" & Ls1(i)).value =  Ls(i)
                    .Controls("TextBox" & Ls1(i)+4).value = Math.Round(Ls(i)/zc*100,2) & "%"
                Next
            End If
        End With
End Select