|
-
Mar 12th, 2001, 09:31 AM
#1
Thread Starter
Hyperactive Member
Hi everyone!
I was wondering if someone can help me. I am thinking about using a 2 dimensional array (I think) to save some data. I am terrible with arrays. I need to get a review from someone how arrays work and some vbscript examples, if possible.
Thanks in advance.
-vbuser1976 
VB6 Enterprise SP6
SQL 7.0 SP2
VBScript, HTML, Javascript, C++, a little UNIX
-
Mar 12th, 2001, 12:48 PM
#2
Addicted Member
No problem:
dim MyArr(2,2)
MyArr(0,0)=1
MyArr(0,1)=2
MyArr(0,2)=3
MyArr(1,0)=4
MyArr(2,0)=5
etc etc
then:
for i=0 to ubound(Myarr,1)
for j=0 to ubound(MyArr,2)
response.write Myarr(i,j)
next
next
good luck
André
-
Mar 12th, 2001, 01:12 PM
#3
Thread Starter
Hyperactive Member
Hmm...
Okay, I understand what you have written. But, maybe I should specify what I am trying to do.I have an asp page with a data entry table with 5 rows and 7 columns. Each row constitutes a record with 7 fields. Basically, what I want to do is create a user-defined data type (that would be the 7 columns)and create an array to save the user entered data. I hope you can understand what I want to do. Is there a specific way to name the data entry fields of the table for this to work. I want to write a little code as possible.
Thanks again for your help.
-vbuser1976 
VB6 Enterprise SP6
SQL 7.0 SP2
VBScript, HTML, Javascript, C++, a little UNIX
-
Mar 12th, 2001, 02:52 PM
#4
Addicted Member
Ah, ok
you want to represent the data entry as a recordset?
why don't you create a custom recordset?
this way you can name your columns and iterate trough the records as you do with an ADODB.Recordset?
else
dim i 'row
dim j 'column
take the values of the first row and put them in their respective columns:
Array(0,0)=ValueOfRow1Column1
...
Array(0,6)=ValueOfRow1Column7
and so forth for each row
Does this help?
André
-
Mar 12th, 2001, 03:13 PM
#5
Thread Starter
Hyperactive Member
Yes, but...
Yes, this is what I am looking for, but I have a stupid question: What is a custom recordset and how do you create one?
-vbuser1976 
VB6 Enterprise SP6
SQL 7.0 SP2
VBScript, HTML, Javascript, C++, a little UNIX
-
Mar 13th, 2001, 03:12 AM
#6
Addicted Member
I have done custom recordsets in VB, but not tested in VBScript, I always encapsulate my business logic into COM components, anyway this is the VB howto create your custom recordset:
Code:
Set rsCustomers = New ADODB.Recordset
With rsCustomers
' Set CustomerID as the primary key.
.Fields.Append "CustomerID", adChar, 5, adFldRowID
.Fields.Append "CompanyName", adChar, 40, adFldUpdatable
.Fields.Append "Address", adChar, 60, adFldUpdatable
.Fields.Append "City", adChar, 15, adFldUpdatable
.Fields.Append "PostalCode", adChar, 10, adFldMayBeNull
.Fields.Append "Country", adChar, 15, adFldUpdatable
.Fields.Append "Phone", adChar, 24, adFldUpdatable
' Use Keyset cursor type to allow updating records.
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open
End With
'Now you have a recordset, let's put values in it:
With rs
.AddNew
.Fields("CustomerID").Value="AMV"
.Fields("CompanyName").Value="PA"
.....
.Fields("Phone").Value="12345678"
.Update
End With
You can put that in a loop or whatever you like, at the end you will have an ADO Recordset yo can work with, as if you had executed a SELECT query!
Good Luck
-
Mar 13th, 2001, 03:18 AM
#7
Addicted Member
Actually, just the AddNew part should be in a Loop, you only need to define the recordset once,
Regards
André
-
Mar 13th, 2001, 09:12 AM
#8
Thread Starter
Hyperactive Member
THANKS!
Thanks on the short tutorial on custom recordsets. One other question though: How do you go through the table and assign the values to the right location, in other words, how do I do this(what is in bold):
Code:
Array(0,0)=ValueOfRow1Column1
I know how to do it with datagrids in vb (textmatrix etc). Any ideas on how to accomplish this. I am sorry I am so annoying. Thanks again for all your help
Oops, just noticed that you answered this. What I am really asking is how does vbscript knows that the table is where I want the custom recordset to work at?
Last edited by vbuser1976; Mar 13th, 2001 at 09:15 AM.
-vbuser1976 
VB6 Enterprise SP6
SQL 7.0 SP2
VBScript, HTML, Javascript, C++, a little UNIX
-
Mar 14th, 2001, 03:21 AM
#9
Addicted Member
I guess you have a form right?
This form has 5 rows and 7 columns right?
Then you know exactly the names of the fields!
If you name the fields the same, then when you submit the form you will have an array of values!
for example an inout type text with the name CustomerID. by having 5 rows you will have an array CustomerID(4). You get this by request.form("CustomerID")(i)
So by doing it this way, you now have 7 column arrays, with their index referring to a row!
I would say that you have to massage the arrays and shape them into the recordset 
André
-
Mar 14th, 2001, 06:15 AM
#10
Thread Starter
Hyperactive Member
Okay, I understand now...
Okay, so what I am getting from this is that if I have a table with rows and columns, in order for vbscript to understand I need for it to create an array, all fields in a column need to have the same name and then when I try to save it using "Arr(i)" it will understand it.
Hmm, sounds simple enough. Thanks for all your help and I will let you know if I got it working.
-vbuser1976 
VB6 Enterprise SP6
SQL 7.0 SP2
VBScript, HTML, Javascript, C++, a little UNIX
-
Mar 14th, 2001, 07:25 AM
#11
Addicted Member
-
Mar 15th, 2001, 01:20 PM
#12
Thread Starter
Hyperactive Member
help again please!
Okay, now I need to bring the data back into the table. How do I do that? Of course, the database is not an array but it is bringing in the records I need. I just need to know how I put them back in the table in the right places. Any ideas? Remember, all the fields in a column have the same name.
Thanks in advance.
-vbuser1976 
VB6 Enterprise SP6
SQL 7.0 SP2
VBScript, HTML, Javascript, C++, a little UNIX
-
Mar 16th, 2001, 01:42 AM
#13
Addicted Member
Ok, you need to build a loop like this, after retrieving the recordset from the database:
Code:
response.write "<table>
Do until rs.EOF
response.write "<tr>"
response.write "<td><input type=text name=CustomerID value=" & rs.Fields("CustomerID").value & "></td>"
response.write "<td><input type=text name=CustomerName value=" & rs.Fields("CustomerName ").value & "></td>"
'etc etc.
response.write "</tr>"
rs.moveNext
Loop
response.write "</table>"
This should build your table with data from the recordset and with fields named the same.
Cheers,
André
-
Mar 16th, 2001, 01:44 AM
#14
Addicted Member
I saw a typo, the first response.write "<table> is missing the end quotation!! it should be "<table>"
André
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
|