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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Two values in Subroutine

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
0
0
US
I am trying to pass two values into a subroutine for an Insert statement. It appears though that "value" is some kind of reserved word and that it is required rather than the value1 and value2 below. Is there another way to do it?

[tt]Sub AddRecord( value1, value2 )
DataConn.Execute = "INSERT into compservices (id, type, fee) " &_
"VALUES (" & session("id") & ", " & value1 & ", " & value1 & ")"
End Sub[/tt]

Here is where the subroutine is being used, but it does not "like" the (ID, Fee) as apparantly that is wrong too:

[tt]rslookup.MoveFirst
do while not rslookup.EOF
ID = rslookup("ID")
Fee = Request("Fee")
If Request(ID) = 1 then AddRecord(ID, Fee)
rslookup.MoveNext
loop[/tt] Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
I think you might need to put quotes around ID in this code:
is this field coming from a form? or a URL parameter?

What does this reference? Request(ID)

If it is just the variable you set above then you don't need the Request, it doesn't appear.
 
No, ID is a variable and is actually an integer, but as the conditional is being met and I am able to Insert a single value, that is not the problem.

The problem is in trying to get the two values passed into the subroutine, which does not seem to work unless there is only one and it is called "value" (without the quotes). If I call it anything else, or if I try to use two, it does not work. Only the (ID, Fee) makes it crash though. If there is one one, such as (ID), then it does not crash but neither does it Insert.

I suppose I could create a second subroutine and reference it separately in the loop but I don't think that should be necessary. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Change your if statement as follows:

If Request(ID) = 1 then AddRecord ID, Fee
 
Thanks! Actually, I tried that yesterday and it did not work though I do not remember if there was an error or if simply nothing was Inserted. I'll try it again tomorrow and post the results. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
No, that doesn't work either. It does not crash but neither does it submit anything. In fact, if I call the subroutine value anything but "value" it does not write to the table:

ie:
Sub AddRecord( value1 ) does not work but

Sub AddRecord( value ) does. I don't know much about arrays, but can "value" be an array containing the two fields' values that I am trying to submit?

Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
I aggree with the message from above:
What does this reference? Request(ID)
Request(ID) is looking in the request object for a key named ID (should be "ID")
ID should be in quotes otherwise you will never find the item in the request object.

To test this change the statement as follows
and print out the values in the sub
IF REQUEST(ID)="" THEN AddRecord ID, Fee
 
No, you are misunderstanding the conditional but that part is working so is not the issue (I regret posting that part now since it's apparently caused so much fuss). To make it clearer though, what it's saying is (for example):

[tt]If Request(6) = 1 then AddRecord(6)[/tt]

where 6 is the value that the variable represents.

I am sending one or more checkbox fields with a different integer as the name=&quot;<%=ID%>&quot; of each and all with a value=&quot;1&quot;.

ID is an integer variable coming from looping through a recordset so quoting would not work at all because it is not the characters &quot;ID&quot; that it is using but rather the value that ID represents. The looping is not a part of the posted problem though so I did not post that part of the code.
Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
I simulated your code(but without the () around the arguments for the addrecord sub) and it appears to work. The values are passed to the sub. The only thing I can think of is where DataConn is declared.
Is it declared in the sub, or as a global variable outside of any subs or functions
 
DataConn is the database connection which uses global.asa to make the connection and is outside the subroutine. It is not a recordset itself but simply opens the database so that recordsets can be created where needed. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Have you put anything in the sub to see if the code is actually getting into the subroutine.
i.e.

Sub AddRecord( value1, value2 )

on error resume next
response.write &quot;Value1&quot; & value1
response.write &quot;Value2&quot; & value2

DataConn.Execute = &quot;INSERT into compservices (id, type, fee) &quot; &_
&quot;VALUES (&quot; & session(&quot;id&quot;) & &quot;, &quot; & value1 & &quot;, &quot; & value1 & &quot;)&quot;

response.write &quot;error:&quot; & err.description
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top