Örneğimizde bir adet textbox içerisinde girilen 2 adet sayıdan büyüğünden küçüğünü çıkartarak sonucu yine aynı textbox içerisine yazacağız. 1. sayı girilip enter'a basılacak text kutusu içeriği temizlenip 2. sayı girilecek enter'a basılacak ve text kutusu içeriği yine temizlenerek sonuç yazılacak.

Kodumuz aşağıdaki gibi olacak:     

 

Class Form1  

Public

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Static sayi, s1, s2 As Integer 

 Dim sonuc As Integer 

If e.KeyChar = Chr(13)  Then

 sayi = sayi + 1

If sayi = 1  Then

 s1 = Val(TextBox1.Text)

 TextBox1.Text =""

 ElseIf sayi = 2 Then

s2 = Val(TextBox1.Text) 

TextBox1.Text =""

 If Val(s1) > Val(s2) Then

 sonuc = s1 - s2

Else 

sonuc = s2 - s1

End If

 TextBox1.Text = sonuc

sayi = 0

s1 = 0

s2 = 0

End If 

End If 

End If 

End Sub

End Class

Etiketler : VB.Net
Kategoriler : VB.Net
Yorumlar : 0 Yorum Yorum Yaz

Yorumlar

Yorum Eklenmemiş...

Yorum Yaz

Adınız: *
E-Mail Adresiniz: *
Web Sitesi:
Yorum: *
Güvenlik Kodu: *
 
Arama
  Ara
Takvim
<September 2010>
SMTWTFS
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Tag Bulutu