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

How to combine varables in foxpro9 and update a column in table.

Status
Not open for further replies.

Niki_S

Programmer
Jun 4, 2021
232
LK
I have 4 variables in my foxpro and I need to combine them. How can I combine them?
Code:
if {vInvFinal.nInvToFob}=0 then
[b]{Fabric}+{TrimNPD}+{TrimPD}+{ProfCent}+{CAM}[/b]  *** here I need to combine my variables*****
else
IF isnull({vInvFinal.cSggNo}) then
   {vInvFinal.nInvQty}*({vInvFinal.nFOBPrice}/12)
ELSE
   {vInvFinal.nInvQty}*({vInvFinal.nFactFobPrice}/12)

And I have a column named Value and I need to update the column in all steps. How can I do this?
Anyone can please help me to fix this?
Thank you
 
Niki,
To ask how to combine variables is very vague. There are a million answers. It's hard to know what you really want by the code.

Exactly which variables you need to combine?

How do you need to combine them (add/multiply/divide etc.)?

You probably don't need all those parentheses.

If you have VFP, suggest you start by adding 2 ENDIFs at end, remove parens, and run it. Then work on the error messages, try to fix, then check back if you have more questions.

Perhaps Tamar could recommend an information source for you.

Steve
 
Is this whole thing meant to be an expression the result of which gets stored somewhere, or is this meant to be a block of code?

If it's a block of code, in addition to Steve's advice, you need to store the results of those calculations somewhere.

If it's an expression, you need to use IIF() instead of IF.

Finally, by combine, do you mean add or concatenate? That is, are they numeric and you want the sum or are they strings that you want to combine into a single string. In either case, the correct operator is +, but if it's concatenation, you may want to use ALLTRIM() to remove extra blanks, or PADL() or PADR() to make things the lengths you want them to be.

Tamar
 
Wasn't this already answered with thread184-1810760?

Creating a variable, in general, can be done using LOCAL, but you can also create it by assigning a value, which means all you're missing, again, is prefixing this by [tt]varname =[/tt].

Code:
Varname = (vInvFinal.nInvQty)*((vInvFinal.nFOBPrice)/12)

If you get any errors like bracketing errors or type errors, you got to fix the expression. I think VFP doesn't like curly brackets there. If you want to use brackets, then use the normal round brackets, VFP also doesn't mind using square brackets, but they also are usable as string delimiters and commonly also used when addressing an array element, for the array index. So just use the round brackets, if that's the problem.

Chriss
 
Niki,
can you also tell us which mistake you found?
As Steve wrote, there are millions of possibilities.
Maybe you made a mistake that we don't know about yet.
I am always grateful when I know how and why one could make a mistake.
I also suspect that I am not asking this question alone, based on your short answer.
Thank you.

Klaus



Peace worldwide - it starts here...
 
Here I have to add variables. So I did it as below.
Code:
SELECT SGG_grn 
SCAN


	IF (SGG_grn.nInvToFob)=0 
		SELECT SGG_grn
		_TrimNPD =  round((nInvQty)*((nTrimNPD)/12),2)
		_TrimPD = round((nInvQty)*((nTrimPD)/12),2)
		_ProfCent = round((nInvQty)*(((nEmbCost)+(nWshCost)+(nOthOpCost))/12),2)
		_CAM = IIF((cInSub)="SUB", round(((round(((nTotSMV)*12*(nSubAdm))+((nMintAdm)*12),2))/12)*(nInvQty),2), round((round((nTotSMV)*(nBillRate)*12,2)/12)*(nInvQty),2))
        
        
        	If dInvDate<CTOD("05/01/2010")
   				_Fabric = round((nInvQty)*((nFabValD2)/12),2)
			Else
   				_Fabric = round((nInvQty)*((nFabValDoz)/12),2)
			ENDIF
			
		_Value = (_Fabric + _TrimNPD + _TrimPD + _ProfCent + _CAM)
        
	 	replace nValue with _Value
	 ELSE 
	  
		IF isnull(SGG_grn.cSggNo)  
			SELECT SGG_grn	
		 	replace nValue with (SGG_grn.nInvQty)*((SGG_grn.nFOBPrice)/12) 
		ELSE
			SELECT SGG_grn
			replace nValue with (SGG_grn.nInvQty)*((SGG_grn.FactPrice )/12)
		ENDIF 
	ENDIF
		
ENDSCAN

Thank you for your guidance.[smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top