Solved

Two dimensional arrays!!!!

Posted on 2003-11-20
7
776 Views
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..

Thanks
-Ram
0
Comment
Question by:sramkris
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:monkesdb
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.
0
 
LVL 1

Author Comment

by:sramkris
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

Thanks
0
 
LVL 1

Expert Comment

by:Lichien
ID: 9795999
Ram...

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






0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:sramkris
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.

Thanks
Ram


0
 
LVL 1

Accepted Solution

by:
Lichien earned 125 total points
ID: 9802524
Ram...

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 it...you run an update query..like

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 ...you 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.
   Next

Next

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.














0
 
LVL 1

Author Comment

by:sramkris
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
Ram\
0
 
LVL 1

Expert Comment

by:Lichien
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 location..you 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 confirm..data get written to database.. he carries on like this for each location..  while entering the details for the 9th... computer crashes (dunno why ..:-)  ...in this case... he's at least got 8 records saved..so 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 ...so that you get an idea... I guess...you just have to try it..and see..

Good luck
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now