Tutorial's von A - Z (www.Knuddels.de.ch.at.MFC)  
 
  [TuT] Taschenrechner 24.06.2025 10:12 (UTC)
   
 
[TuT] Taschenrechner
Hallo.

Wie ich schon angekündigt habe schreibe ich hier noch ein Tutorial für Vb.Net.

Ws ihr braucht:
  • Visual Basic 2005 bzw. 08


Als erstes legt ihr an:
  • 18 Buttons
  • 1 Textbox


Buttons:
  • 1-0
  • Rückgängig
  • C(lear)
  • Komma
  • + - / *
  • =


Screen:


Als erstes deklarieren wir 2 Strings (unter Public Class Form):
Code:
Private zahl As Integer
Private art As String
Doppelklick auf Form:
Code:
TextBox1.ReadOnly = True
Buttons 1-9 & 0:
Code:
TextBox1.Text = TextBox1.Text & 1
So macht ihr das nun bis 0.
Das heißt:
1,2,3,4,5,6,7,8,9,0

Komma
Code:
TextBox1.Text = TextBox1.Text & ","
Rückgängig-Taste:
Code:
TextBox1.Undo()
C-Taste
Code:
TextBox1.Clear()
art = Nothing
zahl = Nothing
*,/,-,+ Taste
Code:
zahl = TextBox1.Text
art = "+"
TextBox1.Clear()
+ mit *,/ oder - ersetzen.

= Button
Code:

Select Case art
Case "+"
TextBox1.Text = zahl + TextBox1.Text
Case "-"
TextBox1.Text = zahl - TextBox1.Text
Case "*"
TextBox1.Text = zahl * TextBox1.Text
Case "*"
TextBox1.Text = zahl / TextBox1.Text
End Select
Dann noch das hinzufügen:
Code:
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case Asc(e.KeyChar)
Case 48 To 57, 8, 32

Case Else
e.Handled = True
End Select
'nur Zahlen in Textbox erlauben
End Sub
Ein bisschen müsst ihr selber schreiben

Bei Fragen einfach posten

(c) KoRn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Heute waren schon 1 Besucher (19 Hits) hier!
Diese Webseite wurde kostenlos mit Homepage-Baukasten.de erstellt. Willst du auch eine eigene Webseite?
Gratis anmelden