INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How To Apply ICase

How To Apply ICase

(OP)
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

RE: How To Apply ICase

 
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")

RE: How To Apply ICase

No and no.

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

CODE

.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") 

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.

RE: How To Apply ICase

(OP)
Thanks for the reply,

I am facing an error as shown in image.

Saif

RE: How To Apply ICase

(OP)
I want to apply the condition as shown in image.

Thanks

Saif

RE: How To Apply ICase

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.

RE: How To Apply ICase

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

.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") 

RE: How To Apply ICase

(OP)
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

RE: How To Apply ICase

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

RE: How To Apply ICase

(OP)
Thanks Mr.Mike, a very useful function.

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

Saif

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close