Selasa, 20 September 2011

Ulangan VB

hei teman teman hari ini aku ulangan VB ..
soal nya beh beda beda ,, ada bubble with flag , ada selec sort , ada sheel sort ..
beh ... >,<
untung aja aku bisa ngerjain .. mungkin kebetulan ya soalnya dulu kelas 1 lek ulangan e pak e gak pernah bisa ..
ehehehehe :D

eh aku mau bagi ilmu nih ..
aku kasik coding sama outputnya ya :)

ini tampilan runningnya 


ini coding nya

Public Class Form1
    Dim T As String
    Dim AR() As Integer, N As Integer

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim R As Integer

        If e.KeyChar = Chr(13) Then
            N = Val(TextBox1.Text)
            ReDim AR(N + 1)
            T = ""
            For I As Byte = 1 To N
                R = Int(Rnd() * 899) + 100
                AR(I) = R
                T += Trim(Str(R)) & "  "
            Next
            TextBox2.Text = T
        End If
 End Sub

    Sub Selection()
        Dim X, Y, K, M As Integer
        For X = 1 To N - 1
            M = X
            For Y = X + 1 To N
                If AR(M) > AR(Y) Then M = Y
            Next Y
            If M <> X Then
                K = AR(M)
                AR(M) = AR(X)
                AR(X) = K
            End If
        Next X
    End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call Selection()
        T = ""
        For X = 1 To N
            T += Trim(Str(AR(X))) & "  "
        Next X
        TextBox2.Text = T
End Sub

End Class


ini hasil nya :)

Tidak ada komentar:

Posting Komentar