Passing parameters (need help)

jigsaw1975
07-18-2003, 07:04 AM
I have never really understood passing parameters and when to use a function to do so and when to use a procedure. Can someone please help me out.

SUMMARY: I have 2 company records. I need to pass a boolean value from one company record to the other. How do I do that?

DETAIL:

In my database, I am dealing with several thousands of companies, some of which are duplicates obviously. I am implementing a function which assists in the consolidation (deletion) of the unwanted or duplicate company records.

A user opens up a company record (for eg. Company 1), within that there is a "Consolidation field" (where the user can select another company record (company 2) - the one he wishes to delete). Then clicks save. Then my internal processing deletes the company saved in the Consolidation field (2) and keeps the one he had actually opened up (1).

All the company records may or may not be attached to several plans. What I need to do is check if Company 2 was attached to any plans or not and then pass this information to Company 1. I know I can have a boolean which checks whether it is attached to a plan or not. I have this coded..I know how to check for that..now I have a 0 or 1 value depending on whether the company is attached to plans or not but I don't know where to store this value and how to send it to Company 1. Also, do I use procedures or functions to do so.

Need help urgently and desperately.

JordanChris
07-18-2003, 07:40 AM
You use a function if you want to get a result back from the sub-routine you are calling. Otherwise you use a procedure.

SO, you could use something like:

If CompanyHasPlans(strCompanyToDelete) then
AddPlans(strCompanyName, strCompanyToDelete)
End if
DeleteCompany (strCompanyToDelete)

This snippet calls three sub-routines. Two are procedures: AddPlans and DeleteCompany. One is a Function: CompanyHasPlans. All three accept parameters (the names of companies to check or to delete).

jigsaw1975
07-18-2003, 08:09 AM
Maybe I should have used my code. I am getting confused.

Below (1). is where I need to send the value of boolPlans from and (2) should receive that value as I check it and so some processing based on what value I have recd.

(1.)
' --------------------------------------------------------------------
' Name: HasRSPlans
' Purpose: This client script checks to see if a client has any RS Plans attached.

Sub HasRSPlans()

Dim boolPlans '(to see whether plan is attached or not)

'JC 07/17/03 Find out if company has RS Plans attached or not
With rstPrimaryRecordset
If UIMaster.RUICenter.GetRecordset(strsRSPlan).RecordCount > 0 then
Global.CMSMsgBox "Has RS Plans attached", vbOKOnly,"Warning"
boolPlans = 1

Else
Global.CMSMsgBox "No RS Plans attached", vbOKOnly,"Warning"
boolPlans = 0
end if
End With
End Sub

---------------------------------------------------------
(2.)
Sub ConsolidateCompany()
Dim boolPlans

If boolPlans = 0 then
do something
end if

End Sub


This is a simplified version of my code. Please help.

thanks much. really appreciate it.

JordanChris
07-18-2003, 08:15 AM
A even more simplified version

Sub HasRSPlans()
With rstPrimaryRecordset
If UIMaster.RUICenter.GetRecordset(strsRSPlan).RecordCount > 0 then
Global.CMSMsgBox "Has RS Plans attached", vbOKOnly,"Warning"
ConsolidateCompany(strRSPlan)
Else
Global.CMSMsgBox "No RS Plans attached", vbOKOnly,"Warning"
end if
End With
End Sub

Sub ConsolidateCompany(strMyPlan)
MsgBox "Consolidating . . . " & strMyPlan
End Sub

You don't need the boolean, because as soon as you find out whether something has a related plan you call the procedure that will do the consolidation. The parameter you are passing (in this case the strRSPlan) can be whatever you want.

jigsaw1975
07-18-2003, 08:39 AM
This is what my revised code looks like: I am going with boolPlans rather than using strsRSPlan because strsRSPlan actually refers to a segment in the form and I thought passing an integer or boolean value may be better.

however, I got this error:
Microsoft VBScript Runtime error: Wrong number of arguments or invalid property assignment: ConsolidateCompany

BTW I am using VBScript and not exactly VB but since VB solutions usually work for it ,I just posted this in the VB Forum. Is the code supposed to be any different for VBScript?

Another question I had was: I see that usually u pass a value by one name eg strsRSPlan and receive it in another procedure by another name eg strMyPlan (this is using your example). Why do we use different names. Shouldn't we use the same name so the program knows what variable/parameter we are talking about. Is it ok to use the same name : i have used boolPlans when sending and receiving in a procedure.

thank you so so much.
------------------------------------------------------------------
MY CODE
----------------------------------------------------------------

Sub HasRSPlans()

Dim boolPlans '(to see whether plan is attached or not)

With rstPrimaryRecordset
If UIMaster.RUICenter.GetRecordset(strsRSPlan).RecordCount > 0 then
Global.CMSMsgBox "Has RS Plans attached", vbOKOnly,"Warning"
boolPlans = 1
ConsolidateCompany(boolPlans)
Else
Global.CMSMsgBox "No RS Plans attached", vbOKOnly,"Warning"
boolPlans = 0
ConsolidateCompany(boolPlans)
end if
End With
End Sub

---------------------------------------------------------
(2.)
Sub ConsolidateCompany(boolPlans)
MsgBox "If Plans attached is 1 and if not is 0: ..." & boolPlans
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum