Array?

djfred

New member
Joined
Mar 28, 2008
Messages
2
Programming Experience
Beginner
Hey guys whats up im new here my name is fred
and i have been into programming for sometime now. but i do consider myself as a beginner.
I have a question about this small app i want to make

This is what i want the app to do
vb.jpg


be able to enter name then hit ADD Name
it will go into the memory/list after i have added X amount of names (could be from 3, 4, 5, 10, names) then hit Generate and it will display one name.

I want to define the names in an Array when i start with the app
i want to populate the array as i go along.


I hope this makes sense.

-fred
 
Something like this?
VB.NET:
Public Class frmGenerateName
    Private names As String() 
    Private i As Integer = 0
    Private selector As New Random

    Private Sub btnAddName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddName.Click
        ReDim Preserve names(i)
        names(i) = Me.txtNewName.Text
        i += 1
    End Sub

    Private Sub btnGenerateName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerateName.Click
        Dim nameList As New List(Of String)(Me.names)
        Me.txtGeneratedName.Text = Me.SelectName(nameList)
    End Sub

    Private Function SelectName(ByVal names As List(Of String)) As String
        Dim index As Integer = Me.selector.Next(0, names.Count)
        Dim name As String = names(index)
        ' removes each name 
        names.RemoveAt(index)
        Return name
    End Function
End Class
 
Back
Top