Solved

Dataset Column Expression With Conditional Outputs

Posted on 2004-09-20
7
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

627 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