| | |
Simple 2d array help
Thread Solved |
•
•
Join Date: Nov 2006
Posts: 30
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Feb 2007
Posts: 114
Reputation:
Solved Threads: 8
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
On form load do the following
Then in a function for the start button do the following
That should cover the basics
Cheers
D
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
•
•
Join Date: Feb 2007
Posts: 114
Reputation:
Solved Threads: 8
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.
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.
![]() |
Similar Threads
- Simple array question (C++)
- Simple 2d array, please help.! (VB.NET)
- Creating simple array... headache. (Java)
- converting a char array to a single char (C)
- Playing with shared memory - problem with non 'simple' data types (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Extract data according to Date
- Next Thread: VB Macro
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





