代表者の戯言

Let's use list(Of String)




Visual Basic has a concept called "columns," which allows related data to be grouped together into a single list by linking them.

For example, when dealing with customer data, it can sometimes be more efficient to bundle information such as gender, height, weight, blood type, hobbies, and place of origin into one cohesive list, rather than storing each item separately. Below is a sample that utilizes such a list.

'At first,Definition

Dim List1 As New List(Of String)

'Add list with data

List1.Add("A")

List1.Add("B")

List1.Add("C")


'What is the box in the list?

MessageBox.Show(List1(0))


'Insert the data into the box,intentionally

List1.Insert(1, "BB")

‘Using messagebox.show, let's check what is inside.

For i As Integer = 0 To List1.Count - 1

MessageBox.Show(List1(i))

Next


'This is the answer.

'A

'BB

'B

'C


'I want to check it is inside the list.

If List1.Contains("BB") = True Then

MessageBox.Show("BB included")

End If


'How much data in the list?

Dim listnumber As Integer

listnumber = List1.Count

MessageBox.Show("data number:" & listnumber)


data1
data2

*************************************************************************:

According to ChatGPT, it seems that using a List is better than using an Array. The reason is that it's easier to change the size. Arrays have a fixed size and once created, you can't freely change the number of elements later. (Using ReDim causes copying, which is inefficient.) On the other hand, List(Of T) has a dynamic size, allowing you to easily add or remove elements using .Add() and .Remove().