Wrox Programmer Forums
|
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 4th, 2012, 01:49 AM
Registered User
 
Join Date: Jan 2012
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Exclamation In School, Need HELP!! (Arrays)

the problem I am trying to code for is as follows:

Construct a two dimensional array and enter into it a sales id number followed by twelve variables which represent sales totals made by the sales agent. this must provide space for five agents.

I can declare the proper array and have done so as follows
Dim Sales (4,12) As Double.
I also crafted a click event which will count from 1-12 (which excludes the sales id number) and disables the sales id number so it cannot get used.

Dim x As Integer
Dim SalesIntCounter As Integer

Private Sub AddToList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddToList.Click

SalesIntCounter = SalesIntCounter + 1
If CDbl(SalesIdInput.Text) = 101 And SalesIntCounter <= 12 Then
' this is where i think the code should go for adding the amount to the variable in the array
ElseIf CDbl(SalesIdInput.Text) = 101 And SalesIntCounter > 12 Then
MsgBox("too many inputs for employee")
SalesIdInput.Items.Remove("101")
SalesIntCounter = 0
End If
End Sub

What I am trying to do is setup a function within the same click event procedure which stores the current SalesAmount as a variable in the array and moves to the next slot to get ready to store the next SalesAmount. However I have no idea where to go from here. I have tried a ton of different pieces of code which are either all littered with errors or do not return a value when I call it. Calling the total of each row and the total for all rows is something I need to do for display and I am not one hundred percent sure I know how to do that either.

Any Direction you can give me would be greatly appreciated even if it is simply a web address to go to which would answer my question.
 
Old January 4th, 2012, 07:50 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

In my opinion i would have create lists containing homemade objects to store all this data.

But as it school, I guess they want you to understand the use of a multidimensional array.

To create the function the two things you need are a key and the returned data, to enter the array. This you should already know. Obviously the returned data is going to be in another array, so you need another Key. And then all that returned data will be in the form of a double.

If you work at your problem like this and breakdown what you need and where the data comes from it should bt easy to code the solution. I can't help you further because I need to know what to use as the keys, what are the limits of array, and how the array is going to be filled out.

Something like this will surfice

myArray(4, 6) As Double

myArray(0)(0) = 12.0 ' This is relating to what
myArray(0)(1) = 13.0 ' This is relating to what

myArray (0) holds the array of data for what . .
myArray (1) holds the array of data for what . .

The Array is self holds what?

If you can be more specific and better covey your problem you will get more help
__________________
Apocolypse2005, I'm a programmer - of sorts.
The Following User Says Thank You to Apocolypse2005 For This Useful Post:
Balthizar (January 4th, 2012)
 
Old January 4th, 2012, 07:53 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

private function returnSales (salesID as double, salesArray()() as double)

dim hisSales() as double

hisSales = salesArray(salesID)

return hisSales

end function

I'm sure that would surfice for finding sales of a specific ID
__________________
Apocolypse2005, I'm a programmer - of sorts.
The Following User Says Thank You to Apocolypse2005 For This Useful Post:
Balthizar (January 4th, 2012)
 
Old January 4th, 2012, 11:33 AM
Registered User
 
Join Date: Jan 2012
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Default

to start, thank you for your help so far. from what i get, you are giving me a solution which contains arrays of arrays. i am required to only work on a two dimensional array at most. however, to answer your question the form this attaches to includes 2 buttons. one button press should do the following:

read data for sales id
locate row for sales id
check current number of inputs stored if this exceeds 12 display a message.
if this does not exceed 12 inputs then store the information from the sales amount into the next open input slot
wait for next input click

the second button is a reporting button so it should gather the total of each row, then gather the total of all the rows and display this information in a list box which is labeled with each sales id and a label stating total sales amount.

the reason i started with an if then statement is because i knew how to tie that to a click event and i could make it check the number of times it has ran. i will eventually, i assume, turn that if statement into a function and use a variable so i could use it over and over for each sales agent.

the real issue in this whole thing is that i do not know how to store data into a declared array, increment to the next spot in the array and store a new value there. this is where i am getting stuck and reading my text book for the fifth time wont get it into my head. what i think i really need is a quick and dirty crash course in two dimensional arrays for a little kid, because i am having a heck of a time grasping this concept.
 
Old January 4th, 2012, 12:07 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

I assume vb has the push function as part of the array functions

myArray.Push( item to push )

Its been a while since programming VB and I have now got a mac.

So basically you would search for the salesID then push to that array . . . simple.

myArray(salesID).Push(salesAmount)

Done!

See myArray(salesID) that selects out of the first array the set of data in the second array. The Push adds the data to the end of the list. Creating the next space in the array so you dont have to.

That is what you limit to 12. Keep track of the number of sales, push each time until 12 is hit!
__________________
Apocolypse2005, I'm a programmer - of sorts.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with school question biggspj Access 6 July 19th, 2006 01:04 AM
HELP! Tables and queries in school project joseph.novak SQL Language 0 October 29th, 2005 01:13 PM
High School Project on Computer Programming Mercution Beginning PHP 0 June 6th, 2005 08:51 PM
Building School Library Application??? mythinky .NET Web Services 1 March 1st, 2004 06:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.