Tutorial Vb.Net : Penggunaan Functions dalam Vb.Net

Tutorial Vb.Net : Penggunaan Functions,Defining Functions,Recursive Function,Param Arrays,Passing Arrays as Function Arguments dalam Vb.Net khusus pemula

Tutorial Vb.Net - Menggunakan Prosedure Functions dalam Vb.Net yang akan kita bahasa pada tutorial vb.net ini, seperti pada tutorial sebelumnya sector code sudah membahas tentang Functions terbilang pada aplikasi inventory vb.net dan c#, bisa kamu baca - baca di sini :
  1. Tutorial CSharp : Membuat Fungsi Terbilang C#
Tutorial penggunaan Functions dalam vb.net akan dijelaskan sejelas-jelasnya, simak terus ya.
Tutorial Vb.Net : Penggunaan Functions dalam Vb.Net

Mendefinisikan Sebuah Functions dalam Vb.Net

Berikut syntax yang digunakan untuk mendefinisikan sebuah functions di vb.net
[Modifiers] Function FunctionName [(ParameterList)] As ReturnType
    [Statements]
End Function
Contoh penggunaan dalam aplikasi Console
    Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
        Dim result As Integer
        If (num1 > num2) Then
            result = num1
        Else
            result = num2
        End If
        FindMax = result
    End Function
Referensi : http://www.tutorialspoint.com/vb.net/vb.net_functions.htm
Dalam contoh ini kita akan mengeksikusi sebuah functions yang dipanggil dari sub main, lihat contoh berikut :
Module Module1

    Sub Main()
        Dim x As Integer = 500
        Dim y As Integer = 600
        Dim z As Integer = 601
        Dim nilai As Integer
        nilai = Cari(x, y, z)
        Console.WriteLine("Nilai yang paling besar adalah : {0}", nilai)
        Console.ReadLine()
    End Sub
    Function Cari(ByVal int1 As Integer, ByVal int2 As Integer, ByVal int3 As Integer) As Integer
        Dim hasil As Integer
        If (int1 > int2 And int1 > int3) Then
            hasil = int1
        ElseIf (int3 > int1 And int3 > int2) Then
            hasil = int3
        Else
            hasil = int2
        End If
        Cari = hasil
    End Function

End Module
Maka aplikasi console diatas akan menghasilkan nilai paling tinggi dari ketiga variable integer diatas :
"Nilai yang paling besar adalah : 601"

Recursive Function

Berikut contoh penggunaan Recursive Function dalam aplikasi console :
Module Module1

    Sub Main()
        'calling the factorial method
        Console.WriteLine("Factorial of 6 is : {0}", factorial(6))
        Console.WriteLine("Factorial of 7 is : {0}", factorial(7))
        Console.WriteLine("Factorial of 8 is : {0}", factorial(8))
        Console.ReadLine()
    End Sub
    Function factorial(ByVal num As Integer) As Integer
        ' local variable declaration 
        Dim result As Integer
        If (num = 1) Then
            Return 1
        Else
            result = factorial(num - 1) * num
            Return result
        End If
    End Function

End Module
Referensi : http://www.tutorialspoint.com/vb.net/vb.net_functions.htm
Aplikasi diatas akan menghasilkan pesan sebagai berikut :
Factorial of 6 is : 720
Factorial of 7 is : 5040
Factorial of 8 is : 40320

Membuat Arrays sebagai Functions

Kamu bisa saja mendeklarasikan array sebagai functions, lihat penulisan codenya :
Module Module1

    Sub Main()
        Dim Nilai As Integer() = {1000, 2, 3, 17, 50}
        Dim _Average As Double
        _Average = getAverage(Nilai, 5)
        Console.WriteLine("Nilai average : {0} ", _Average)
        Console.ReadLine()
    End Sub
    Function getAverage(ByVal arr As Integer(), ByVal size As Integer) As Double
        Dim x As Integer
        Dim _Average As Double
        Dim sum As Integer = 0
        For x = 0 To size - 1
            sum += arr(x)
        Next x
        _Average = sum / size
        Return _Average
    End Function

End Module
Jalankan aplikasi dan kamu akan mendapatkan hasil : "Nilai average : 214,4"

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: Tutorial Vb.Net : Penggunaan Functions dalam Vb.Net
Tutorial Vb.Net : Penggunaan Functions dalam Vb.Net
Tutorial Vb.Net : Penggunaan Functions,Defining Functions,Recursive Function,Param Arrays,Passing Arrays as Function Arguments dalam Vb.Net khusus pemula
http://3.bp.blogspot.com/-GVyIR3Q9zEM/Vjw5ZR4OfxI/AAAAAAAABEk/7BDfWU7g-tM/s320/fungtions-vbnet.jpg
http://3.bp.blogspot.com/-GVyIR3Q9zEM/Vjw5ZR4OfxI/AAAAAAAABEk/7BDfWU7g-tM/s72-c/fungtions-vbnet.jpg
KODE AJAIB
https://www.kodeajaib.com/2015/11/tutorial-vbnet-penggunaan-functions.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2015/11/tutorial-vbnet-penggunaan-functions.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy