Friday 10 January 2014

Visual Basic

Creating ur first visual basic program
Notepad + command line compiler

Array
Create an array

Dim number(0 to 2) as integer
    number(0) = 1
    number(1) = 2


Function
Create function/method

1.Function that return a method but not take parameter
function sandirahasia() as String
    return "Aloha!"
end function

2. Function that return an output and take parameter

function sandirahasia2(ByVal name as String) as String
    return "Aloha" & name
end function


Call our function
Style 1:
sub main()
    dim my_string = sandirahasia() as String
    console.writeline(my_string)
end sub

Style2:
sub main()
    console.writeline(sandirahasia())
end sub

Style1 and style 2 the result is the same

While

Contoh 1: While sederhana

Module Module1

    Sub Main()
        Dim perutgue As Integer = 0
        While perutgue < 10
            perutgue = perutgue + 1
        End While
        Console.WriteLine("Gue kenyang!")
        Console.ReadLine()
    End Sub
End Module

If

Module Module1

    Sub Main()
        Dim lampu = Console.ReadLine()
start:
        If lampu = "merah" Then
            Console.WriteLine("Berhenti")
        ElseIf lampu = "kuning" Then
            Console.WriteLine("Hati-hati")
        ElseIf lampu = "hijau" Then
            Console.WriteLine("Maju")
        End If
        Console.ReadLine()
        If jawab == "y" Then GoTo start
        else console.readline()
        End if

    End Sub

End Module

No comments:

Post a Comment