Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Two dimensional arrays!!!!

Posted on 2003-11-20
Medium Priority
Last Modified: 2010-05-01
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..

Question by:sramkris
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Expert Comment

ID: 9791554
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.

Author Comment

ID: 9791862
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


Expert Comment

ID: 9795999

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!!

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 9801128
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.



Accepted Solution

Lichien earned 500 total points
ID: 9802524

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.


Author Comment

ID: 9812672
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

Expert Comment

ID: 9818036
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question