VB菜鸟编程问题
输入一个十进制的数,利用单选按钮控制,用命令按钮执行转换,分别转换为二进制,十六进制,八进制设计窗体菜单的子菜单:要求字体子菜单设计成一个控件数组,用于设...
输入一个十进制的数,利用单选按钮控制,用命令按钮执行转换,分别转换为二进制,十六进制,八进制
设计窗体菜单的子菜单:
要求字体子菜单设计成一个控件数组,用于设计文本框的字体
单击“文字颜色”后,打开“颜色”对话框,用于设置文本框中的文字颜色,单击“背景颜色”后,打开“颜色”对话框,用于设置文本框的背景颜色
“属性”菜单初始状态如图2所示,单击“只读”后可以在该项前面打上对号或取消对号,用于控制文本框是否只读;而单击“隐藏”后将文本框隐藏起来,同时该项名称变为“显示”,再单击“显示”将显示文本框,同时该项名称变为“隐藏”
讲一下过程 展开
设计窗体菜单的子菜单:
要求字体子菜单设计成一个控件数组,用于设计文本框的字体
单击“文字颜色”后,打开“颜色”对话框,用于设置文本框中的文字颜色,单击“背景颜色”后,打开“颜色”对话框,用于设置文本框的背景颜色
“属性”菜单初始状态如图2所示,单击“只读”后可以在该项前面打上对号或取消对号,用于控制文本框是否只读;而单击“隐藏”后将文本框隐藏起来,同时该项名称变为“显示”,再单击“显示”将显示文本框,同时该项名称变为“隐藏”
讲一下过程 展开
5个回答
展开全部
VERSION 5.00
Begin VB.Form Form1
Caption = "By Pcsun"
ClientHeight = 3045
ClientLeft = 60
ClientTop = 450
ClientWidth = 3870
LinkTopic = "Form1"
ScaleHeight = 3045
ScaleWidth = 3870
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "转 换"
Height = 375
Left = 720
TabIndex = 7
Top = 2280
Width = 2295
End
Begin VB.TextBox Text2
Height = 495
Left = 1920
TabIndex = 6
Top = 960
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 1920
TabIndex = 4
Top = 240
Width = 1215
End
Begin VB.OptionButton Option3
Caption = "十六进制"
Height = 255
Left = 2520
TabIndex = 2
Top = 1800
Width = 1215
End
Begin VB.OptionButton Option2
Caption = "八进制"
Height = 255
Left = 1320
TabIndex = 1
Top = 1800
Width = 1215
End
Begin VB.OptionButton Option1
Caption = "二进制"
Height = 255
Left = 240
TabIndex = 0
Top = 1800
Value = -1 'True
Width = 975
End
Begin VB.Label Label2
Caption = "转换成"
Height = 375
Left = 360
TabIndex = 5
Top = 1080
Width = 1335
End
Begin VB.Label Label1
Caption = "输入十进制数值:"
Height = 255
Left = 360
TabIndex = 3
Top = 360
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Function bintodec(s As String) As Long
bintodec = 0
For i = Len(s) To 1 Step -1
bintodec = Val(Mid(s, i, 1)) * (2 ^ (Len(s) - i)) + bintodec
Next i
End Function
Function octtodec(s As String) As Long
octtodec = 0
For i = Len(s) To 1 Step -1
octtodec = Val(Mid(s, i, 1)) * (8 ^ (Len(s) - i)) + octtodec
Next i
End Function
Function hextodec(s As String) As Long
hextodec = 0
For i = Len(s) To 1 Step -1
hextodec = Val("&h" + Mid(s, i, 1)) * (16 ^ (Len(s) - i)) + hextodec
Next i
End Function
Public Function dec2bin(mynum As Long) As String
Dim loopcounter As Long
If mynum >= 2 ^ 31 Then
dec2bin = "Too big"
Exit Function
End If
Do
If (mynum And 2 ^ loopcounter) = 2 ^ loopcounter Then
dec2bin = "1" & dec2bin
Else
dec2bin = "0" & dec2bin
End If
loopcounter = loopcounter + 1
Loop Until 2 ^ loopcounter > mynum
End Function
Public Function dec2oct(mynum As Long) As String
Dim loopcounter As Long
If mynum >= 8 ^ 31 Then
dec2oct = "Too big"
Exit Function
End If
loopcounter = 1
dec2oct = ""
Do
dec2oct = Trim(Str(mynum Mod (8))) + dec2oct
mynum = mynum - (mynum Mod (8))
mynum = mynum / 8
loopcounter = loopcounter + 1
Loop Until mynum < 8
If Not (mynum = 0) Then
dec2oct = Trim(Str(mynum)) + dec2oct
End If
End Function
Private Sub Command1_Click()
If Option1.Value = True Then Text2 = dec2bin(Val(Text1))
If Option2.Value = True Then Text2 = dec2oct(Val(Text1))
If Option3.Value = True Then Text2 = Hex(Val(Text1))
End Sub
Private Sub Form_Load()
End Sub
将以上内容弄到记事本中,另存为一个form1.frm
之后执行就ok了
Begin VB.Form Form1
Caption = "By Pcsun"
ClientHeight = 3045
ClientLeft = 60
ClientTop = 450
ClientWidth = 3870
LinkTopic = "Form1"
ScaleHeight = 3045
ScaleWidth = 3870
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "转 换"
Height = 375
Left = 720
TabIndex = 7
Top = 2280
Width = 2295
End
Begin VB.TextBox Text2
Height = 495
Left = 1920
TabIndex = 6
Top = 960
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 1920
TabIndex = 4
Top = 240
Width = 1215
End
Begin VB.OptionButton Option3
Caption = "十六进制"
Height = 255
Left = 2520
TabIndex = 2
Top = 1800
Width = 1215
End
Begin VB.OptionButton Option2
Caption = "八进制"
Height = 255
Left = 1320
TabIndex = 1
Top = 1800
Width = 1215
End
Begin VB.OptionButton Option1
Caption = "二进制"
Height = 255
Left = 240
TabIndex = 0
Top = 1800
Value = -1 'True
Width = 975
End
Begin VB.Label Label2
Caption = "转换成"
Height = 375
Left = 360
TabIndex = 5
Top = 1080
Width = 1335
End
Begin VB.Label Label1
Caption = "输入十进制数值:"
Height = 255
Left = 360
TabIndex = 3
Top = 360
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Function bintodec(s As String) As Long
bintodec = 0
For i = Len(s) To 1 Step -1
bintodec = Val(Mid(s, i, 1)) * (2 ^ (Len(s) - i)) + bintodec
Next i
End Function
Function octtodec(s As String) As Long
octtodec = 0
For i = Len(s) To 1 Step -1
octtodec = Val(Mid(s, i, 1)) * (8 ^ (Len(s) - i)) + octtodec
Next i
End Function
Function hextodec(s As String) As Long
hextodec = 0
For i = Len(s) To 1 Step -1
hextodec = Val("&h" + Mid(s, i, 1)) * (16 ^ (Len(s) - i)) + hextodec
Next i
End Function
Public Function dec2bin(mynum As Long) As String
Dim loopcounter As Long
If mynum >= 2 ^ 31 Then
dec2bin = "Too big"
Exit Function
End If
Do
If (mynum And 2 ^ loopcounter) = 2 ^ loopcounter Then
dec2bin = "1" & dec2bin
Else
dec2bin = "0" & dec2bin
End If
loopcounter = loopcounter + 1
Loop Until 2 ^ loopcounter > mynum
End Function
Public Function dec2oct(mynum As Long) As String
Dim loopcounter As Long
If mynum >= 8 ^ 31 Then
dec2oct = "Too big"
Exit Function
End If
loopcounter = 1
dec2oct = ""
Do
dec2oct = Trim(Str(mynum Mod (8))) + dec2oct
mynum = mynum - (mynum Mod (8))
mynum = mynum / 8
loopcounter = loopcounter + 1
Loop Until mynum < 8
If Not (mynum = 0) Then
dec2oct = Trim(Str(mynum)) + dec2oct
End If
End Function
Private Sub Command1_Click()
If Option1.Value = True Then Text2 = dec2bin(Val(Text1))
If Option2.Value = True Then Text2 = dec2oct(Val(Text1))
If Option3.Value = True Then Text2 = Hex(Val(Text1))
End Sub
Private Sub Form_Load()
End Sub
将以上内容弄到记事本中,另存为一个form1.frm
之后执行就ok了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim i As Long
i = Val(Text1.Text)
If Option1.Value = True Then '二进制
MsgBox "二进制结果为" & cBin(i)
ElseIf Option2.Value = True Then '十六进制
MsgBox "十六进制结果为:" & Hex(i)
Else
MsgBox "八进制结果为:" & Oct(i)
End If
End Sub
Function cBin(ByVal N As Long) As String
Do
cBin = N Mod 2 & cBin
N = N \ 2
Loop While N > 0
End Function
Dim i As Long
i = Val(Text1.Text)
If Option1.Value = True Then '二进制
MsgBox "二进制结果为" & cBin(i)
ElseIf Option2.Value = True Then '十六进制
MsgBox "十六进制结果为:" & Hex(i)
Else
MsgBox "八进制结果为:" & Oct(i)
End If
End Sub
Function cBin(ByVal N As Long) As String
Do
cBin = N Mod 2 & cBin
N = N \ 2
Loop While N > 0
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public a As Integer
Private Sub Command1_Click()
Dim str As String
Dim num, result As Integer
str = Text1.Text
num = Val(str)
Select Case a
Case 1: '2jinzhi
result = d_to_b(num)
Case 2: '8jinzhi
result = h_to_b(num)
result = b_to_d(result)
Case 3: '16jinzhi
result = h_to_b(num)
result = b_to_d(result)
End Select
Text1.Text = result
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Option1_Click()
a = 1
End Sub
Private Sub Option2_Click()
a = 2
End Sub
Private Sub Option3_Click()
a = 3
End Sub
Public Function d_to_b(ByVal dec As Long) As String
Do
d_to_b = dec Mod 2 & d_to_b
dec = dec \ 2
Loop While dec
End Function
Public Function b_to_d(ByVal bin As String) As Integer
Dim i As Long
For i = 1 To Len(bin)
b_to_d = b_to_d * 2 + Val(Mid(bin, i, 1))
Next i
End Function
Public Function h_to_b(ByVal hex As String) As String
Dim i As Long
Dim b As String
hex = UCase(hex)
For i = 1 To Len(hex)
Select Case Mid(hex, i, 1)
Case "0": b = b & "0000"
Case "1": b = b & "0001"
Case "2": b = b & "0010"
Case "3": b = b & "0011"
Case "4": b = b & "0100"
Case "5": b = b & "0101"
Case "6": b = b & "0110"
Case "7": b = b & "0111"
Case "8": b = b & "1000"
Case "9": b = b & "1001"
Case "a": b = b & "1010"
Case "b": b = b & "1011"
Case "c": b = b & "1100"
Case "d": b = b & "1101"
Case "e": b = b & "1110"
Case "f": b = b & "1111"
End Select
Next i
While Left(b, 1) = "0"
b = Right(b, Len(b) - 1)
Wend
h_to_b = b
End Function
Public Function b_to_h(ByVal bin As String) As String
Dim i As Long
Dim h As String
If Len(bin) Mod 4 <> 0 Then
bin = String(4 - Len(bin) Mod 4, "0") & bin
End If
For i = 1 To Len(bin) Step 4
Select Case Mid(bin, i, 4)
Case "0000": h = h & "0"
Case "0001": h = h & "1"
Case "0010": h = h & "2"
Case "0011": h = h & "3"
Case "0100": h = h & "4"
Case "0101": h = h & "5"
Case "0110": h = h & "6"
Case "0111": h = h & "7"
Case "1000": h = h & "8"
Case "1001": h = h & "9"
Case "1010": h = h & "a"
Case "1011": h = h & "b"
Case "1100": h = h & "c"
Case "1101": h = h & "d"
Case "1110": h = h & "e"
Case "1111": h = h & "f"
End Select
Next i
b_to_h = h
End Function
Private Sub Command1_Click()
Dim str As String
Dim num, result As Integer
str = Text1.Text
num = Val(str)
Select Case a
Case 1: '2jinzhi
result = d_to_b(num)
Case 2: '8jinzhi
result = h_to_b(num)
result = b_to_d(result)
Case 3: '16jinzhi
result = h_to_b(num)
result = b_to_d(result)
End Select
Text1.Text = result
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Option1_Click()
a = 1
End Sub
Private Sub Option2_Click()
a = 2
End Sub
Private Sub Option3_Click()
a = 3
End Sub
Public Function d_to_b(ByVal dec As Long) As String
Do
d_to_b = dec Mod 2 & d_to_b
dec = dec \ 2
Loop While dec
End Function
Public Function b_to_d(ByVal bin As String) As Integer
Dim i As Long
For i = 1 To Len(bin)
b_to_d = b_to_d * 2 + Val(Mid(bin, i, 1))
Next i
End Function
Public Function h_to_b(ByVal hex As String) As String
Dim i As Long
Dim b As String
hex = UCase(hex)
For i = 1 To Len(hex)
Select Case Mid(hex, i, 1)
Case "0": b = b & "0000"
Case "1": b = b & "0001"
Case "2": b = b & "0010"
Case "3": b = b & "0011"
Case "4": b = b & "0100"
Case "5": b = b & "0101"
Case "6": b = b & "0110"
Case "7": b = b & "0111"
Case "8": b = b & "1000"
Case "9": b = b & "1001"
Case "a": b = b & "1010"
Case "b": b = b & "1011"
Case "c": b = b & "1100"
Case "d": b = b & "1101"
Case "e": b = b & "1110"
Case "f": b = b & "1111"
End Select
Next i
While Left(b, 1) = "0"
b = Right(b, Len(b) - 1)
Wend
h_to_b = b
End Function
Public Function b_to_h(ByVal bin As String) As String
Dim i As Long
Dim h As String
If Len(bin) Mod 4 <> 0 Then
bin = String(4 - Len(bin) Mod 4, "0") & bin
End If
For i = 1 To Len(bin) Step 4
Select Case Mid(bin, i, 4)
Case "0000": h = h & "0"
Case "0001": h = h & "1"
Case "0010": h = h & "2"
Case "0011": h = h & "3"
Case "0100": h = h & "4"
Case "0101": h = h & "5"
Case "0110": h = h & "6"
Case "0111": h = h & "7"
Case "1000": h = h & "8"
Case "1001": h = h & "9"
Case "1010": h = h & "a"
Case "1011": h = h & "b"
Case "1100": h = h & "c"
Case "1101": h = h & "d"
Case "1110": h = h & "e"
Case "1111": h = h & "f"
End Select
Next i
b_to_h = h
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public Function D_To_B(ByVal Dec As Long) As String
Do
D_To_B = Dec Mod 2 & D_To_B
Dec = Dec \ 2
Loop While Dec
End Function
Public Function B_To_D(ByVal Bin As String) As Integer
Dim i As Long
For i = 1 To Len(Bin)
B_To_D = B_To_D * 2 + Val(Mid(Bin, i, 1))
Next i
End Function
Public Function H_To_B(ByVal Hex As String) As String
Dim i As Long
Dim B As String
Hex = UCase(Hex)
For i = 1 To Len(Hex)
Select Case Mid(Hex, i, 1)
Case "0": B = B & "0000"
Case "1": B = B & "0001"
Case "2": B = B & "0010"
Case "3": B = B & "0011"
Case "4": B = B & "0100"
Case "5": B = B & "0101"
Case "6": B = B & "0110"
Case "7": B = B & "0111"
Case "8": B = B & "1000"
Case "9": B = B & "1001"
Case "A": B = B & "1010"
Case "B": B = B & "1011"
Case "C": B = B & "1100"
Case "D": B = B & "1101"
Case "E": B = B & "1110"
Case "F": B = B & "1111"
End Select
Next i
While Left(B, 1) = "0"
B = Right(B, Len(B) - 1)
Wend
H_To_B = B
End Function
Public Function B_To_H(ByVal Bin As String) As String
Dim i As Long
Dim H As String
If Len(Bin) Mod 4 <> 0 Then
Bin = String(4 - Len(Bin) Mod 4, "0") & Bin
End If
For i = 1 To Len(Bin) Step 4
Select Case Mid(Bin, i, 4)
Case "0000": H = H & "0"
Case "0001": H = H & "1"
Case "0010": H = H & "2"
Case "0011": H = H & "3"
Case "0100": H = H & "4"
Case "0101": H = H & "5"
Case "0110": H = H & "6"
Case "0111": H = H & "7"
Case "1000": H = H & "8"
Case "1001": H = H & "9"
Case "1010": H = H & "A"
Case "1011": H = H & "B"
Case "1100": H = H & "C"
Case "1101": H = H & "D"
Case "1110": H = H & "E"
Case "1111": H = H & "F"
End Select
Next i
B_To_H = H
End Function
Do
D_To_B = Dec Mod 2 & D_To_B
Dec = Dec \ 2
Loop While Dec
End Function
Public Function B_To_D(ByVal Bin As String) As Integer
Dim i As Long
For i = 1 To Len(Bin)
B_To_D = B_To_D * 2 + Val(Mid(Bin, i, 1))
Next i
End Function
Public Function H_To_B(ByVal Hex As String) As String
Dim i As Long
Dim B As String
Hex = UCase(Hex)
For i = 1 To Len(Hex)
Select Case Mid(Hex, i, 1)
Case "0": B = B & "0000"
Case "1": B = B & "0001"
Case "2": B = B & "0010"
Case "3": B = B & "0011"
Case "4": B = B & "0100"
Case "5": B = B & "0101"
Case "6": B = B & "0110"
Case "7": B = B & "0111"
Case "8": B = B & "1000"
Case "9": B = B & "1001"
Case "A": B = B & "1010"
Case "B": B = B & "1011"
Case "C": B = B & "1100"
Case "D": B = B & "1101"
Case "E": B = B & "1110"
Case "F": B = B & "1111"
End Select
Next i
While Left(B, 1) = "0"
B = Right(B, Len(B) - 1)
Wend
H_To_B = B
End Function
Public Function B_To_H(ByVal Bin As String) As String
Dim i As Long
Dim H As String
If Len(Bin) Mod 4 <> 0 Then
Bin = String(4 - Len(Bin) Mod 4, "0") & Bin
End If
For i = 1 To Len(Bin) Step 4
Select Case Mid(Bin, i, 4)
Case "0000": H = H & "0"
Case "0001": H = H & "1"
Case "0010": H = H & "2"
Case "0011": H = H & "3"
Case "0100": H = H & "4"
Case "0101": H = H & "5"
Case "0110": H = H & "6"
Case "0111": H = H & "7"
Case "1000": H = H & "8"
Case "1001": H = H & "9"
Case "1010": H = H & "A"
Case "1011": H = H & "B"
Case "1100": H = H & "C"
Case "1101": H = H & "D"
Case "1110": H = H & "E"
Case "1111": H = H & "F"
End Select
Next i
B_To_H = H
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VB书上有!自己找一下!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询