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 Apply ICase

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

How can I use I case for some conditions of SrCode in grid, like

Code:
With This.parent.parent.ContSrDisp.Grid1
   .Width  = 1146
   .Height = 145
   .Top    = 84
   .Left   = 6 && Adjust Grid position
   .ColumnCount  = 10
   .HeaderHeight = 24
   .ReadOnly = .T.
   .FontName = "Tahoma"
   .RecordSource = "SrDisp"
   .RecordSourceType = 1
   .RowHeight = 24
   .DeleteMark = .F.
   *.setall("dynamicbackcolor", "IIF(RECNO()%2 = 0,RGB(219,125,27), RGB(255,255,255))", "Column")
    .setall("Dynamicbackcolor"=ICASE(SrCode='G30',RGB(255,0,0),SrCode='G10',RGB(0,64,64),SrCode='G23',RGB(255,255,255),RGB(192,192,192)), "Column")
   .Visible = .T.  && Grid control visible
   .ScrollBars = 2
   .column1.header1.Caption = 'ItemCode'
   .column2.header1.Caption = 'BarCode'
   .column3.header1.Caption = 'Item Description'
   .column4.header1.Caption = 'Cartons'
   .column5.header1.Caption = 'Units'
   .column6.header1.Caption = 'Ctn.Rate'
   .column7.header1.Caption = 'Unit.Rate'
   .column9.header1.Caption = 'Value'
   .column8.header1.Caption = 'GrvCode'
   .column10.header1.Caption = 'Description'
   .column1.header1.Alignment = 2
   .column2.header1.Alignment = 2
   .column3.header1.Alignment = 2
   .column4.header1.Alignment = 2
   .column5.header1.Alignment = 2
   .column6.header1.Alignment = 2
   .column7.header1.Alignment = 2
   .column9.header1.Alignment = 2
   .column8.header1.Alignment = 2
   .column10.header1.Alignment = 2
   .column1.Width  = 72
   .column2.Width  = 100
   .column3.Width  = 240
   .column4.Width  = 85
   .column5.Width  = 85
   .column6.Width  = 72
   .column7.Width  = 72
   .column9.Width  = 110
   .column8.Width  = 53
   .column10.Width = 218
   .column4.Format = 'Z'
   .column5.Format = 'Z'
   .column6.Format = 'Z'
   .column7.Format = 'Z'
   .column9.Format = 'Z'
   .column4.InputMask = '999,999.999'
   .column5.InputMask = '999,999.999'
   .column6.InputMask = '9,999.999'
   .column7.InputMask = '9,999.999'
   .column9.InputMask = '999,999.99'
   .column1.ControlSource = "SrDisp.Icode"
   .column2.ControlSource = "SrDisp.BarCode"
   .column3.ControlSource = "SrDisp.full_desc"
   .column4.ControlSource = "SrDisp.QntyMaj"
   .column5.ControlSource = "SrDisp.QntyMin"
   .column6.ControlSource = "SrDisp.RateMaj"
   .column7.ControlSource = "SrDisp.RateMin"
   .column9.ControlSource = "iif(SrDisp.qntymin*SrDisp.ratemin#0,SrDisp.qntymin*SrDisp.ratemin,SrDisp.qntymaj*SrDisp.ratemaj)"
   .column9.ControlSource = "SrDisp.amount"
   .column8.ControlSource = "SrDisp.SrCode"
   .column10.ControlSource = "SrDisp.SrDesc"
Endwith

Thanks

Saif
 
[pre][/pre]Dynamicxxx must be enclosed in parentheses.

.setall("Dynamicbackcolor"="ICASE(SrCode='G30',RGB(255,0,0),SrCode='G10',RGB(0,64,64),SrCode='G23',RGB(255,255,255),RGB(192,192,192))", "Column")
 
No and no.

Common, take a close look at your previous code with IIF:

Code:
.setall("dynamicbackcolor"[highlight #73D216],"[/highlight]IIF(RECNO()%2 = 0,RGB(219,125,27), RGB(255,255,255))[highlight #8AE234]"[/highlight], "Column")
.setall("dynamicbackcolor"[highlight #EF2929]=[/highlight]ICASE(SrCode='G30',RGB(255,0,0),SrCode='G10',RGB(0,64,64),SrCode='G23',RGB(255,255,255),RGB(192,192,192)), "Column")

An assignment = is totally wrong here, you separate the property name you want to set and the value you want to set with comma, not with the assignment operator. The setall function does the assignment, you don't do that within a parameter you pass in.

And the ICASE expression you want to set has to be put in string delimiters. Is it so hard to just do as before, just replacing the IIF with an ICASE?

Bye, Olaf.

 
Thanks for the reply,

I am facing an error as shown in image.

Saif
grerr1_p0pgtl.png
 
I want to apply the condition as shown in image.

Thanks

Saif
grerr2_im80h6.png
 
Of course this causes an error, it is wrong syntax. I marked the wrong places with red and the correct ones in green.

Bye, Olaf.
 
I was too quick with my answer. Replace the = in my answer with a comma.

[pre].setall("Dynamicbackcolor","ICASE(SrCode='G30',RGB(255,0,0),SrCode='G10',RGB(0,64,64),SrCode='G23',RGB(255,255,255),RGB(192,192,192))", "Column")[/pre]
 
Thanks Mr.Olaf/tbleken,

It is working perfectly.
I want to apply the same in report also.
Where should I apply this syntax in report?

Please guide

Saif
 
A small improvement:

Wrap your ICASE() in a function, and call that function from your SetAll().

So, write a function named, say, GenColor:

Code:
FUNCTION GenColor
LPARAM tcSrCode

RETURN ICASE(tcSrCode='G30',RGB(255,0,0),tcSrCode='G10',RGB(0,64,64), ;
  tcSrCode='G23',RGB(255,255,255),RGB(192,192,192))

Then, instead of writing the ICASE() in your SetAll, just call the function:

Code:
.SetAll("DynamicBackColor", "GenColor(SrCode)")

This doesn't change the behaviour, nor is it any better for performance. But it does simplify the code and make it easier to read. It also allows you to call the same logic from different places, and makes it easier to change the colours should the need arise.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mr.Mike, a very useful function.

I will apply it in grid/forms, can I have the same for report?

Saif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top