Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Someine Elplain the concept behind Dim "arFormFields0(7)"

Status
Not open for further replies.
Apr 11, 2003
105
US
I am working with an ASP form that has several fields that i can't find any logic behind. I am still a novice when it comes to writing pages. Any help would be grately apreacheated.
Code:
        Dim iRecordId
	Dim arFormFields0(7)
	Dim arFormDBFields0(7)
	Dim arFormValues0(7)

	arFormFields0(0) = "Prob"
	arFormDBFields0(0) = "Prob"
	arFormValues0(0) = Request("Prob")
	arFormFields0(1) = "Last"
	arFormDBFields0(1) = "Last"
	arFormValues0(1) = Request("Last")
	arFormFields0(2) = "tech"
        ______________________________

	deleted for space
        _______________________________
	arFormFields0(6) = "Operator"
	arFormDBFields0(6) = "Entered"
	arFormValues0(6) = Request("Operator")

Okay, What i am trying to do is add another request that will tell me the database id of the entry that is created. I am also trying to make it so that all of this information is then e-mails to a receipeint. so this is a How dose this work questions. at the end of the "Dim arFormFields0(7)
" statement there is a 7 what dose the 7 represent? also if i had a nother field do i have to bump it up to 8 or can i just add 8 as the next line. Also at the end of the code i have put an entry to request the ID of the Database but it never returns the info. it wrights with no problem.
Code:
   <input type="hidden" name="ID" value="<%= fp_rs.Fields("ID").Value %>"
 
it's an array declaration. though it's a pretty odd method of using arrays. 3 single dimension arrays where 1 multi dimensional one would do, seems to be pretty inefficient, and the potential for error is great.

but anyway to extend it change the 7s to 8s though this could be simplified by this
Code:
const arMax = 8 ' set value for max size of array
    Dim arFormFields0(arMax)
    Dim arFormDBFields0(arMax)
    Dim arFormValues0(arMax)
then one edit changes all (less error prone)



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Dim arFormFields0(7)
" statement there is a 7 what dose the 7 represent?
When you are dimensioning an array named arFormFields0 and saying that it will have a maximum index of 7 (meaning that there are 8 possible elements in the array - 0,1,2,3,4,5,6,7)

Getting the ID of the input back can depend on which DB you are using (Access, sqlServer, mySQL, ???) but you can also get the info like this...
Code:
sql = "INSERT myTable (field1, field2) VALUES (" int1 & "," & int2 & ")"
cn.execute(sql)
sql = "SELECT id FROM myTable WHERE field1 = " & int1 & " AND field2 = " & int2 
set rs = cn.execute(sql)

id = rs(0)
Obviously, this is VERY simplistic and not the best way - it's just an example. If you have more than one record with the same data, you could get the wrong ID...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
i'll try to note out as best i can what most of this is, based on common naming conventions:

Code:
    Dim iRecordId [green] (i)nteger variable for the record ID [/green]
    Dim arFormFields0(7) [green] (ar)ray for the form fields/elements defined as 7 ( 0-7, which is 8 items ) the zero before the parens is just part of the name, i guess the developer guessed he might have needed more than one of these, or methodically added non-alphabet chars to names to avoid conflict [/green]
    Dim arFormDBFields0(7)  [green] same as the last one but for the database fields ( 8 array slots again ) [/green]
    Dim arFormValues0(7)  [green] my assumption this would be a "sister" (ar)ray for the form field/elements that would house the values in matched pairs for the first array ( see example 1 below ) [/green]

 [green] all this below here is just putting values into the arrays, some from the request collection, the others are just static like "Problem" , "Last (contact?)", and Technician" [/green]

    arFormFields0(0) = "Prob"
    arFormDBFields0(0) = "Prob"
    arFormValues0(0) = Request("Prob")
    arFormFields0(1) = "Last"
    arFormDBFields0(1) = "Last"
    arFormValues0(1) = Request("Last")
    arFormFields0(2) = "tech"
        ______________________________

    deleted for space
        _______________________________
    arFormFields0(6) = "Operator"
    arFormDBFields0(6) = "Entered"
    arFormValues0(6) = Request("Operator")

**Example 1 :
sample Arrays of matched pairs based on the alphabet :
Letters = Array(a,b,c,d)
Positions = Array(1,2,3,4)

although it would be very easy to eliminate one of these in the example, but it's just a simple ( useless ) example

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
my guess on DBFields, it's not database interaction, until later, in an sql statement or such... i would estimate there's a loop cycle later that takes the values back out of the arrays, or uses the arrays in their whole state to populate an SQL statement. the DB fields array i think only holds the field names.

which ..sort of (??) makes sense, in order to use form elemets to update the DB ( besides connections and so forth ) you have to know 3 things :
which form element goes to what DB field with what entered value

which is giving you your 3 arrays, BUT, whomever set it up very undynamic because the fieldnames, and the element names are hard coded into it..(defeats the purpose of the arrays)

hopefully that helps shed some light on the original questions, as for if you add another db field ( i would bet this array is NOT all the db fields ) would u have to bump up the number, no, unless it becomes a part of your web form that would need to go back into the DB, then yes. use Chris's code for that, it will save some headaches, or save more space and headaches, you'll need to kill all the definition lines afterwards, and change a few things at first, but in the future if you need to add a new field, you just add the respective values to :
Code:
[green] the definition numbers are removed to allow Array() below to define the size with the supplied values, use Ubound(arFormFields0) to figure out how many slots it's using.[/green]

    Dim arFormFields0() 
    Dim arFormDBFields0()
    Dim arFormValues0()

    arFormFields0 = Array("Tech","Problem","Operator",etc) [green]' these are the form element names[/green]
    arFormDBFields0 = Array("Tech","Prob","Oper",etc) [green]' these are the actual field names in the DB associated w/ the form elements[/green]
    arFormValues0 = array(request("tech"),request("Problem"),Request("Operator"), etc) [green]' these are the requested values that match the first array above of the form elements, in all actuality, this can be removed, and all you need is the form element names and the db names, and just request as you go.[/green]


[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top