Public Class Form1 Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New() MyBase.New()
'This call is required by the Windows Form Designer. InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list. 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
'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. 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 Label4 As System.Windows.Forms.Label Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents txtd1 As System.Windows.Forms.TextBox Friend WithEvents txtn1 As System.Windows.Forms.TextBox Friend WithEvents txtd2 As System.Windows.Forms.TextBox Friend WithEvents txtn2 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.txtd1 = New System.Windows.Forms.TextBox Me.Label2 = New System.Windows.Forms.Label Me.txtn1 = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.txtd2 = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.txtn2 = New System.Windows.Forms.TextBox Me.Button1 = New System.Windows.Forms.Button Me.Button2 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(32, 24) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(48, 16) Me.Label1.TabIndex = 0 Me.Label1.Text = "d1 =" ' 'txtd1 ' Me.txtd1.Location = New System.Drawing.Point(80, 16) Me.txtd1.Name = "txtd1" Me.txtd1.Size = New System.Drawing.Size(88, 20) Me.txtd1.TabIndex = 1 Me.txtd1.Text = "" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(32, 56) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(48, 16) Me.Label2.TabIndex = 2 Me.Label2.Text = "n1 =" ' 'txtn1 ' Me.txtn1.Location = New System.Drawing.Point(80, 48) Me.txtn1.Name = "txtn1" Me.txtn1.Size = New System.Drawing.Size(320, 20) Me.txtn1.TabIndex = 3 Me.txtn1.Text = "" ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(32, 88) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(48, 16) Me.Label3.TabIndex = 4 Me.Label3.Text = "d2 =" ' 'txtd2 ' Me.txtd2.Location = New System.Drawing.Point(80, 80) Me.txtd2.Name = "txtd2" Me.txtd2.Size = New System.Drawing.Size(88, 20) Me.txtd2.TabIndex = 5 Me.txtd2.Text = "" ' 'Label4 ' Me.Label4.Location = New System.Drawing.Point(32, 112) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(40, 16) Me.Label4.TabIndex = 6 Me.Label4.Text = "n2 =" ' 'txtn2 ' Me.txtn2.Location = New System.Drawing.Point(80, 112) Me.txtn2.Name = "txtn2" Me.txtn2.Size = New System.Drawing.Size(320, 20) Me.txtn2.TabIndex = 7 Me.txtn2.Text = "" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(328, 152) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(64, 24) Me.Button1.TabIndex = 8 Me.Button1.Text = "موافق" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(240, 152) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(64, 24) Me.Button2.TabIndex = 9 Me.Button2.Text = "إنهاء" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(408, 182) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.txtn2) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.txtd2) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.txtn1) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.txtd1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "تحويل الأعداد" Me.ResumeLayout(False)
End Sub
#End Region Private Function ConvertNumberToDecimal(ByRef Number As String, ByRef id As Short) As String 'تحويل العدد من النظام المحدد إلى النظام العشري Dim Index As Short Dim Exponent As Short Dim DecimalNumber As Double Dim Digit As String Dim DecimalDigit As Short
Exponent = 0 DecimalNumber = 0
For Index = Len(Number) To 1 Step -1 Digit = Mid(Number, Index, 1)
Select Case Digit Case "0" To "9" DecimalDigit = Val(Digit) Case "A", "a" DecimalDigit = 10 Case "B", "b" DecimalDigit = 11 Case "C", "c" DecimalDigit = 12 Case "D", "d" DecimalDigit = 13 Case "E", "e" DecimalDigit = 14 Case "F", "f" DecimalDigit = 15 End Select
DecimalNumber = DecimalNumber + DecimalDigit * id ^ Exponent
Exponent = Exponent + 1 Next '--- ConvertNumberToDecimal = CStr(DecimalNumber) End Function
Private Function ConvertDecimalToNumber(ByRef Number As String, ByRef id As Short) As String 'تحويل العدد من النظام العشري إلى النظام المحدد Dim Number1 As Double Dim Number2 As Double Dim numberNumber As String Dim Digit As String
numberNumber = "" Number1 = Val(Number)
Do Number2 = Int(Number1 / id)
Select Case Number1 - id * Int(Number1 / id) Case 0 Digit = "0" Case 1 Digit = "1" Case 2 Digit = "2" Case 3 Digit = "3" Case 4 Digit = "4" Case 5 Digit = "5" Case 6 Digit = "6" Case 7 Digit = "7" Case 8 Digit = "8" Case 9 Digit = "9" Case 10 Digit = "A" Case 11 Digit = "B" Case 12 Digit = "C" Case 13 Digit = "D" Case 14 Digit = "E" Case 15 Digit = "F" End Select
numberNumber = Digit & numberNumber Number1 = Number2 Loop While Number2 <> 0
ConvertDecimalToNumber = numberNumber End Function
Private Function ConvertNumberToNumber(ByRef Number As String, ByRef id1 As Short, ByRef id2 As Short) As String 'تحويل العدد من نظام إلى نظام ConvertNumberToNumber = ConvertDecimalToNumber(ConvertNumberToDecimal(Number, id1), id2) End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim d1 As Short Dim d2 As Short Dim n1 As String Dim n2 As String
d1 = Val(txtd1.Text) n1 = txtn1.Text d2 = Val(txtd2.Text)
If d1 <> 2 And d1 <> 8 And d1 <> 10 And d1 <> 16 Then MsgBox("d1= 2 or 8 or 10 or 16", MsgBoxStyle.Critical, "رسالة خطأ") txtd1.Focus()
Exit Sub End If
If d2 <> 2 And d2 <> 8 And d2 <> 10 And d2 <> 16 Then MsgBox("d2= 2 or 8 or 10 or 16", MsgBoxStyle.Critical, "رسالة خطأ") txtd2.Focus()
Exit Sub End If
n2 = ConvertNumberToNumber(n1, d1, d2) txtn2.Text = n2 End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub End Class
|