|
-
Nov 20th, 2004, 08:17 AM
#1
Thread Starter
New Member
2 dimensional arrays
I need help with the following:
I want to develop a program for school attendance using a 2 dimensional array. I will have textboxes representing Monday through Friday. Also, I have a combo box representing each week. eg: Week1,2...
I want to be able to correspond the attendance each day to the week number and save it to an array.
Any help would be most appreciated. I am using visual basic.net
Thanks
Ken
-
Nov 20th, 2004, 08:29 AM
#2
PowerPoster
Hi,
If you use a 3 dimension array it is simpler.
As you know you can only store data in the final dimension, the other dimensions being merely numerical locations.
So, in arr1(52,7,0) the first dimension index number represents the week number (assuming a yearly basis); the second dimension represents the numerical day of the week and you can store the attendance record in the third dimension.
If you wish you can give the third dimension more than one element and store data in each of those elements -
e.g. arr1(52,7,1) would allow you to store male attendence in element 0 and female attendence in element 1
You could use a 2 dimension array but it would be much mor involved.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 20th, 2004, 08:53 AM
#3
-
Nov 20th, 2004, 09:03 AM
#4
Thread Starter
New Member
This is an assignment that I am doing for my self study program. I have not reached the section regarding databases yet. The assignment requires that I use a 2 dimensional array. I need help in setting it up. Thanks
-
Nov 20th, 2004, 09:05 AM
#5
PowerPoster
Originally posted by mendhak
Why no database?
Hi,
If you want to teach him database connections from scratch I will follow this thread with interest I bet you only posted that to keep ahead
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 20th, 2004, 09:11 AM
#6
Originally posted by taxes
I bet you only posted that to keep ahead
Do you think I really need to keep ahead? Just trying to suggest something here, post counts stopped mattering after I got to 666.
-
Nov 20th, 2004, 09:12 AM
#7
PowerPoster
Hi,
If you have to use only one 2 dimension array you could use
Dim arr1(52,4) (assuming a 5 day week)
The first dimension index number again represents the week number.
You cand then store the attendance for the first week for
Monday in arr1(1,0)
Tuesday in arr1(1,1)
etc.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 20th, 2004, 09:15 AM
#8
Thread Starter
New Member
Taxes,
Could you help me in setting up the array from the beginning. I am very new to vb.net and your's or anyone's help is greatly appreciated
Ken
-
Nov 20th, 2004, 09:23 AM
#9
Thread Starter
New Member
This is how I have it set up.
Combobox shows weeks 1 to 52 and its name is cboWeeks
Then there are 5 textboxes representing Monday thru Friday named txtMonday etc. The user selects a week and then enters the attendance numbers each day in the textbox and would save the weeks result in the array.
-
Nov 20th, 2004, 09:37 AM
#10
PowerPoster
Hi,
Have a try, then post your attempt. That is the best way to learn.
Consider the following;
1. Preparing the array is simple.
Dim arrAttendance(52,5) As Integer There is actually
53 elements in the first dimension and 6 in the second
as they start at 0 but I am ignoring the 0 index in each
dimension for clarity of reference.
2. Decide whether you want the array to have form or more local
scope. For form scope declare it at the beginning of the code.
3. Decide how you want to add the attendance results to the
array. At design time or in run time.
4. How do you want to show the results. In a ListBox, a ListView
or a series of TextBoxes or Labels.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 20th, 2004, 09:46 AM
#11
PowerPoster
Hi,
Our posts crossed.
Consider the following:
1. Once the user has made an entry into the textbox, you have to make sure he has entered a valid number. To do this use the IsNumeric function. Have a look at the events available to the TextBox and decide which event is most suitable to handle the code.
2. Do you need a method whereby the program knows it has to proceed with the storage of the data?
See how you get on.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 20th, 2004, 11:42 AM
#12
PowerPoster
Originally posted by mendhak
Do you think I really need to keep ahead? Just trying to suggest something here, post counts stopped mattering after I got to 666.
I'm surprised you went past 665
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 20th, 2004, 12:58 PM
#13
Thread Starter
New Member
Taxes,
I have a program to ensure that the items entered in the text boxes are valid. I will set up my program later using your suggestions and let you know the outcome.
Thanks again for your time
Ken
-
Nov 20th, 2004, 05:36 PM
#14
Thread Starter
New Member
Please advise if I am the right track here. I provided coding for 4 weeks of information: Thank you...
Dim iAttendance(3, 4) As Integer
Private Sub btnSaveWeek_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveWeek.Click
Dim iMon As Integer = CInt(txtMonday.Text)
Dim iTue As Integer = CInt(txtTuesday.Text)
Dim iWed As Integer = CInt(txtWednesday.Text)
Dim iThu As Integer = CInt(txtThursday.Text)
Dim iFri As Integer = CInt(txtFriday.Text)
Dim iIndex1 As Integer
For iIndex1 = 0 To 3
iAttendance(iIndex1, 0) = iMon
iAttendance(iIndex1, 1) = iTue
iAttendance(iIndex1, 2) = iWed
iAttendance(iIndex1, 3) = iThu
iAttendance(iIndex1, 4) = iFri
Next iIndex1
End Sub
Private Sub btnShowAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowAverage.Click
Dim iMon As Integer = CInt(txtMonday.Text)
Dim iTue As Integer = CInt(txtTuesday.Text)
Dim iWed As Integer = CInt(txtWednesday.Text)
Dim iThu As Integer = CInt(txtThursday.Text)
Dim iFri As Integer = CInt(txtFriday.Text)
Dim iIndex1 As Integer
Dim dAverage As Decimal
Dim dTotalDays As Decimal
For iIndex1 = 0 To 3
iAttendance(iIndex1, 0) = iMon
iAttendance(iIndex1, 1) = iTue
iAttendance(iIndex1, 2) = iWed
iAttendance(iIndex1, 3) = iThu
iAttendance(iIndex1, 4) = iFri
dTotalDays = iMon + iTue + iWed + iThu + iFri
Next iIndex1
dAverage = dTotalDays / 5
MessageBox.Show("Average Days For Week: " & cboWeek.SelectedItem & " is: " & CStr(dAverage))
End Sub
-
Nov 20th, 2004, 05:51 PM
#15
Sleep mode
Originally posted by mendhak
Do you think I really need to keep ahead? Just trying to suggest something here, post counts stopped mattering after I got to 666.
Frog , your post count is great acheivement . This proves how helpful you're
-
Nov 20th, 2004, 08:47 PM
#16
PowerPoster
Hi,
Let's take this a little at a time.
In
For iIndex1 = 0 To 3
iAttendance(iIndex1, 0) = iMon
iAttendance(iIndex1, 1) = iTue
iAttendance(iIndex1, 2) = iWed
iAttendance(iIndex1, 3) = iThu
iAttendance(iIndex1, 4) = iFri
Next iIndex1
You are storing the same data in each of the 4 weeks covered. You do not need a loop here. You need to load the week number selected in the combobox (say iWeek) and then use
iAttendance(iWeek, 0) = iMon
iAttendance(iIWeek, 1) = iTue
iAttendance(iWeek, 2) = iWed
iAttendance(iWeek, 3) = iThu
iAttendance(iWeek, 4) = iFri
I would be inclined to give iAttendance form scope and either put this code in a separate Sub or automatically calculate the average in the Sub btnSaveWeek_Click. If you don't want to show the average automatically, disable the btnShowAverage until there is an average to be shown.
Don't forget to check the textboxes for numeric, integer value only.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 20th, 2004, 09:06 PM
#17
PowerPoster
Originally posted by Pirate
Frog , your post count is great acheivement . This proves how helpful you're
It was just banter.. Do you appreciate the significance of 666?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 21st, 2004, 05:35 AM
#18
Thread Starter
New Member
Taxes,
Thank you for the information. I assume I will not need a loop for iweek either because that value is determined by the selection of the combo box value
Ken
-
Nov 21st, 2004, 07:54 AM
#19
PowerPoster
Originally posted by kgs51
Taxes,
Thank you for the information. I assume I will not need a loop for iweek either because that value is determined by the selection of the combo box value
Ken
Correct
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|