944,082 Members | Top Members by Rank

Ad:
Apr 12th, 2007
0

Simple 2d array help

Expand Post »
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.

Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
jameswoodhouse is offline Offline
30 posts
since Nov 2006
Apr 12th, 2007
0

Re: Simple 2d array help

The first thing is to decide where to store your array data, in code, an ini file or in a database. For the purposes of simplicity we will use code an two simple arrays, one for the question (surname) and one for the answer (first name).

At module level in the form define the following

Private strSurnames(2) as String
Private strFirstName(2) as String

On form load do the following

strSurname(0) = "Dillon"
strFirstName(0) = "Bob"

strSurname(1) = "Lennon"
strFirstName(1) = "John"

strSurname(2) = "Jagger"
strFirstName(2) = "Mick"


Then in a function for the start button do the following

For i = 0 to uBound(strSurname)

strAnswer = trim$(inputbox("Enter the first name for " & strSurname(i)))
If LCase(strAnswer) = LCase(strFirstName) Then
intScore = intScore + 1
End If

Next i


That should cover the basics

Cheers

D
Reputation Points: 12
Solved Threads: 8
Junior Poster
davidcairns is offline Offline
114 posts
since Feb 2007
Apr 13th, 2007
0

Re: Simple 2d array help

excuse my arrogance even after a quick google serach i cannot work out what "module level" is and where to find it. I assume "on form load" simply means The area under where it says "public class Form 1"

Thanks
Reputation Points: 10
Solved Threads: 0
Light Poster
jameswoodhouse is offline Offline
30 posts
since Nov 2006
Apr 13th, 2007
0

Re: Simple 2d array help

Basically all code in VB is placed in one of three containers

1. Forms
2. Modules
3. Classes

Forms and Classes can be used to conform with the majority of OO design, excluding principally inheritance. Modules sit outside that as separate peices of code. Despite the name module level variables are actually just variables placed within any of these containers, but outside of any functions or subs. Also module level variables are defined as Private, and hence only usable within that container.

In the case of your problem the container would be a form and the variables would be defined at the top of the form code before any functions.

Form load is an event function, at the top of the vb code window when looking at your form there are two drop down boxes, the first for objects and the second for events that can occur on those objects (if (General) is selected then the containers functions and subroutines are listed). These boxes have a dual purpose, to easily navigate to the desired function and to create the shell of event handlers. In order to create the form load event do the following

1. Open the code window for your form
2. Select Form from the object box
3. Select Load from the event box

This will either take you to an already created Load event, or create an empty procedure to handle that event.

Having said all that to make it easy you could just put the whole thing under the click event of your command button. But it's best to learn this stuff anyway.
Reputation Points: 12
Solved Threads: 8
Junior Poster
davidcairns is offline Offline
114 posts
since Feb 2007
Apr 13th, 2007
0

Re: Simple 2d array help

ohh man i've bitten off more than i can chew, thanks for this explanation its made it a bit clearer, but i'm still no nearer in knowing how to progress
Reputation Points: 10
Solved Threads: 0
Light Poster
jameswoodhouse is offline Offline
30 posts
since Nov 2006
Apr 13th, 2007
0

Re: Simple 2d array help

I'm still finding this very difficult does anyone have a working piece of code in actual vb.net project that i could download & have a look at thanks
Reputation Points: 10
Solved Threads: 0
Light Poster
jameswoodhouse is offline Offline
30 posts
since Nov 2006
Apr 13th, 2007
0

Re: Simple 2d array help

If you are using .Net that will change much of what I said in the previous post, you may want to post in the .Net forum and let the guys over there help you out

Cheers

D
Reputation Points: 12
Solved Threads: 8
Junior Poster
davidcairns is offline Offline
114 posts
since Feb 2007
Apr 17th, 2007
0

Re: Simple 2d array help

can you tell me what would change, i have encountered the original version of visual basic years ago but i dont understand this vb.net.
Reputation Points: 10
Solved Threads: 0
Light Poster
jameswoodhouse is offline Offline
30 posts
since Nov 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Extract data according to Date
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB Macro





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC