Solved

Dataset Column Expression With Conditional Outputs

Posted on 2004-09-20
7
442 Views
Last Modified: 2010-08-05
Hi,

How do you set a column expression to assign a large number of string values that are determined by an existing column value?

I have numbers ranging from 0 to 30 say in my existing [New Score] column. I wan't my column expression on my [Level] column to show the following:

New Score                 Level

1-3                              A
3-6                              B
6-9                              C
etc                              etc
24-27                           I
27-30                           J

I have used an IIF statement before to handle just two classifications "High" and "Low" levels, but cannot get VB.NET to extend to the multiple-argument. The line below works fine for two [Level] values only.

ds.Tables(2).Columns("Level").Expression = "IIF([New Score] < 15, 'Low', 'High')"

How do I get more than a true/false conditional expression?

Thanks,
Nathan.
0
Comment
Question by:nathanpz
  • 5
  • 2
7 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12109705
Well you could nest your iif, like

Dim s As Integer = 12
       ds.Tables(2).Columns("Level").Expression = "IIF([New Score] < 4, "A",IIF([New Score] < 7,"B", IIF([New Score] < 10,"C", etc... )"
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12109734
or you could use the switch function, something like

dim s as integer = 9
MsgBox(Microsoft.VisualBasic.Switch(s < 4, "A", s < 6, "B", s < 10, "C"))
0
 

Author Comment

by:nathanpz
ID: 12119083
Hi RonaldBiemans,

I don't think the IIF statement can be nested in VB.NET. It says I am using too many arguments if I have more than IIF(argument,val_true,val_false).

Also, the Switch function wont allow me to use the [New Score] column values. I can't easily code the switch function to alter each [Level] column entry because the [Level] column is readonly and part of a dataset so it needs to use the Dataset.DataColumn.Expression command. Do you know how this could be coded?

Any ideas how to alter on of the above functions to work with my dataset column?

Thanks,
Nathan.

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12120526
I'll have a look, but I'm pretty sure the iif can be nested.
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
ID: 12120602
Hi nathanpz, I tested it and it works

ds.Tables(0).Columns("scores").Expression = "IIF([tata] < 4, 'A',IIF([tata] < 7,'B', IIF([tata] < 10,'C', IIF([tata] < 15,'D','E'))))"
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12120606
Could you post your expression maybe you made a small type error.
0
 

Author Comment

by:nathanpz
ID: 12128782
Thanks for persevering RonaldBiemans,

I wasn't being careful enough with the number of arguments in the nested IIF statement.

The points are yours.

Thanks again.
Nathan.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question