home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2003 January / PCpro_2003_01.ISO / born / Beisp / EuroRechner.vb < prev    next >
Encoding:
Text File  |  2002-10-15  |  3.9 KB  |  145 lines

  1. '************************************************
  2. ' File:  EuroRechner.vb 
  3. ' Autor: G. Born www.borncity.de
  4. '
  5. ' Umrechnung DM/Euro mittels Formular, Textfeldern und
  6. ' zwei SchaltflΣchen. 
  7. ' Beim ▄bersetzen die Bibliotheken system.dll,
  8. ' dll und dll
  9. ' referenzieren! 
  10. '************************************************
  11. Option Strict
  12. Imports System.Drawing
  13. Imports System.Windows.Forms
  14. Imports Microsoft.VisualBasic
  15.  
  16. Class Test
  17.  Shared Eingabe As String         ' Eingabespeicher
  18.  
  19.  Shared Sub Main() 
  20.   Dim oForm As New Formular()     ' Formular anlegen
  21.   oForm.ShowDialog()        ' als modalen Dialog anzeigen
  22.   oForm.Dispose()
  23.  End Sub
  24.  
  25.  
  26.  Class Formular                  ' Formularklasse 
  27.   Inherits Form ' wir erben
  28.   Friend WithEvents button  As New Button()         
  29.   Friend WithEvents button2 As New Button()
  30.   Private label4 As New Label()
  31.   Private label3 As New Label()
  32.   Private textBox2 As New TextBox()
  33.   Private textBox As New TextBox()
  34.   Private label2 As New Label()
  35.   Private label As new Label()
  36.  
  37.  
  38.   Sub New()    ' New-Construktor zum Anlegen des Formulars
  39.    MyBase.New()                   ' Formularobjekt aus Klasse
  40.    With Me
  41.     .Name = "Form"
  42.     .MaximizeBox = false
  43.     .Text = "Euro-Rechner (by G. Born)"
  44.     .Size = New Size(382, 178)
  45.     .FormBorderStyle = FormBorderStyle.Fixed3D
  46.  ' button2
  47.  
  48.  
  49.    button2.Name = "button2"
  50.    button2.TabIndex = 7
  51.    button2.Text = "Schlie▀en"
  52.    button2.Size = New Size(104, 32)
  53.    button2.Location = New Point(160, 80)
  54.    .Controls.Add(button2)
  55.             
  56. ' button
  57.  
  58.    button.Name = "button"
  59.    button.TabIndex = 6
  60.    button.Text = "Calc"
  61.    button.Size = New Size(112, 32)
  62.    button.Location = New Point(32, 80)
  63.    .Controls.Add(button)
  64.             
  65. ' label4
  66.    label4 = New Label
  67.    label4.Name = "label4"
  68.    label4.Location = New Point(184, 40)
  69.    label4.Size = New Size(124, 16)
  70.    label4.TabIndex = 5
  71.    label4.Text = "0 DM"
  72.    .Controls.Add(label4)
  73.  
  74. ' label3
  75.    label3 = New Label
  76.    label3.Name = "label3"
  77.    label3.Location = New Point(184, 8)
  78.    label3.Size = New Size(124, 23)
  79.    label3.TabIndex = 4
  80.    label3.Text = "0 Euro"
  81.    .Controls.Add(label3)
  82.             
  83. ' textBox2
  84.    textBox2 = New TextBox
  85.    textBox2.Name = "textBox2"
  86.    textBox2.Text = "0"
  87.    textBox2.Size = New Size(96, 20)
  88.    textBox2.Location = New Point(64, 40)
  89.    textBox2.TabIndex = 3
  90.    .Controls.Add(textBox2)
  91.             
  92. ' textBox
  93.    textBox = New TextBox
  94.    textBox.Name = "textBox"
  95.    textBox.Text = "0"
  96.    textBox.Size = New Size(96, 20)
  97.    textBox.Location = New Point(64, 8)
  98.    textBox.TabIndex = 2
  99.    .Controls.Add(textBox)
  100.             
  101. ' label2
  102.    label2 = New Label
  103.    label2.Name = "label2"
  104.    label2.Location = New Point(16, 40)
  105.    label2.Size = New Size(48, 24)
  106.    label2.TabIndex = 1
  107.    label2.Text = "Euro"
  108.    .Controls.Add(label2)
  109.             
  110. ' label
  111.  
  112.    label = New Label
  113.    label.Name = "label"
  114.    label.Location = New Point(16, 8)
  115.    label.Size = New Size(48, 16)
  116.    label.TabIndex = 0
  117.    label.Text = "DM"
  118.    .Controls.Add(label)
  119.   End With
  120.  End Sub
  121.  
  122. ' Ereignisbehandlungsroutinen 
  123.   Private Sub Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
  124.    Me.Close                         ' Formular schlie▀en 
  125.   End Sub
  126.  
  127.   Private Sub Calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.Click
  128.    Const EuroFaktor As Double = 1.95583
  129.    Dim tmp As Double
  130.     If IsNumeric (textbox.Text) Then
  131.      tmp = CDbl(textbox.Text) / EuroFaktor     ' DM in Euro umrechnen
  132.      label3.Text =  tmp.ToString("#,##0.00")  & " Euro"
  133.     Else
  134.      label3.Text =  "***"                             ' Fehler
  135.     End If
  136.  
  137.     If IsNumeric (textbox2.Text) Then
  138.      tmp = CDbl(textbox2.Text) * EuroFaktor     ' Euro in DM umrechnen
  139.      label4.Text =  tmp.ToString("#,##0.00")  & " DM" 
  140.     Else
  141.      label4.Text =  "***"                           ' Fehler
  142.     End If
  143.   End Sub
  144.  End Class
  145. End Class