?? form1.vb
字號:
Imports System.Math
Public Class Form1
Inherits System.Windows.Forms.Form
'TranDec( )函數是將十進制整數(iDec)轉換成任意進制
Function TranDec$(ByVal m, ByVal r)
Dim imr(60) As Integer '存放不斷除r后得到的余數
Dim strBase As String : Dim StrDtoR$ : Dim iB, i As Integer
strBase = "0123456789ABCDEF"
i = 0
Do While m <> 0 '不斷除某進制取余直到商為0
imr(i) = m Mod r
m = m \ r
i = i + 1
Loop
StrDtoR = ""
i = i + 1
Do While i >= 0 '形成某進制的字符串
iB = imr(i) '將余數轉換成對應的字符
StrDtoR = StrDtoR + Mid$(strBase, iB + 1, 1)
i = i - 1
Loop
TranDec = StrDtoR
End Function
#Region " Windows 窗體設計器生成的代碼 "
Public Sub New()
MyBase.New()
'該調用是 Windows 窗體設計器所必需的。
InitializeComponent()
'在 InitializeComponent() 調用之后添加任何初始化
End Sub
'窗體重寫處置以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗體設計器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下過程是 Windows 窗體設計器所必需的
'可以使用 Windows 窗體設計器修改此過程。
'不要使用代碼編輯器修改它。
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.TextBox3 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("黑體", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.Location = New System.Drawing.Point(48, 144)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "轉換"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("宋體", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.Location = New System.Drawing.Point(16, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(112, 23)
Me.Label1.TabIndex = 1
Me.Label1.Text = "輸入十進制數:"
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("宋體", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label2.Location = New System.Drawing.Point(16, 56)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(112, 23)
Me.Label2.TabIndex = 2
Me.Label2.Text = "輸入R進制:"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(16, 104)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(120, 23)
Me.Label3.TabIndex = 3
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(152, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 4
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(152, 48)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 5
Me.TextBox2.Text = ""
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(152, 88)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.TabIndex = 6
Me.TextBox3.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(7, 16)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox3, Me.TextBox2, Me.TextBox1, Me.Label3, Me.Label2, Me.Label1, Me.Button1})
Me.Font = New System.Drawing.Font("宋體", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim m0%, r0%, I%
m0 = Val(TextBox1.Text) '輸入十進制正整數
r0 = Val(TextBox2.Text) '輸入r進制
If r0 < 2 Or r0 > 16 Then
I = MsgBox("輸入的r進制數超出范圍", vbRetryCancel)
If I = vbRetry Then
TextBox2.Text = ""
Else
End
End If
End If
Label3.Text = "轉換成" & r0 & "進制數" '轉換標簽隨輸入的進制改革
TextBox3.Text = TranDec(m0, r0) '調用轉換函數,顯示轉換結果
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -