Konu 13: Arkadaş Sayılar

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim a As Integer = Val(TextBox1.Text)
        Dim b As Integer = Val(TextBox2.Text)

        For sayi As Integer = a To b

            Dim sonuc1 As Integer = 0
            For i As Integer = 1 To sayi - 1
                If sayi Mod i = 0 Then
                    sonuc1 += i
                End If
            Next

            Dim sonuc2 As Integer = 0
            For j As Integer = 1 To sonuc1 - 1
                If sonuc1 Mod j = 0 Then
                    sonuc2 += j
                End If
            Next

            If sayi = sonuc2 Then
                If sayi <> sonuc1 Then
                    MsgBox(sayi & " ve " & sonuc1 & " arkadaştır")
                End If
            End If

        Next
        MsgBox("bitti")
    End Sub
End Class

Konu 12: Döngü Uygulamaları (Faktöriyel, Tek Sayı Toplamları)

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sayi As Integer = Val(TextBox1.Text)
        Dim faktoriyel As Integer = 1

        For i As Integer = 1 To sayi
            faktoriyel *= i
        Next

        MsgBox(sayi & "!= " & faktoriyel)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sayi As Integer = Val(TextBox2.Text)
        Dim toplam As Integer = 0
        For i As Integer = 1 To sayi Step 2
            toplam += i
        Next

        Dim n As Integer = (sayi + 1) / 2

        If toplam = n ^ 2 Then
            MsgBox(toplam)
        End If

    End Sub
End Class

Konu 11: Döngü Uygulamaları (Asal Sayı, İki Sayı Arasındaki Asallar, Bölenler, Obeb)

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sayi As Integer = Val(TextBox1.Text)
        Dim asalmi As Boolean = True

        For i As Integer = 2 To sayi - 1
            If sayi Mod i = 0 Then
                'sayının asal olmadigini gosterir
                MsgBox("sayi asal degil " & i & "'ye bölünüyor")
                asalmi = False
                Exi t For
            End If
        Next
        If asalmi = True Then
            MsgBox("sayi asaldir")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sayi1 As Integer = Val(TextBox2.Text)
        Dim sayi2 As Integer = Val(TextBox3.Text)

        For sayi As Integer = sayi1 To sayi2

            Dim asalmi As Boolean = True

            For i As Integer = 2 To sayi - 1
                If sayi Mod i = 0 Then
                    'sayının asal olmadigini gosterir
                    MsgBox(sayi & " sayisi asal degil " & i & "'ye bölünüyor")
                    asalmi = False
                    Exi t For
                End If
            Next
            If asalmi = True Then
                MsgBox(sayi & " sayisi asaldir")
            End If
        Next
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ListBox1.Items.Clear()
        Dim sayi As Integer = Val(TextBox4.Text)
        For i As Integer = 1 To sayi
            If sayi Mod i = 0 Then
                ListBox1.Items.Add(i)
            End If
        Next

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim sayi As Integer = Val(TextBox5.Text)
        For i As Integer = sayi To 1 Step -1
            If sayi Mod i = 0 Then
                '1. sayının boleni bulundu
                If Val(TextBox6.Text) Mod i = 0 Then
                    '1. sayıyı bolen sayi 
                    '2. sayıyı da bolmustur
                    MsgBox("sayıların obebi =" & i)
                    Exi t For
                End If

            End If
        Next
    End Sub
End Class

Konu 10: Donguler2(For)

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s1, s2, tek, cift, topla As Integer
        If Val(TextBox1.Text) > Val(TextBox2.Text) Then
            s1 = Val(TextBox2.Text)
            s2 = Val(TextBox1.Text)
        Else
            s1 = Val(TextBox1.Text)
            s2 = Val(TextBox2.Text)
        End If
        For i As Integer = s1 To s2
            If i Mod 2 = 0 Then
                cift = cift + i
            Else
                tek = tek + i
            End If
            topla = topla + i

        Next
        Label1.Text = tek
        Label2.Text = cift
        Label3.Text = topla
    End Sub
End Class

Konu 9: Döngüler(For)

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sayi1, sayi2 As Integer
        If Val(TextBox1.Text) > Val(TextBox2.Text) Then
            sayi2 = Val(TextBox1.Text)
            sayi1 = Val(TextBox2.Text)
        Else
            sayi1 = Val(TextBox1.Text)
            sayi2 = Val(TextBox2.Text)
        End If
        Dim toplam As Integer = 0
        For i As Integer = sayi1 To sayi2
            toplam = toplam + i
        Next
        Label1.Text = toplam
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label2.Text = ""
        Label3.Text = ""
        Dim sayi1, sayi2 As Integer
        If Val(TextBox1.Text) > Val(TextBox2.Text) Then
            sayi2 = Val(TextBox1.Text)
            sayi1 = Val(TextBox2.Text)
        Else
            sayi1 = Val(TextBox1.Text)
            sayi2 = Val(TextBox2.Text)
        End If
        For i As Integer = sayi2 To sayi1 Step -1
            Label2.Text &= i & "  "
        Next
        For i As Integer = sayi1 To sayi2
            Label3.Text &= i & "  "
        Next
    End Sub
End Class

Konu 8: Koşullar(Select,Choose,Switch)

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim degisken As Integer
        degisken = Val(TextBox1.Text)

        Select Case degisken
            Case 1
                MsgBox("1 girdiniz")
            Case 2
                MsgBox("2 girdiniz")
            Case 3 To 10
                MsgBox("3 ile 10 arasında bir deger girdiniz")
            Case Is > 10
                MsgBox("10dan buyuk bir deger girdiniz")
            Case Else
                MsgBox("1den küçük bir deger girdiniz")
        End Select

        'Select Case degisken
        '    Case "ahmet"
        '        MsgBox("ahmet bey hosgeldiniz")
        '    Case "mehmet"
        '        MsgBox("mehmet bey hosgeldiniz")
        '    Case "q"
        '        MsgBox("sifreniz 123")
        '    Case "w"
        '        MsgBox("kullanici adiniz admin")
        '    Case Else
        '        MsgBox("hatalı bilgi girişi")
        'End Select

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Dim hangisi As Integer
        'hangisi = Weekday(TextBox2.Text)
        'Dim gun As String
        'gun = Choose(hangisi, "pazar", "pazartesi", "salı", "cars.", "pers.", "cuma", "ctesi")
        'MsgBox(gun)
        Dim hangisi As Integer
        hangisi = Val(TextBox2.Text)
        hangisi = (hangisi - 1) Mod 7 + 1
        Dim gun As String
        gun = Choose(hangisi, "pazartesi", "salı", "cars.", "pers.", "cuma", "ctesi", "pazar")
        MsgBox(gun)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim notunuz As Integer
        notunuz = Val(TextBox3.Text)
        Dim sonuc As String
        sonuc = Microsoft.VisualBasic.Interaction.Switch(notunuz >= 0 And notunuz < 55, "FF", notunuz > 54 And notunuz < 60, "DD")
        MsgBox(sonuc)
    End Sub
End Class

Konu 7: Kosullar(if) ortalama hesabı

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim vize, final, ortalama As Byte
        vize = Val(TextBox1.Text)
        final = Val(TextBox2.Text)
        ortalama = (vize * 0.4) + (final * 0.6)
        Label1.Text = ortalama

        If ortalama < 55 Then
            Label2.Text = "ff"
        Else
            'ortalama 54'ten buyuk
            If ortalama < 60 Then
                Label2.Text = "dd"
            Else
                'ortalama 59'dan buyuk
                If ortalama < 65 Then
                    Label2.Text = "dc"
                Else
                    'ortlama 64'ten buyuk
                    If ortalama < 75 Then
                        Label2.Text = "cc"
                    Else
                        'ortalama 74ten buyuk
                        If ortalama < 80 Then
                            Label2.Text = "cb"
                        Else
                            'ortalama 79dan buyuk
                            If ortalama < 85 Then
                                Label2.Text = "bb"
                            Else
                                'ortalama 84ten buyuk
                                If ortalama < 90 Then
                                    Label2.Text = "ba"
                                Else
                                    'ortalama 89dan buyuk
                                    If ortalama <= 100 Then
                                        Label2.Text = "aa"
                                    Else
                                        Label2.Text = "hatalı not girisi"
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim vize, final, ortalama As Byte
        vize = Val(TextBox1.Text)
        final = Val(TextBox2.Text)
        ortalama = (vize * 0.4) + (final * 0.6)
        Label1.Text = ortalama

        If ortalama < 55 Then
            Label2.Text = "ff"
        ElseIf ortalama < 60 Then
            Label2.Text = "dd"
        ElseIf ortalama < 65 Then
            Label2.Text = "dc"
        ElseIf ortalama < 75 Then
            Label2.Text = "cc"
        ElseIf ortalama < 80 Then
            Label2.Text = "cb"
        ElseIf ortalama < 85 Then
            Label2.Text = "bb"
        ElseIf ortalama < 90 Then
            Label2.Text = "ba"
        ElseIf ortalama < 101 Then
            Label2.Text = "aa"
        Else
            Label2.Text = "hatalı not"
        End If
    End Sub
End Class

Konu 6: Koşullar(İf)

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ka As String = TextBox1.Text
        Dim sifre As String = TextBox2.Text

        If ka = "ahmet" And sifre = "123" Then
            MsgBox("hoşgeldiniz")
            'işlemleri yap
        Else
            If ka <> "ahmet" And sifre <> "123" Then
                MsgBox("kullanıcı adı ve sifre hatalı")

            Else
                If ka <> "ahmet" Then
                    MsgBox("kullanıcı adı hatalı")
                Else
                    MsgBox("sifre hatalı")
                End If
                MsgBox("düzelt")
            End If

        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim vize, final As Integer
        vize = Val(TextBox3.Text)
        final = Val(TextBox4.Text)
        Dim ortalama As Integer
        ortalama = vize * 0.4 + final * 0.6
        If ortalama >= 55 Then
            If ortalama >= 60 Then
                If ortalama >= 65 Then
                    If ortalama >= 75 Then
                        If ortalama >= 80 Then
                            If ortalama >= 85 Then
                                If ortalama >= 90 Then
                                    Label3.Text = "aa"
                                Else
                                    Label3.Text = "ba"
                                End If
                            Else
                                Label3.Text = "bb"
                            End If
                        Else
                            Label3.Text = "cb"
                        End If
                    Else
                        Label3.Text = "cc"
                    End If
                Else
                    Label3.Text = "dc"
                End If
            Else
                Label3.Text = "dd"
            End If
        Else
            Label3.Text = ("ff")
        End If
    End Sub
End Class

Konu 5: Operatörler

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sayi1, sayi2 As Double
        sayi1 = Val(TextBox1.Text)
        sayi2 = Val(TextBox2.Text)
        'Label1.Text = sayi1 + sayi2
        'Label1.Text = sayi1 - sayi2
        'Label1.Text = sayi1 * sayi2
        'Label1.Text = sayi1 / sayi2
        'Label1.Text = sayi1 \ sayi2
        'Label1.Text = sayi1 ^ sayi2
        'Label1.Text = sayi1 Mod sayi2
        Label1.Text = TextBox1.Text & TextBox2.Text
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim a As Double
        a = 5
        a += 2
        MsgBox(a) '7
        a -= 5
        MsgBox(a) '2
        a *= 3
        MsgBox(a) '6
        a /= 2
        MsgBox(a) '3
        a ^= 2
        MsgBox(a) '9
        a \= 2
        MsgBox(a) '4
        Dim b As String = "ahmet " & " can"
        MsgBox(b) ' ahmet can

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim a, b As Integer
        a = 5
        b = 5
        If a > b Then MsgBox("a, b'den büyük")
        If a < b Then MsgBox("a, b'den küçük")
        If a >= b Then MsgBox("a, b'ye büyük eşit")
        If a <= b Then MsgBox("a, b'ye küçük eşit")
        If a <> b Then MsgBox("a, b'den farklı")
        If a = b Then MsgBox("a, b'ye eşit")

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim yazi As String
        yazi = TextBox3.Text
        If yazi Like "?hm*" Then
            'MsgBox("benzer")
        End If
        If yazi Like "az2#" Then
            'MsgBox("benzer")
        End If
        If yazi Like "[a-f]hmet" Then
            'MsgBox("benzer")
        End If
        If yazi Like "[!g-z]hmet" Then
            MsgBox("benzer")
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        MsgBox(7 And 9)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim a, b As Integer
        a = TextBox4.Text
        b = TextBox5.Text
        a = 1
        MsgBox(Not (a))
        If Not (a) Then
            Label2.Text = "1"
        Else
            Label2.Text = ("0")
        End If
    End Sub
End Class

Konu 4: Veri Tipleri Ve Dönüşümleri

Örnek Uygulama

Ekran Görüntüsü

VBNETVeriTipleri

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sayi1, sayi2 As Integer
        sayi1 = CInt(TextBox1.Text)
        sayi2 = CInt(TextBox2.Text)
        Label1.Text = sayi1 + sayi2
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sayi1, sayi2 As Integer
        sayi1 = Val(TextBox1.Text)
        sayi2 = Val(TextBox2.Text)
        Label1.Text = sayi1 + sayi2
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim sayi As Double
        'Dim sayi As Integer
        'sayi = Val(TextBox3.Text)
        'sayi = CInt(TextBox3.Text)
        sayi = CDbl(TextBox3.Text)
        'sayi = 3.6
        Label2.Text = sayi

        'cbyte 
        'cchar 'karakter
        'cdate
        'cdbl 'double
        'cdec 'decimal
        'cint 
        'clng 'long integer
        'cobj 'object
        'cshort 'short integer
        'csng 'single
        'cstr 'string
        'cbool 'boolean 
        'Dim a As Boolean = CType(sayi, Boolean)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim tarih As Date
        'tarih = Now
        'tarih = DateValue(Now)
        tarih = TimeValue(Now)
        MsgBox(tarih)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim yazi As String
        Dim tarih As Date

        yazi = "22,10,2009"
        tarih = DateValue(yazi)
        MsgBox(tarih)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim sayi As Double = -3.2
        'MsgBox(Fix(sayi)) 'girilen ifadenin tam kısmını alır
        MsgBox(Int(sayi)) 'pozitif sayıların sadece tam kısmını alır
        'negatif sayıları ise once yuvarlar sonra tam olarak dondurur

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        'hex() 'hexadecimal (16)lık sisteme cevirir
        MsgBox(Hex(255))
        'oct() '8lik sisteme cevirir
    End Sub
End Class