473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

2-D Array

I've just moved onto 2-D Arrays in my VB6 beginners book. I'm struggling to
get my head around the following problem but no doubt you will think it
rather easy.
My program is supposed to allow up to 20 students to enter their name and 3
exam marks, with each students details being entered into a 2-D Array upon
the click of a command button. There is also a list box and another command
button which will display the contents of the array. I have next to nothing
done but I'll post it anyway. Thank you.

Option Explicit
Dim Details(1 To 20, 1 To 3) As String
Dim Index As Integer

Private Sub cmdAddToArray_Click()
Index = Index + 1
Details(Index, 1) = txtMark1.Text
Details(Index, 2) = txtMark2.Text
Details(Index, 3) = txtMark3.Text
End Sub
Jul 17 '05 #1
3 15502
"Roy Riddex" <ro**************@blueyonder.co.uk> wrote in message
news:Zf*****************@news-binary.blueyonder.co.uk...
I've just moved onto 2-D Arrays in my VB6 beginners book. I'm struggling to get my head around the following problem but no doubt you will think it
rather easy.
My program is supposed to allow up to 20 students to enter their name and 3 exam marks, with each students details being entered into a 2-D Array upon
the click of a command button. There is also a list box and another command button which will display the contents of the array. I have next to nothing done but I'll post it anyway. Thank you.

Option Explicit
Dim Details(1 To 20, 1 To 3) As String
Dim Index As Integer

Private Sub cmdAddToArray_Click()
Index = Index + 1
Details(Index, 1) = txtMark1.Text
Details(Index, 2) = txtMark2.Text
Details(Index, 3) = txtMark3.Text
End Sub


Where are you going to store the student's name?
....
Dim Details(1 To 20, 1 To 4) As String
....
How are you going to store the student's name?
....
Private Sub cmdAddToArray_Click()
Index = Index + 1
Details(Index, 0) = txtStudentName.Text
Details(Index, 1) = txtMark1.Text
....

And a question for you:
What happens when Index >20?
Should get you started.
Geoff Turner
Jul 17 '05 #2

Where are you going to store the student's name?
That's why I'm struggling. The book says to store the student's name and the
3 exam marks in the 2D array. It also says I must declare it as a string
since all values must be of the same type within an array. So it looks as
tho my 1 to 20 statement may be wrong, but, what do I replace it with?
And a question for you:
What happens when Index >20?


I haven't thought that far ahead yet because I really feel I've hit a brick
wall. Maybe my brain has hit it's limits with programming...lol. Can
somebody point me in the right direction?
Thanks
Jul 17 '05 #3
I believe you may find it advantageous to use named constants for the
variables in the array ... it can make identifying different elements easier
when reading the code. And get into the habit of using 0-based arrays -- a
suggestion.

For example ...

private const nStudentName = 0
private const nMark1 = 1
private const nMark2 =2
private const nMark3 = 3

Dim Details(0 To 19, 0 To 3) As String '20 x 4

Details(Index, nStudentName ) = txtName.Text
Details(Index, nMark1) = txtMark1.Text
Details(Index, nMark2) = txtMark2.Text
Details(Index, nMark3) = txtMark3.Text
--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Roy Riddex" <ro**************@blueyonder.co.uk> wrote in message
news:Zf*****************@news-binary.blueyonder.co.uk...
: I've just moved onto 2-D Arrays in my VB6 beginners book. I'm struggling
to
: get my head around the following problem but no doubt you will think it
: rather easy.
: My program is supposed to allow up to 20 students to enter their name and
3
: exam marks, with each students details being entered into a 2-D Array upon
: the click of a command button. There is also a list box and another
command
: button which will display the contents of the array. I have next to
nothing
: done but I'll post it anyway. Thank you.
:
: Option Explicit
: Dim Details(1 To 20, 1 To 3) As String
: Dim Index As Integer
:
: Private Sub cmdAddToArray_Click()
: Index = Index + 1
: Details(Index, 1) = txtMark1.Text
: Details(Index, 2) = txtMark2.Text
: Details(Index, 3) = txtMark3.Text
: End Sub
:
:
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.