永发信息网

vb串口通信中怎么把接收到的一串十六进制数放到一个动态数组中

答案:2  悬赏:10  手机版
解决时间 2021-02-06 22:44
其中接收到的那串十六进制数字节数是可变的

哪位高手指点下
最佳答案
在load里面定义一个 dim aa() as byte
再在接收里面重新定义一个
dim i as interge
redim aa(1-i)
再存入即可
全部回答
'字符表示的十六进制数转化为相应的整数,错误则返回 -1 function converthexchr(str as string) as integer dim test as integer test = asc(str) if test >= asc("0") and test <= asc("9") then test = test - asc("0") elseif test >= asc("a") and test <= asc("f") then test = test - asc("a") + 10 elseif test >= asc("a") and test <= asc("f") then test = test - asc("a") + 10 else test = -1 '出错信息 end if converthexchr = test end function '字符串表示的十六进制数据转化为相应的字节串,返回转化后的字节数 function strhextobytearray(strtext as string, bytbyte() as byte) as integer dim hexdata as integer '十六进制(二进制)数据字节对应值 dim hstr as string * 1 '高位字符 dim lstr as string * 1 '低位字符 dim highhexdata as integer '高位数值 dim lowhexdata as integer '低位数值 dim hexdatalen as integer '字节数 dim stringlen as integer '字符串长度 dim account as integer dim n as integer '计数 'txtsend = "" '设初值 hexdatalen = 0 strhextobytearray = 0 stringlen = len(strtext) account = stringlen \ 2 redim bytbyte(account) for n = 1 to stringlen do '清除空格 hstr = mid(strtext, n, 1) n = n + 1 if (n - 1) > stringlen then hexdatalen = hexdatalen - 1 exit for end if loop while hstr = " " do lstr = mid(strtext, n, 1) n = n + 1 if (n - 1) > stringlen then hexdatalen = hexdatalen - 1 exit for end if loop while lstr = " " n = n - 1 if n > stringlen then hexdatalen = hexdatalen - 1 exit for end if highhexdata = converthexchr(hstr) lowhexdata = converthexchr(lstr) if highhexdata = -1 or lowhexdata = -1 then '遇到非法字符中断转化 hexdatalen = hexdatalen - 1 exit for else hexdata = highhexdata * 16 + lowhexdata bytbyte(hexdatalen) = hexdata hexdatalen = hexdatalen + 1 end if next n if hexdatalen > 0 then '修正最后一次循环改变的数值 hexdatalen = hexdatalen - 1 redim preserve bytbyte(hexdatalen) else redim preserve bytbyte(0) end if if stringlen = 0 then '如果是空串,则不会进入循环体 strhextobytearray = 0 else strhextobytearray = hexdatalen + 1 end if end function 下面跟你介绍strhextobytearray(strtext as string, bytbyte() as byte)的功能。 假如text内输入"ff fe aa 14 af"(引号内的包括空格)那么 strhextobytearray=5 则bytebyte()中 bytebyte(0)=ff bytebyte(1)=fe bytebyte(2)=aa bytebyte(3)=14 bytebyte(4)=af 注意:假如输入你想输入1,则必须写01 我想有了这个函数会给你很大的帮助。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
百度糯米…到店付…自助餐…我把百度糯米的到
金剪子发型设计地址有知道的么?有点事想过去
唱吧怎么导入视频啊?(不是录视频!!)。就比
【he takes no please in his work】
花絮家纺(工厂直销店)这个地址在什么地方,我
为什么我的为胃老实反酸,难受的很,这是怎么
琪美造型地址在什么地方,想过去办事
要给一片庄稼施肥,每公顷施75kg,则多60kg,每
浙江台州椒江海洋世界门票是多少?
家里没体重称的,没资格说话。谢谢。应该相信
观音菩萨圣杯
靓点美容美发中心地址在什么地方,想过去办事
江西省第二人民医院在哪里啊,我有事要去这个
在碳酸盐岩石地区,土洞和塌陷一般由下列()原
公司电脑下载被封 求解决
推荐资讯
求 Nightstep - Run Away 歌词
什么是起酥性?
以前看过的一个穿越架空小言,女主是宰相千金
遥望蓝天,我们渴望像小鸟一样,自由自在地展
金通加油站地址在什么地方,想过去办事
真正英语教育中心地址在哪,我要去那里办事
自然铜醋煅淬后主要成分是A.硫化亚铁B.硫化铁
甜蜜都市零食量贩地址在什么地方,想过去办事
led显示屏显示特技怎么才是最正确的
2019年新学案同步导与练七年级数学上册北师大
=真的 不是要英语翻译
里有哒哒哒的声音是怎么回事
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?