| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 328 人关注过本帖
标题:VB按键出错求解!!!急
只看楼主 加入收藏
webfly
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-12-13
结帖率:0
收藏
已结贴  问题点数:10 回复次数:3 
VB按键出错求解!!!急
代码如下:
Private Sub Command1_Click()
  Dim Senddata(56) As Byte
  Dim templong As Long
  Dim tempuint As Integer
  Dim tempbyte As Byte
  Dim Sendstr As String
  Dim k As Byte
  
 On Error GoTo err
  
  Sendata(0) = "&HFE"
  Sendata(1) = "&H68"
  Sendata(2) = "&H11"
  Sendata(3) = "&H11"
  Sendata(4) = "&H11"
  Sendata(5) = "&H11"
  Sendata(6) = "&H11"
  Sendata(7) = "&H11"
  Sendata(8) = "&H68"
  Sendata(9) = "&H14"
  
  Sendata(10) = "&H2C"
  Sendata(11) = "&H00"
  Sendata(12) = "&H20"
  Sendata(13) = "&HF8"
  Sendata(14) = "&H04"
      
  Sendata(15) = "&H03"
  Sendata(16) = "&H00"
  Sendata(17) = "&H00"
  Sendata(18) = "&H00"
  Sendata(19) = "&H00"
  Sendata(20) = "&H00"
  Sendata(21) = "&H00"
  Sendata(22) = "&H00"

      
     templong = Val(changshu.Text)
     tempbyte = templong Mod 256
     Sendata(23) = "&H" + Hex(tempbyte)
     tempbyte = Int(templong / 256)
     Sendata(24) = "&H" + Hex(tempbyte)       'Const 发送时,高位在前,低位在后。其他标准值数据均是低位在前,高位在后
  

     
     templong = Val(Text1.Text) * 100         'A voltage
     tempbyte = templong Mod 256
     Sendata(25) = "&H" + Hex(tempbyte)
     tempbyte = Int(templong / 256)
     Sendata(26) = "&H" + Hex(tempbyte)
     
     templong = Val(Text2.Text) * 100        'B voltage
     tempbyte = templong Mod 256
     Sendata(27) = "&H" + Hex(tempbyte)
     tempbyte = Int(templong / 256)
     Sendata(28) = "&H" + Hex(tempbyte)
     
     templong = Val(Text3.Text) * 100        'C voltage
     tempbyte = templong Mod 256
     Sendata(29) = "&H" + Hex(tempbyte)
     tempbyte = Int(templong / 256)
     Sendata(30) = "&H" + Hex(tempbyte)
     
     templong = Val(Text4.Text) * 1000       'A current
     tempbyte = templong Mod 256
     Sendata(31) = "&H" + Hex(tempbyte)
     tempbyte = Int(templong / 256)
     Sendata(32) = "&H" + Hex(tempbyte)
     
     templong = Val(Text5.Text) * 1000       'B current
     tempbyte = templong Mod 256
     Sendata(33) = "&H" + Hex(tempbyte)
     tempbyte = Int(templong / 256)
     Sendata(34) = "&H" + Hex(tempbyte)
     
     templong = Val(Text6.Text) * 1000       'C current
     tempbyte = templong Mod 256
     Sendata(35) = "&H" + Hex(tempbyte)
     tempbyte = Int(templong / 256)
     Sendata(36) = "&H" + Hex(tempbyte)
     
     templong = Val(Text8.Text) * 10
     tempbyte = templong Mod 256
     tempuint = templong / 256
     Sendata(37) = "&H" + Hex(tempbyte)
     tempbyte = tempuint Mod 256
     Sendata(38) = "&H" + Hex(tempbyte)
     tempbyte = tempuint / 256
     Sendata(39) = "&H" + Hex(tempbyte)
     
     templong = Val(Text9.Text) * 10
     tempbyte = templong Mod 256
     tempuint = templong / 256
     Sendata(40) = "&H" + Hex(tempbyte)
     tempbyte = tempuint Mod 256
     Sendata(41) = "&H" + Hex(tempbyte)
     tempbyte = tempuint / 256
     Sendata(42) = "&H" + Hex(tempbyte)
     
     templong = Val(Text21.Text) * 10
     tempbyte = templong Mod 256
     tempuint = templong / 256
     Sendata(43) = "&H" + Hex(tempbyte)
     tempbyte = tempuint Mod 256
     Sendata(44) = "&H" + Hex(tempbyte)
     tempbyte = tempuint / 256
     Sendata(45) = "&H" + Hex(tempbyte)
     
     templong = Val(Text22.Text) * 10
     tempbyte = templong Mod 256
     tempuint = templong / 256
     Sendata(46) = "&H" + Hex(tempbyte)
     tempbyte = tempuint Mod 256
     Sendata(47) = "&H" + Hex(tempbyte)
     tempbyte = tempuint / 256
     Sendata(48) = "&H" + Hex(tempbyte)
     
     templong = Val(Text23.Text) * 10
     tempbyte = templong Mod 256
     tempuint = templong / 256
     Sendata(49) = "&H" + Hex(tempbyte)
     tempbyte = tempuint Mod 256
     Sendata(50) = "&H" + Hex(tempbyte)
     tempbyte = tempuint / 256
     Sendata(51) = "&H" + Hex(tempbyte)
     
     templong = Val(Text24.Text) * 10
     tempbyte = templong Mod 256
     tempuint = templong / 256
     Sendata(52) = "&H" + Hex(tempbyte)
     tempbyte = tempuint Mod 256
     Sendata(53) = "&H" + Hex(tempbyte)
     tempbyte = tempuint / 256
     Sendata(54) = "&H" + Hex(tempbyte)
     
     
     If Check1.Value = 1 Then
        tempbyte = Val(Text19.Text)
        Sendata(59) = "&H" + Hex(tempbyte)
        m = 59
        Call Add33
        For k = 0 To 61
           Senddata(k) = Sendata(k)
        Next k
    Else
        m = 54
        Call Add33
        For k = 0 To 56
           Senddata(k) = Sendata(k)
        Next k
    End If
     
     index = 12
     MSComm1.OutBufferCount = 0
     MSComm1.Output = Senddata
     MSComm1.RThreshold = 13
     MSComm1.InBufferCount = 0
     
     Command4.Enabled = True
err:
   Load Me
 
End Sub

运行后,如果不在文本框中输入数据或输入数据不超过3个,则按键Click可以响应,如果输入的数据超过3个,则Click事件不响应
这是怎么回事呢?是因为数据太多吗?
搜索更多相关主题的帖子: 按键 
2012-12-13 18:24
webfly
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-12-13
收藏
得分:0 
急啊,求高手解决!自己先顶起
2012-12-13 18:36
webfly
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-12-13
收藏
得分:0 
已解决
2012-12-13 19:41
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:10 
tempbyte = Int(templong / 256)错了
      Sendata(24) = "&H" + Hex(tempbyte)

无知
2012-12-14 12:48
快速回复:VB按键出错求解!!!急
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015805 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved