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

How to identify a check box inside a container and update using checkbox in foxpro9

Status
Not open for further replies.

Niki_S

Programmer
Jun 4, 2021
232
LK
I have a checkbox inside a container and now I want to update my dbf when I put a tick on my check box. I tried it as below and but the records are not updated.

Code:
Sele A.nSuplID,B.cBatchNo,B.cInvNo,Round(B.nInvValue*B.nConvRate,2) As InvVal,B.nRsRate,B.nConvRate,000000.00 As VatVal,nTax1_ID,nTax2_ID,nTax3_ID,nTax4_ID,nOthercharge,B.cPaymentCurr As Po_InvCurr,B.dCreateDate,B.cFactory,B.dInvDate ;
	From C:\_UnqSupp A,Acp_InvDtl B Where A.nSuplID=B.nSuplID And B.cTag<>"N" And B.dPoDate>=dFrom And B.dPoDate<=dTo And B.cOrderType=cPoTypeTxt And B.cBatchNo Not In(Sele cBatchNo From FinalPym Where dPaymentDate<=_Asatdt) Into Dbf ;
	C:\_PendBch

IF THISFORM.container2.cheRupees.Value=1
SELECT _PendBch
	SCAN
		IF _PendBch.Po_InvCurr<>"LKR" AND _PendBch.Po_InvCurr<>"RS."
			SELECT _PendBch
			REPLACE InvVal WITH InvVal*nRsRate
		ENDIF 
	ENDSCAN
ENDIF

Can anyone please help me to do this?
Thank you
 
Hello,

I think its into TABLE (see help)

What do you want to do , do replaces in a new table or in an existing one ?

Regards
tom
 
If you want to react to a user interactively checking the checkbox, you would do things in InteractiveChange. And then you refer to its value by THIS.VALUE.

Also the value of a checkbox can either be numeric with the values 0,1,or 2 or it is boolean .t., .f., null., When you get an error comparing the value to 1 it's likely just .t. or .f.

When you initialize it as 0 or .f. you stay within the numeric or boolean values.

If your code should run at any other condition and only check the current value of the checkbox the only problem is when you SELECT INTO DBF or TABLE, it will generate a file, but will not be open, so you have to USE the new dbf before working on it.


Chriss
 
Here I have to replace data to an existing dbf.The dbf is _PendBch and I need to update it's InvVal field with InvVal*nRsRate which has same dbf.

Code:
IF THISFORM.container2.cheRupees.Value=1
In here I used '1' to get .T.
When I'm selecting my checkbox on my screen I need to replace values into my existing bdf.
 
As said: If you want a reaction to changing the checkbox you have to write code in in cheRupees.Interactivechange. If your code is in the CheRupees control then why refer to it by THISFORM.container2.cheRupees? Within methods of the checkbox you can refer to it with THIS - like in any other control or object.

And as said: When you create a table by a query INTO DBF (and that does create a table and doesn't update an existing table) you still don't have a workarea open with the table name, wirst step before any replace, locate, scan or other operations on the dbf must be to open it.

Chriss
 
My code is not in the cheRupees Control. I did my code inside a button.
 
Okay, then you only use the checkbox before you press that button?

Then that code will create a new C:\_PendBch.dbf and not open it. You get an error at the line SELECT _PendBch, right?
USE C:\_PendBch.dbf and you can do the rest of the code.

Chriss
 
Yes first I need to use checkbox and after need to press button and do the rest.
When I run my code I didn't get any error in SELECT _PendBch.
As you said I did it like this.
Code:
IF THISFORM.container2.cheRupees.Value=1
USE C:\_PendBch
SELECT _PendBch
GO top
	SCAN
		IF _PendBch.Po_InvCurr<>"LKR" AND _PendBch.Po_InvCurr<>"RS."
			SELECT _PendBch
			REPLACE InvVal WITH InvVal*nRsRate
		ENDIF 
	ENDSCAN
ENDIF

I think now the code is okay. Am I correct?
 
Run it to see. When you USE a dbf without IN0 you just use it in the current workarea, then you don't need to SELEC _PendBch. On the other side you close whatever is in the current workarea.

So a minor change would be:
Code:
IF THISFORM.container2.cheRupees.Value=1
   Select 0
   USE C:\_PendBch
   SCAN && default starts at top, no matter where you are in a workarea
		IF _PendBch.Po_InvCurr<>"LKR" AND _PendBch.Po_InvCurr<>"RS."
			* SELECT _PendBch && it's selected
			REPLACE InvVal WITH InvVal*nRsRate
		ENDIF 
   ENDSCAN
ENDIF

Last thing: you could put the if condition in the SCAN, by using SCAN FOR.
I have no idea whether the replaces are doing what you want, though, assuming it is, you might also replace all that by an UPDATE _PendBch SET InvVal=InvVal*nRsRate WHERE Po_InvCurr<>"LKR" AND Po_InvCurr<>"RS."

Chriss
 
I have to do some changes in my code and my final could is this.
Code:
IF THISFORM.container2.cheRupees.Value=1
	SELECT * FROM C:\_PendBc2 INTO CURSOR InvVal2
	Use In Select('_InvVal2')

	Select InvVal2
	Scan
		TEXT TO stra NOSHOW
		SELECT nBatchInvId,nRsRate from Acp_Invoice_Hdr where nBatchInvId=?InvVal2.nBatchInvId GROUP BY nBatchInvId,nRsRate
		ENDTEXT
		SQLExec(hndOps,stra,'_Tempinv2')
		If Not Used('_InvVal2')
			Select * From  _Tempinv2 Into Cursor _InvVal2 Readwrite
		Else
			Select _InvVal2
			Append From Dbf('_Tempinv2')
		Endif
	ENDSCAN
	
        select 0	
        use _PendBc2
	Go Top
	SCAN 
		Select _InvVal2
		Seek _PendBc2.nBatchInvId
		If _PendBc2.Po_InvCurr<>"LKR" AND _PendBc2.Po_InvCurr<>"RS."
			Select _PendBc2
			Replace InvVal With InvVal*nRsRate
			SELECT _PendBc2
			REPLACE Po_InvCurr WITH 'LKR'
		ENDIF

	ENDSCAN 

ENDIF

Thank you for the helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top