Two dimensional arrays!!!!

Hey Experts,

I have a table which has a list of locations and for each location i need to capture the Company and Sponsor information like name address phone and fax. I have a form which has the drop down which lists the location and 10 text boxes to accept the contact information. for each of the location the form has to accept all the contact information and save all the information at the same time. I was trying to use the 2 dimesional array to capture all the contact information and save them to the database but was not able to figure out how to do it..

Any ideas will help me a great deal..

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It's usually benaficial to create Classes which define all the information and are linked like in the database.

Use the Class Builder Utility, it makes it simple. Then you can create a collection based on that class. so you create a class called Client and a collection called Clients and then use that to save the data from the database.
sramkrisAuthor Commented:
THanks for the comment
I have very little idea as how to get it done so if you have any example or code base which i can look at it will be very helpful.
The db structure is all not that good and basically i want to complete the data entry of what the user is entered so i was thinking more in terms of arrays to get the job done...

If you have any eg for either case it will help me a great deal to get this one done


Ok..just to confirm what you want to do...

User selects a location from the list box..and then enters the contact details like name, address..etc using these 10 textboxes... right?

Now how is your database designed.. i mean..have you a table for Location  and one for Contact or.. do you have only one table?

NExt question... what database have you got it sql server or ms access...or anything else.?

I guess the easiest way to do this is to

1. Get location which user selects from list
2. Read whatever details user has entered in the textboxes
3. Just Pass these data from textboxes as parameters and insert them in your database..(i.e no need to use 2-d arrays)

Now how you insert these data for each location in your tables depend on how your tables are designed!!!

Maybe you could give us some more information here!!

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

sramkrisAuthor Commented:
Hey Lichien

You got most of it right. The user selects a location and then enters data in the text boxes and he can select the next one and enter data in all the text boxes. All this is stored in a table called contact. I have a table called location and it has PK loc_id and it is a FK in the contact table. The contact table has loc_id and cont_id as PK in this table. I have a Sybase database and i am using MS Access and VB Automation to write data to this table. I agree with your idea that i need 2 d arrays but i have not used 2 d arrays before so i have no idea how to get this done!! Any help is highly appreciated.



Sorry I think you missed it.. I suggested NOT to use 2-d arrays... :-)

I was thinking more in term of updating the table directly..for example having an update button ..when user clicks on run an update

Insert into contact (loc_id,cont_id, field1, field2,field3...field10)
values (<selected locid>,<new contid>,<from textbox1>,<from textbox2>...<from textbox3>)

Now I dunno the exact syntax with sybase...maybe you could rearrange the query for sybase.

Its arguable... but personally I think in this case using the 2-d array is an extra overhead.. because you will be reading whatever has been inputted in the textbox.. transfer them to a 2-d array and then transfer to the tables..  when you could have make do without the 2-d array...if you c what I mean.

but if you still wanna use the 2-d array

you could declare it as..

dimension my2darray(X,Y) as string ...where X will be the index for your locid... and Y will be the textbox..

for example
my2darrray(1,5)... will represent Location 1..textbox 5 ...important to note that the array actually starts at 0 ..but you can start assigning from index 1.. just make sure that you remember it if looping thru array.

hmmm..thinking of it can keep the location_id in the first cell.i.e my2darray(1,0) = location_id

so you can loop thru the array like

' Loop through all locations in array
For locIndex=1to  NumberofLocations
   ' Now check all data entered for a location
   For TextIndex=0 to 10  ' Here I am starting at 0 because I want to keep the location_id in (1,0 )..remember
          my2darray(locindex,textindex)  ' this is how you access each cell in the array.


Going back to previous point.. i still think its better to just wack whatever is in the textboxes directly to the table..rather than going thru a 2d array...  anyway have a go and let me know in case of problems... can try to give you ideas..but as far as syntax on sybase is concerned...i haven't used it,....sorry.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sramkrisAuthor Commented:
Hi Lichien

I guess i missed the point totally. Actually i was interested in using the 2D  arrays because when the user is doing data entry he can enter data for 3 locations at the same time and before commiting the data to the db he can change any data for any location and then save it. So i was thinking if he needs to see the data before the save is done then the data has to be stored in a array and show the user the values at the change of the value in the location drop down.
Now after seeing your ideas i feel i can add the record to the db and populate the record back from the db when the user selects the location and update the record everytime.
Will that make the process slow cause i am going back and forth with the data....?????
I also did not need any code in sybase..I am more interested in the knowing how to do it in VB.. I will run through your code in vb and then let you know or may be if you remember anything which needs to be added in th code which you have written let me know and i will use it to see if it works using a 2D arrays.
Now i am more interested in knowing how it is done using a 2d array.

Thanks for all your help
Actually its better to send multiple small requests to the server ...than sending one big chunk....

I dont think its going to make the process slower... and anyhow... after the user has entered info for a can get him to click on a Save button...and then just prompt him that he wants to save the details.

The problem with using arrays is that... for example.. basic scenario....user enters details for 10 locations.. computer crashes... that means he has to do the whole thing again..i.e enter details for 10 locations again..because the array exists only in memory

Doing it the way i suggested... user has to enter details for 10 locations... he does the first one.. program prompts him to get written to database.. he carries on like this for each location..  while entering the details for the 9th... computer crashes (dunno why ..:-) this case... he's at least got 8 records he just need to enter for the 9th and 10th location..  this itself should convince you!!

Concerning the codes for the 2darray..I think I've given you the skeleton that you get an idea... I just have to try it..and see..

Good luck
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.