Alternative To Select Case When Dealing With Object Values?

May 26, 2011

I was able to do this via a SELECT CASE statement, however I'm always trying to improve my code writing and was wondering if there was a better approach. Here's the scenario:Each document has x custom fields on it.There's y number of documentsHowever there's only 21 distinct custom fields, but they can obviously have n different combinations of them depending on the form.So here's what I did, I created an object called CustomFields like so:

Private Class CustomFields
Public agentaddress As String
Public agentattorney As String

[code].....

View 1 Replies


ADVERTISEMENT

.net - Use Time Values In Select Case Statement?

Jul 4, 2011

I want to check the current time with the half an hour time slots (total of 48 starts from 00:00,00:30,01:00,....23:30). Is it possible using select case statement.

I am storing the current time in an object.

Dim datime As DateTime = DateTime.Now.ToString("t")

now i need to do conditional check on this variable. under whichever the time slot the variable belongs, i need to write a value under corresponding timeslot.

View 2 Replies

Switch Statement Select Case On An Object's Type

Aug 19, 2009

[code]How would I switch on an object's type but using VB.NET's Select Case?I'm aware that some might suggest using polymorphism but I'm using a hierarchy of small message classes so that really wouldn't work in my csae.

View 6 Replies

Using Sender As A Case In Select Case Statement?

Mar 21, 2006

When my form loads it adds some handles (using AddHandler) to a sub (showStatus). What this sub does is checks which control activated the sub (using sender.Equals) and displays text in the status label (status) accordingly.For this I use an If...Then statement for each possibility. There are many possibilities and my code get cluttered. Is there a way to do the same thing with a Select...Case statement. I tried: Select Case sender Case tbOne : status.Text = "blahblahblahblahblahblah" End Selectwhere: tbOne is a textbox, status is a StatusLabelIt gives me an error though, saying "Operator '=' is not defined for types 'Object' and 'System.Windows.Forms.TextBox'."Any ideas on how I can get this to work with a select case statement?

View 13 Replies

VS 2008 - Select Case Not Catching The Case

Oct 20, 2009

here is my code..

[Code]....

If the result is 86 and it's mod by 43 the answer is 2 Case 2 is not firing. it just goes to the end of the procedure.

View 4 Replies

Read Upper And Lower Case Letters Without Having To Put The Upper Case Letters In Select Case Statement

Oct 28, 2009

i have a program using a select case to convert letters to special charaters. My question is how can I get the code to read upper and lower case letters without having to put the upper case letters in my select case statement. Example: Part of my code is

[Code]...

View 6 Replies

Asp.net - SQLDataReader: Dealing With Null Values?

Feb 9, 2010

Some tables I am dealing with have null values and are throwing errors. So far ive tried a few solutions to deal with the nulls with no success.Here are the code samples from my efforts so far;

If (r("datemodified").Equals(DBNull.Value)) Then
datemodified = String.Empty
Else[code]....

i have ran the query and it is working ok (i.e all the cols exist)

View 2 Replies

Dealing NULL Values In SQLDataReader

Jan 12, 2012

Dim myreader As SqlDataReader = cmd.ExecuteReader
'read information from the database and give the values to the arguments(column_1, and column_2)
While myreader.Read
column_1 = myreader.GetString(1)
column_2 = myreader.GetString(2)
.....
I get an error when the data returned from myreader.GetString(2) is NULL. How do I check for nulls before assigning column_2 a value?

View 3 Replies

SQLDataReader: Dealing With Null Values?

Jul 8, 2010

Some tables I am dealing with have null values and are throwing errors. So far ive tried a few solutions to deal with the nulls with no success.

Here are the code samples from my efforts so far;
If (r("datemodified").Equals(DBNull.Value)) Then
datemodified = String.Empty

[code].....

View 1 Replies

Properly Dealing With Null Database Values In .net?

Jan 1, 2012

I am looping thorugh a datatable and and printing each row to the console and I keep on getting a dbnull error. I inserted an if statement in my loop to try and catch it, but I can't seem to get it to work.

[Code]...

View 3 Replies

VS 2008 - Class With Attribute / Dealing With DBNull Values

Dec 22, 2010

I wonder, what is the most elegant way of dealing with the dbnull situation. I have a class, with attribute, let's say: "End_Date", which is being read from database. Type of this variant should be date, but as it's the "End_Date", there might be the situation that something haven't ended yet, and in the database in this field I have a null value.

Right now a deal with the problem this way:
Dim mEnd_Date
...
Public Property End_Date ()
Get
End_Date = mEnd_Date
End Get
Set(ByVal value)
mEnd_Date = value
End Set
End Property
But I am not sure if that's a good way as I don't declare variants as any datatype?

View 5 Replies

Using Treeview To Select One From The Other The Code Contains The Case Select?

Oct 31, 2010

ive got a form containing treeview on the left docked, and two panels one over the other (just as for practice), so i am using treeview to select one from the other the code contains the Case select,

If
Not e.Node
Is
Nothing

[code]....

The problem is , both panels are not visible, when i select the first node the firstpanel is visible then i select the second node both panels are not visible, i return to the first node the first panel is visible.

View 2 Replies

Fastest Alternative To Datatable.Select To Narrow Cached Data?

Sep 28, 2009

I have a search function on my company's website (based on .NET 2.0) that allows you to narrow the product catalog using up to 9 different fields. Right now, after you make your selections on the frontend I am building a dynamic query and hitting the database (SQL Server) to get the resulting list of items numbers. I would like to move away from hitting the database everytime and do all of this in memory for faster results. Basically a 3500 - 4500 row "table" with 10 columns: the item number (which could be a primary key) and the 9 attribute fields (which have repeating values for many many rows).

There can be any number of different searches between the 9 columns to get the items you want:
Column A = 'foo' AND Column D = 'bar'
Column B = 'foo' AND Column C = 'bar' AND Column I = 'me'
Column H = 'foo'
etc...

Based on my research, the .Select() function seems like the slowest way to perform the search, but it stands out to me as being the quickest and easiest way to perform the narrowing searches to get the list of item numbers:
MyDataSet.Select("Column B = 'foo' AND Column E = 'bar' AND Column I = 'me'")
In my specific case, what method I use as an alternative that has the same narrowing functionality and better performance instead of settling for the datatable.select() method?

View 2 Replies

AND / OR In A Select Case

Oct 28, 2010

[code]I don't get any error messages, but the DoSomething() line is never executed. I guess this isn't possible.

View 7 Replies

If-Then-Else Vs Select Case ?

Jan 3, 2011

I'm working on a routine that requires a significant amount of nested and daisy-chained logic. Using If-Then-Else, each logic construct would run 8-15 lines of code (quite readable) while using Select Case each construct doubles that (even with significant commentation, it gets less and less readable with each new Case).

I've read many times in this forum how Select Case is leaps and bounds ahead of If-Then-Else in runtime performance, although I can't recall any discussion of the underlying process(es) that make it so. I've also not had any luck finding good, detailed documentation on the nuts and bolts under each logic construct. What I'm working on, if the performance leap is legit, needs the performance more than the readability but if the performance is marginal then the readability is going to get the priority. how and why Select Case is supposed to process so much faster than If-Then-Else. Links to good white paper would be really nice too.

View 1 Replies

Using Select Case In VBA?

Jun 12, 2011

I have a macro that uses "If Then" to choose what macro to run based on the ActiveCell. I would like to use the Select Case method instead. How would I change this code?

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.DisplayAlerts = False
Application.ScreenUpdating = False

[Code].....

View 1 Replies

.net - Turning What If Into Select Case?

Apr 11, 2011

Question is, I basically wrote a Rock Paper Scissors game in VB.NET using If statements and wondered how exactly I would try and work this into a Select Case instead.Professor was pretty awful at teaching things and didn't let us know until today that it had to be Select Case(its due tomorrow

View 2 Replies

Converting An IF THAN ELSE Into A Select Case

Apr 3, 2012

Converting an IF THAN ELSE into a select case

View 4 Replies

Converting The Select Case With To And Is To C#?

Nov 30, 2010

I am convertng vb.net to c# 2010 as my job, and none of the automatic tools I have can succeed completely. In special example, this case:

[Code]...

I am mostly java developer before this, so not great with c# and none with vb.net. I do not understand the "oaaaa to" part and this part is not converting. Can you please point me to right place to find the c# version of this?

View 3 Replies

How To Change To Select Case

Aug 26, 2009

I have an if-elseif-then setup as below:
Private Sub CommandButton1_Click()
If OptionButton1.Value = True Then
getdate
Unload glpmenu
[Code] .....
I would like to change to Select Case.

View 3 Replies

New To Vb Select Case Not Working?

Mar 24, 2011

i think this is the right place to post this.so i am doing my First Vb project and have run into some problems

[Code]...

View 7 Replies

Select Case & Combo Box Value?

Jan 26, 2009

I am using visual basic in VS 2008 and trying to learn how to assign a value to a word in a combo box using case select, this is my first attempt at programing and i just can't work out what to do next. So far i have two combo boxes a label and a button, i want the word, first to = 11, second = 9, third =7, fourth = 5. All it is doing at the moment is adding the list index value and displaying that total in the label. I want it to display for eg: if (first=11) and (second=9) are selected a total of 20 in the label,and so on for what ever combination is selected.

[Code]...

View 4 Replies

Select Case Node Key?

Aug 18, 2009

I have assigned nodes in my treeview keys depending on what they are to do with and now i would like to use a select case to choose the right calculation depending on which node is selected.i have tried selecting the key like this:

Select Case tvwFCOM.Nodes.IndexOfKey(tvwFCOM.SelectedNode.Text)
Case Is = "assi06"
Call MinimumSpeeds()

but option strict on dissalows conversion from string to integer. there are more cases, but i have only shown one here. How can i code so that the key is selected from the selected node?

View 6 Replies

Select Case Not Working?

Jan 27, 2010

I had to change the given code from If Then to Select Case, and this is what I came up with. But when I run the program, it does not work and gives me zeroes instead of the correct information.

Public Class MovieInfo
Private wkndBox, screens As Integer
Private title As String

[Code].....

View 4 Replies

Use Select Case Statement?

Jun 3, 2011

I just replaced a different segment of code with the select case statement and it works fine. However I don't understand what the dim is for after you do "Select case [variable name here]"

I currently just dimmed a value as nothing. I didn't specify any data type for my variable I'm using for this case statement. But it works.[code]...

View 4 Replies

Using Enumeration In Select Case?

Jun 16, 2009

Enum age
Over18
Under18
End enum

[code]....

'age' is a type and cannot be used as an expression.Is there any way of using enums in "select case"?

View 5 Replies

Using TryParse Within Select Case?

Nov 8, 2010

I am in my programming class and we had a small program to make that would check to see if an value that was entered is a integer and convert it to a Roman numeral. I know how to properly do it by putting the TryParse into the If...Then statement. What I am trying to do is to not use an If...Then statement and go just by a Case Selection statement. If it is not possible then that is cool with me, I am just trying to think outside the box. Here is what i have done with it:
[code]....

When you do say "Case 1" it says it needs to be "Case CBool(1)." Using either "Case CBool(1)" or "Case 1 = 1" provides the same result .However the code shows no errors it doesn't do the conversion, it always displays the label's value as "I"

View 3 Replies

VB Select Case Troubleshooting?

May 1, 2009

I have a question regarding a null value which I am not supposed to get in VB. Here is my code.

Public Class SelectDemo
Private Sub lstData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstData.SelectedIndexChanged

[code].....

View 2 Replies

Working With SELECT CASE And MOD

Oct 18, 2009

i need to make a statement that checks the remainder of a number divided by 4.[code]can i get this in SELECT CASE ..MOD format please

View 1 Replies

Get The Error " 'Select Case' Must End With A Matching 'End Select'."

Jun 15, 2011

Select Case currentNodeName
Case "string1","string2","string3","stringEtc"
Case Else

[Code]....

The above is a code snippet... of course I've already made my declarations earlier in the code. My issue is I get the error " 'Select Case' must end with a matching 'End Select'." It looks to me like VB is not liking my If statement with the "Next For" in the middle. I'm sure this is a basic syntax issue.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved