搜索
首页 电脑/网络 程序设计 VB

怎么样才能使2进制转为10进制?

  我创建一个COMMAND跟2个TEXT,要求TEXT1里只能输入0跟1,输入别的TEXT2里都是错误的,对了,还有没有什么简便的算法?我的程序里输入别的数还行啊! 我这个程序不知道哪错了,我刚学VB,请大家帮我看看 Private Sub Command1_Click() k = 0 For i = 1 To Len(Text1) If Val(Mid(Text1。
  Text, i, 1)) <> 0 Or Val(Mid(Text1。Text, i, 1)) <> 1 Then Text2。Text = "wrong" Else k = k + Mid(Text1。Text, i, 1) * 2 ^ (Len(Text1) - i) End If Next i Text2。
  Text = k End Sub 。

全部回答

2005-08-02

0 0
    '我也是刚学VB,但我这个程序可以通过。。。 Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii > 49 Or KeyAscii < 48 Then Text2。
  Text = "Wrong" End If End Sub Private Sub Command1_Click() k = 0 For i = 1 To Len(Text1) k = k + Mid(Text1。
    Text, i, 1) * 2 ^ (Len(Text1) - i) Next i Text2。Text = k End Sub 。

2005-08-17

71 0
    用如下代码能达到提问者目的。 Option Explicit Private Sub Form_Load() Text1 = "": Text2 = "" End Sub Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) If Mid(Text1, Len(Text1), 1) = 0 Or Mid(Text1, Len(Text1), 1) = 1 Then 'Or KeyAscii = 49 Text1 = UCase$(Text1) Text2 = "输入正确。
    " Text2。BackColor = vbGreen Else Text1。SelStart = Len(Text1) - 1 Text1。
  SelLength = 1 Text2 = "输入错误!" Text2。  BackColor = vbRed End If End Sub 也可用himlai和风舞冰尘的代码做改动,如下: Option Explicit Private Sub Form_Load() Text1 = "": Text2 = "" End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii > 49 Or KeyAscii < 48 Then Text2。
    Text = "Wrong" KeyAscii = 0 Else Text2。Text = "Right" End If End Sub 。
  

2005-08-03

64 0
这里可以稍微修改点 If KeyAscii > 49 Or KeyAscii < 48 Then KeyAscii=0

类似问题换一批

热点推荐

热度TOP

相关推荐
加载中...

热点搜索 换一换

电脑/网络
VB
程序设计
电脑装机
操作系统/系统故障
硬件
笔记本电脑
百度
互联网
反病毒
软件
程序设计
VB
数据库
C/C++
JAVA相关
C#/.NET
VC++
汇编语言
其他编程语言
VB
VB
举报
举报原因(必选):
取消确定举报