hey guys! i have a problem, for my GCSE i have been given the task of making a prixe draw program, which allows the user to add 10 names then select a name at random. i have come to a problem when i have tried using a for loops to create 10 inputbox's to add to the array, for example. i click on the add names button it should start running a loop where it creates an input box then when the user clicks 'ok' on that inputbox it send the names from it into the array(0) then restarts with another loop but then sending the name into array(1). please help if you can, heres my code to help you along:

public Class Form1
    Dim names(9) As String
    Dim rnd As New Random
    Dim winner As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button2.Hide()
        Button3.Hide()
        Label1.Hide()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button2.Show()
        Button3.Show()
        Button1.Hide()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        winner = names(rnd.Next(0, 9))
        Label1.Text = ("Well Done" & " " & winner)
        Label1.Show()
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
        Button1.Show()
        Button2.Hide()
        Button3.Hide()
        Label1.Hide()
    End Sub
End Class

so i need button2_click to start the loop.

Use InputBox to enter the names as in

Private Sub btnAddNames_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNames.Click

    For i As Integer = 0 to 9
        names(i) = InputBox("Enter Name")
    Next

End Sub

Of course, you'd want to pretty it up a little by checking for blank names, etc.

thanks, that works fine! i probebly sound like a noob but ive only just started leraning it! thanks anyway!

We all had to start at the beginning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.