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!

Adding Issue 1

Status
Not open for further replies.

pineisland99

Instructor
Feb 13, 2007
22
0
0
US
Hello All....

Please excuse if not in correct section.

Below is a macro I wrote which adds 1 point to my variable(strNewRate) when certain conditions are met.

This macro runs when 'save' is clicked on the application.
It is written in a macro editor that is part of the app.

The macro works - The problem is that I need my if then statement to run only once if my conditions are met.
As it is now, it will run again, and again, upon each click of the save button, and creates erroneous information.


How can I get my macro to either run once, or what change can I do to get an add-on to be added only once.

Thank You

'Adds 1 point to rate for No Cost loans
dim strNCost as string
dim strProg as string
dim strfix as string
dim strArm as string
dim strNewRate as single
strNcost = GetLoanData(10155)
strfix=GetLoanData(402)
strArm=GetLoanData(292)
strProg=GetLoanData(7074)
If strProg = "CFIX" and strNCost = "Yes" then
strNewRate=(Val(strFix) + 1)
SetLoanData 402, CStr(strNewRate)
end if
If strProg = "CARM" and strNCost = "Yes" then
strNewRate = (Val(strARM) + 1)
SetLoanData 292, CStr(strNewRate)
end if
 
You increase your strNewRate in 2 places:
Code:
If strProg = "CFIX" and strNCost = "Yes" then 
[b]strNewRate=(Val(strFix) + 1)[/b] 
SetLoanData 402, CStr(strNewRate) 
end if
and here
Code:
If strProg = "CARM" and strNCost = "Yes" then 
[b]strNewRate = (Val(strARM) + 1) [/b]
SetLoanData 292, CStr(strNewRate) 
end if
but let's say you want only first piece of code run once.
Code:
[blue]Static blnWhatever As Boolean[/blue]
dim strNCost as string 
dim strProg as string 
dim strfix as string 
dim strArm as string 
dim strNewRate as single 
strNcost = GetLoanData(10155) 
strfix=GetLoanData(402) 
strArm=GetLoanData(292) 
strProg=GetLoanData(7074) 

If strProg = "CFIX" and strNCost = "Yes" then 
  [blue]If blnWhatever = False Then[/blue]
    strNewRate=(Val(strFix) + 1) 
    SetLoanData 402, CStr(strNewRate) 
    [blue]blnWhatever = True
  End If [/blue]
End If

If strProg = "CARM" and strNCost = "Yes" then 
strNewRate = (Val(strARM) + 1) 
SetLoanData 292, CStr(strNewRate) 
end if


Have fun.

---- Andy
 
Thank you. I used a similar solution to yours, where I looked at a field to verify that it was not equal to "Y" before the if-then run, then set it to "Y" once the run was complete:

dim strNCost as string
dim strProg as string
dim strfix as string
dim strArm as string
dim strNewRate as single
dim strNCValueHolder as string
dim strinitialarmrate as string
strNcost = GetLoanData(10155)
strfix=GetLoanData(402)
strArm=GetLoanData(292)
strProg=GetLoanData(7074)
strNCValueHolder = GetLoanData(10156)
strinitialarmrate = Getloandata(277)

If strProg = "CFIX" and strNCost = "Yes" and strNCValueHolder <> "Y" then
strNewRate=(Val(strFix) + 1)
SetLoanData 402, CStr(strNewRate)
SetLoanData 10156, "Y"
end if
If strProg = "CARM" and strNCost = "Yes" and strNCValueHolder <> "Y" then
strNewRate = (Val(strARM) + 1)
SetLoanData 292, CStr(strNewRate)
SetLoanData 10156, "Y"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top