I'm very new to VB this is my first attempt at a project.

basically i want a simple program that will display a famous singers surname in a text box, then ask the user to input the singers first name in another box. The system must then check the answer in relation to the values stored inside a 2D array. it should then give the user 1 point for a correct answer.


Does anyone have any ideas where i's start or any sample programs that can point me in the right direction.


I've uploaded my project so far its not very good and doesnt work, but you can get the idea of what i am trying to achieve.

http://www.megaupload.com/?d=45CDXI3M


Thanks

Recommended Answers

All 6 Replies

i'm having real trouble with this has anyone got any suggestions?

Thanks

Here's a clue, put some of you're own code around it. Post it and we help you get it right. But you have to code first, even if it doesn't work.

Dim famouseNames(,) As String = {{John,Wayne},{Delia,Smith},{Florence,Nightingale}}

Ooops excuse me you did posta link to code I forgot.

ok heres what i got from your clue:

dim famousnames(,) as string = {{John,Wayne},{Delia,Smith}}

r=String.compare(Textbox,famousnames(0,1))

if r = 0 then score = 1

messagebox.show(correct)

else score = 0


but even when i put this into a vb.net project it will not work, can someone put it in a project and save the project so that i can download it and look thanks.

Hi your project was in a bit of a mess, I had to move Application.Designer.vb, AssemblyInfo.vb, Resources.Designer.vb, Resources.resx, Settings.Designer.vb into the MyProject folder before it would run in debug.

Ok *never* go straight into code. First design :

Create a 2d array of famouse Christain and Surnames.

Randomly select a surname (remember the index for later)

display randomly selected surname to user, ask user to supply christian name

read users response

compare response to expected answer (using the saved index)

award points if any

select another name
----------------------------------------------------------------------------

Ok so we got the 2d array, you need to randonly select a surname from it, use the Random class and use the Form1_Load event to set things up, and then implement the buttons click event to have another go:

Public Class Form1

    'Our array of names surnames are in dimension 0 and christian names in dimension 1
    Private strSurnames(,) As String = {{"Dillon", "Bob"}, {"Lennon", "John"}, {"Jagger", "Mick"}}

    'An instance of the .NET Frameworks' Random class, we'll use this to randomly
    'select a name from the 2d array by index
    Private rnd As New Random()

    'Keep tabs on the index we randomly chose so we can fetch again later
    'and see if it's the same as the users guess
    Private lastIndex As Integer

    'Kicks things of this event is fired when the form is first loaded
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Calls the SetSurname subroutine that selects a surname and displays it
        SetSurname()

    End Sub


    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click, Button2.Click
        'We are here because the user clicked the button, this is the event handler for 
        'the click event of Button2 I had to wire this up in the buttons property sheet
        'you obviously fluffed in the designer and double clicked a label or something

        'Anyway compare the input to the answer if they match
        If (strSurnames(lastIndex, 1) = TextBox2.Text) Then
            'Award points
            If TextBox3.Text = "" Then
                TextBox3.Text = 1
            Else
                TextBox3.Text = CInt(TextBox3.Text) + 1
            End If
        End If

        'Start again
        SetSurname()

    End Sub

    'Randomly selects a surname and displays it, clears out any previous guesses.
    Private Sub SetSurname()
        'Generate a random integer >= to 0 and < 3 therefore could 0 or 1 or 2
        lastIndex = rnd.Next(0, 3)

        'Display the surname
        TextBox1.Text = strSurnames(lastIndex, 0)

        'Clear out any previous guesses
        TextBox2.Text = ""
    End Sub
End Class

thanks m8, i can move on from here, you've been a big help!

No problem glad to help. If you like you can click my rep ta.

commented: excellent member +1
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.