Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
Public Class decimalebinario
Inherits System.Windows.Forms.Form
Dim a As New ArrayList
Dim r As New ArrayList
#Region " Codice generato da Progettazione Windows Form "
Public Sub New()
MyBase.New()
'Chiamata richiesta da Progettazione Windows Form.
InitializeComponent()
'Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent()
End Sub
'Form esegue l'override del metodo Dispose per pulire l'elenco dei componenti.
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
'Richiesto da Progettazione Windows Form
Private components As System.ComponentModel.IContainer
'NOTA: la procedura che segue è richiesta da Progettazione Windows Form.
'Può essere modificata in Progettazione Windows Form.
'Non modificarla nell'editor del codice.
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()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(decimalebinario))
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.BackColor = System.Drawing.Color.White
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.MaxLength = 1
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(24, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
Me.TextBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'TextBox2
'
Me.TextBox2.BackColor = System.Drawing.Color.White
Me.TextBox2.Location = New System.Drawing.Point(152, 32)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.ReadOnly = True
Me.TextBox2.Size = New System.Drawing.Size(64, 20)
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = ""
'
'TextBox3
'
Me.TextBox3.AutoSize = False
Me.TextBox3.BackColor = System.Drawing.Color.White
Me.TextBox3.Location = New System.Drawing.Point(40, 8)
Me.TextBox3.MaxLength = 1
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.ReadOnly = True
Me.TextBox3.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal
Me.TextBox3.Size = New System.Drawing.Size(320, 20)
Me.TextBox3.TabIndex = 3
Me.TextBox3.Text = ""
'
'decimalebinario
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(366, 60)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "decimalebinario"
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Da Binario a Decimale"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Select Case TextBox1.Text
Case "0"
GoTo casa
Case "1"
GoTo casa
Case Else
MsgBox("Inserire solo 0 oppure 1!", MsgBoxStyle.Critical, Me.Text)
a.Clear()
r.Clear()
TextBox2.Clear()
TextBox3.Clear()
End Select
Exit Sub
casa:
a.Add(TextBox1.Text)
TextBox3.Text = TextBox3.Text & TextBox1.Text
TextBox1.SelectAll()
Dim f As Integer
For f = 0 To a.Count - 1
r.Add(TextBox2.Text = a.Item(f) * (2 ^ f))
Next f
Dim t As Integer
For t = 0 To r.Count - 1
TextBox2.Text = r.Item(t) + r.Item(t + 1)
Next t
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(27) = True Then Me.Close()
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(27) = True Then Me.Close()
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(27) = True Then Me.Close()
End Sub
Private Sub Form10_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(27) = True Then Me.Close()
End Sub
End Class