How to Display Data Randomly from a List Array with Visual Basic.NET

This article discusses a tutorial for displaying character data that is taken from one of all lists of data listed in an Array randomly (randomly) using the Visual Basic.NET Programming Language (Vb.NET). You can do this tutorial using Visual Studio tools with any version as long as it supports Visual Basic.NET Programming Language (Vb.NET)

There may be several applications or programs made by feature systems or services that can display random data taken from Arrays such as making lucky applications based on Zodiac predictions, drawing numbers that will get something or rewards, and so on.

CREATE APPLICATION FORM OR DISPLAY

From the appearance of the form above, you need 1 unit label, 1 unit button, and 1 unit textbox which each has its own function in the ToolBox, including a Button to display random fruit data taken from one of the lists in the Array. For the appearance of the application, you can create your own according to your needs.

The author provides a command code or source code to display data taken from one of the lists in the Array randomly (Random). Here use the TextBox component to display the data and you can use components or toolbox that support it as well such as labels, buttons, and so on.

SOURCE CODE

In this section, there are several command codes that are used to display character data randomly taken from one of the entire list of data contained in the Array.

'Membuat beberapa list data ke dalam array.
Dim buah() As String = {"Apel", "Belimbing", "Ceri", "Delima", "Duku", "Pisang", "Tomat", "Cabe", "Mangga", "Rambutan"}
'Menghitung total seluruh data yang ada di dalam satu array.
Dim totalArray As Integer = buah.Length
Dim indexBuah As Integer
Dim acak As New Random

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Menampung data index Array yang akan ditampilkan secara acak.
indexBuah = acak.Next(1, totalArray)
'Menampilkan data yang telah ditampung oleh variabel indexBuah ke TextBox.
TextBox1.Text = buah(indexBuah)
End Sub

THE FINAL RESULT

In this section, we will display the results of displaying character data that is taken from one of all the data lists listed in the Array randomly (randomly) using the Visual Basic.NET Programming Language (Vb.NET).

A. Initial View.

B. Display Text Data randomly after clicked.

C. Display Text Data randomly after clicked once again.

CLOSING

You can create a feature, service, or validation to display random character or text data taken from one of the lists in the Array during the Button click event or other components that support Click or OnClick events using a programming language. Visual Basic.NET (vb.NET) in support for the creation of Desktop-based applications.

Leave a comment

Your email address will not be published.