Foxtable(狐表)用户栏目专家坐堂 → 字符转数值,再转字符 ,帮我看看,这代码错在哪里?


  共有2327人关注过本帖树形打印复制链接

主题:字符转数值,再转字符 ,帮我看看,这代码错在哪里?

帅哥哟,离线,有人找我吗?
hongyefor
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
字符转数值,再转字符 ,帮我看看,这代码错在哪里?  发帖心情 Post By:2016/8/3 15:57:00 [只看该作者]

Dim mx11 As WinForm.TextBox = e.Form.Controls("TBMX01")
Dim mx12 As WinForm.TextBox = e.Form.Controls("TBMX02")
Dim mx16 As WinForm.TextBox = e.Form.Controls("TBMX06")
Dim Multi As String = mx11.text
Dim pars() As String = Multi.Split("-")
Dim e1 As Double = Val(pars(0))
Dim e2 As Double = Val(pars(1))
Dim Multi1 As String = mx12.text
Dim pars1() As String = Multi1.Split("-")
Dim c1 As Double = Val(pars1(0))
Dim c2 As Double = Val(pars1(1))
Dim z1 As Double
Dim z2 As Double
z1 = e1 + c1
z2 = e2 + c2
Dim y As String
Dim y1 As String
y = z1
y1 = z2
mx16.text = y + "-" + y1

 字符转数值,再转字符 ,帮我看看,这代码错在哪里?

 


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

 


 


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/3 16:10:00 [只看该作者]

Dim pars() As String = Multi.Split("-")
If pars.length <> 2 then

    msgbox("输入不正确")

    Return

End If


 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/8/3 16:55:00 [只看该作者]

Dim mx11 As WinForm.TextBox = e.Form.Controls("TBMX01")
Dim mx12 As WinForm.TextBox = e.Form.Controls("TBMX02")
Dim mx16 As WinForm.TextBox = e.Form.Controls("TBMX06")

Dim Multi2 As String = mx11.text
Dim pars2() As String = Multi2.Split("-")
If pars2.length <> 2 Then
    msgbox("输入不正确")
    Return
End If
Dim b1 As Double = Val(pars2(0))
Dim b2 As Double = Val(pars2(1))

Dim Multi1 As String = mx12.text
Dim pars1() As String = Multi1.Split("-")
If pars1.length <> 2 Then
    msgbox("输入不正确")
    Return
End If
Dim c1 As Double = Val(pars1(0))
Dim c2 As Double = Val(pars1(1))

Dim z1 As Double
Dim z2 As Double
If mx11.text > "" Then
    If mx12.text > "" Then
        z1 = b1 + c1
        z2 = b2 + c2
    Else
        z1 = b1
        z2 = b2
    End If
Else
    If mx12.text > "" Then
        z1 = c1
        z2 = c2
    Else
        z1 = ""
        z2 = ""
    End If
End If
Dim y As String = Val(z1)
Dim y1 As String = Val(z2)
mx16.text = y + "-" + y1

 

为什么单独在 “mx11”或“mx12”输入数据时 提示“输入不正确”


 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/8/3 17:21:00 [只看该作者]

Dim mx11 As WinForm.TextBox = e.Form.Controls("TBMX01")
Dim mx12 As WinForm.TextBox = e.Form.Controls("TBMX02")
Dim mx16 As WinForm.TextBox = e.Form.Controls("TBMX06")
Dim Multi2 As String = mx11.text
Dim Multi1 As String = mx12.text
Dim z1 As Double
Dim z2 As Double
If mx11.text > "" Then
    If mx12.text > "" Then
        Dim pars2() As String = Multi2.Split("+")
        Dim pars1() As String = Multi1.Split("+")
        If pars1.length <> 2 Then
            msgbox("输入不正确,请按照***+**的方式输入")
            Return
        End If
        Dim c1 As Double = Val(pars1(0))
        Dim c2 As Double = Val(pars1(1))
       
        If pars2.length <> 2 Then
            msgbox("输入不正确,请按照***+**的方式输入")
            Return
        End If
        Dim b1 As Double = Val(pars2(0))
        Dim b2 As Double = Val(pars2(1))
        z1 = b1 + c1
        z2 = b2 + c2
        Dim y As String = Val(z1)
        Dim y1 As String = Val(z2)
        mx16.text = y + "+" + y1
    Else
        Dim pars2() As String = Multi2.Split("+")
        If pars2.length <> 2 Then
            msgbox("输入不正确,请按照***+**的方式输入")
            Return
        End If
        Dim b1 As Double = Val(pars2(0))
        Dim b2 As Double = Val(pars2(1))
        z1 = b1
        z2 = b2
        Dim y As String = Val(z1)
        Dim y1 As String = Val(z2)
        mx16.text = y + "+" + y1
    End If
Else
    If mx12.text > "" Then
        Dim pars1() As String = Multi1.Split("+")
        If pars1.length <> 2 Then
            msgbox("输入不正确,请按照***+**的方式输入")
            Return
        End If
        Dim c1 As Double = Val(pars1(0))
        Dim c2 As Double = Val(pars1(1))
        z1 = c1
        z2 = c2
        Dim y As String = Val(z1)
        Dim y1 As String = Val(z2)
        mx16.text = y + "+" + y1
    Else
Return
    End If
End If

 

这样对吗,问题是如果有几十个框的话代码是不是太大了呀


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/3 17:50:00 [只看该作者]

直接说明你的逻辑,你想做什么?

 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/8/3 18:42:00 [只看该作者]

我有7*7 49个TextBox ,每行7个,还有7*1 ,7个每行1个

我想当每行TextBox 填入数据(比如 255+6)的时候自动在Label 合计,并且显示的数据也是和填入的格式一样

如图


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

怎么多的TextBox,这个代码不是要写晕过去的呀

 

Dim mx11 As WinForm.TextBox = e.Form.Controls("Tsa01")
Dim mx12 As WinForm.TextBox = e.Form.Controls("Tsa02")
Dim mx13 As WinForm.TextBox = e.Form.Controls("Tsa03")
Dim mx14 As WinForm.TextBox = e.Form.Controls("Tsa04")
Dim mx15 As WinForm.TextBox = e.Form.Controls("Tsa05")
Dim mx16 As WinForm.TextBox = e.Form.Controls("Tsa06")
Dim mx17 As WinForm.TextBox = e.Form.Controls("Tsa07")
Dim hjha As WinForm.Label = e.Form.Controls("ahj")
Dim Multia1 As String = mx11.text
Dim Multia2 As String = mx12.text
Dim Multia3 As String = mx13.text
Dim Multia4 As String = mx14.text
Dim Multia5 As String = mx15.text
Dim Multia6 As String = mx16.text
Dim Multia7 As String = mx17.text
Dim z1 As Double
Dim z2 As Double
If mx11.text > "" Then
    If mx12.text > "" Then
        Dim pars1() As String = Multia1.Split("+")
        Dim pars2() As String = Multia2.Split("+")
        If pars1.length <> 2 Then
            msgbox("输入不正确,请按照***+**的方式输入")
            Return
        End If
        Dim cfa21 As Double = Val(pars2(0))
        Dim cfa22 As Double = Val(pars2(1))
       
        If pars2.length <> 2 Then
            msgbox("输入不正确,请按照***+**的方式输入")
            Return
        End If
        Dim cfa11 As Double = Val(pars1(0))
        Dim cfa12 As Double = Val(pars1(1))
        z1 = cfa11 + cfa21
        z2 = cfa12 + cfa22
        Dim y As String = Val(z1)
        Dim y1 As String = Val(z2)
        hjha.text = y + "+" + y1
    Else
        Dim pars1() As String = Multia1.Split("+")
        If pars1.length <> 2 Then
            msgbox("输入不正确,请按照***+**的方式输入")
            Return
        End If
        Dim cfa11 As Double = Val(pars1(0))
        Dim cfa12 As Double = Val(pars1(1))
        z1 = cfa11
        z2 = cfa12
        Dim y As String = Val(z1)
        Dim y1 As String = Val(z2)
        hjha.text = y + "+" + y1
    End If
Else
    If mx12.text > "" Then
        Dim pars2() As String = Multia2.Split("+")
        If pars2.length <> 2 Then
            msgbox("输入不正确,请按照***+**的方式输入")
            Return
        End If
        Dim cfa21 As Double = Val(pars2(0))
        Dim cfa22 As Double = Val(pars2(1))
        z1 = cfa21
        z2 = cfa22
        Dim y As String = Val(z1)
        Dim y1 As String = Val(z2)
        hjha.text = y + "+" + y1
    Else
hjha.text = ""
Return
    End If
End If

[此贴子已经被作者于2016/8/3 18:43:37编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/3 18:53:00 [只看该作者]

 控件命名要规范, 前缀_行号_列号 这样,如 Tsa_1_1

 

 然后,写成循环

 

For i As Integer = 1 to 7

    Dim sum As Double = 0

    For j As Integer = 1 to 7

        Dim val As String = e.Form.Controls("Tsa_" & i & "_" & j).Text

        '这里实现你的逻辑

    Next

    e.Form.Controls("Tsa_" & i & "_8").Text = sum

Next


 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/8/3 21:10:00 [只看该作者]

晕倒,不会哦,能不能写个实例代码,让我学习学习啊


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

[此贴子已经被作者于2016/8/3 21:26:24编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/3 21:59:00 [只看该作者]

比如,横向的统计

 

For i As Integer = 1 To 7
    Dim sum1 As Double = 0
    Dim sum2 As Double = 0
    For j As Integer = 1 To 7
        Dim ary() As String = e.Form.Controls("Ts_" & i & "_" & j).Text.split("+")
        If ary.length = 2 Then
            sum1 += val(ary(0))
            sum2 += val(ary(1))
        End If
    Next
    e.Form.Controls("Ts_" & i & "_8").Text = sum1 & "+" & sum2
Next


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/3 22:00:00 [只看该作者]

纵向的统计,参考9楼,略微修改,即可。

 回到顶部