VB设计两个机器数做运算!在线等!高分!
text1和text2分别输入两个机器数(二进制,首位为符号位,0代表正,1代表负)还有一个option,四个选项为加减乘除,要实现command1.click,在lab...
text1和text2分别输入两个机器数(二进制,首位为符号位,0代表正,1代表负) 还有一个option,四个选项为加减乘除,要实现command1.click,在label1中显示运算结果。。。。急急急,在线等!!!
re:chenxfsoft
你这样是把二进制数当做十进制数运算了。。。 展开
re:chenxfsoft
你这样是把二进制数当做十进制数运算了。。。 展开
2个回答
展开全部
Private sub text1_KeyPress(...)
if asc = '0' or asc = '1' then
text1.text=text1.text+asc
end if
end sub
Private sub command1_click()
dim OPD1,OPD2,R AS LONG
OPD1=STR2BIN(text1.text)
OPD2=STR2BIN(text2.text)
select case true
case option(1).value
R=OPD1+OPD2
case option(2).value
R=OPD1-OPD2
case option(3).value
R=OPD1*OPD2
case option(4).value
if OPD2 = 0 then
msgbox "出错!"
else
R=OPD1/OPD2
end if
case else
'
end select
label1.caption = Str(R)
end sub
PUBLIC FUNCTION STR2BIN(ByVal S as String) AS LONG
dim Num as long
dim i,L as long
S=Trim(S)
L=Len(S)-1
Num=0
For i = 1 to L step 1
Num=Num+Val(Mid(S,i,1))*2^(L-i)
Next i
if left(S)='1' then
Num=2^L-Num
end if
STR2BIN=Num
END FUNCTION
if asc = '0' or asc = '1' then
text1.text=text1.text+asc
end if
end sub
Private sub command1_click()
dim OPD1,OPD2,R AS LONG
OPD1=STR2BIN(text1.text)
OPD2=STR2BIN(text2.text)
select case true
case option(1).value
R=OPD1+OPD2
case option(2).value
R=OPD1-OPD2
case option(3).value
R=OPD1*OPD2
case option(4).value
if OPD2 = 0 then
msgbox "出错!"
else
R=OPD1/OPD2
end if
case else
'
end select
label1.caption = Str(R)
end sub
PUBLIC FUNCTION STR2BIN(ByVal S as String) AS LONG
dim Num as long
dim i,L as long
S=Trim(S)
L=Len(S)-1
Num=0
For i = 1 to L step 1
Num=Num+Val(Mid(S,i,1))*2^(L-i)
Next i
if left(S)='1' then
Num=2^L-Num
end if
STR2BIN=Num
END FUNCTION
展开全部
dim a as double
dim b as double
dim c as double
a=val(text1.text)
b=val(text2.text)
select case true
case option1.value
c=a+b
case option2.value
c=a-b
case option3.value
c=a*b
case else
if b = 0 then
label1.caption = "被0除出错!"
else
c=a/b
endif
end select
label1.caption = c
dim b as double
dim c as double
a=val(text1.text)
b=val(text2.text)
select case true
case option1.value
c=a+b
case option2.value
c=a-b
case option3.value
c=a*b
case else
if b = 0 then
label1.caption = "被0除出错!"
else
c=a/b
endif
end select
label1.caption = c
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询