ElseIf Statement Into A Select Case Statement?

Jun 23, 2010

A co-worker wants to convert the following IfThenElseIf statement into a Select Case statement.
Explain why this is not possible.

If temperature = 100 Then
X = 0
ElseIf population > 1000 Then
X = 1
ElseIf rate < .1 Then
X = -1
End If

View 7 Replies


ADVERTISEMENT

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

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

How To Change IF Statement To Select Case

Dec 17, 2011

I've got the following that has got multiple values of a particular variable and I don't want to stack up to a lot of IF ELSE statements to handle them, so I'd be grateful if some one could very kindly modify the code by using the SELECT CASE statement. Also, I'd like dgMarksEntry.Item(7, i).Value and dgMarksEntry.Item(8, i).Value to handle RANK and COUNT the number of items entered respectively. [Code]

View 2 Replies

Select Case Statement With Beginswith?

Sep 22, 2010

Is there a way to use the Select Case statment in VB.net for beginswith? Or do i have to use a long elseif? Example:

If text.StartsWith("/go") then
elseif test.StartsWith("/stop")
elseif test.StartsWith("/continue")

[Code]....

View 3 Replies

Select Case Statement Won't Work

Jul 13, 2011

I am trying to type in the food Pizza, Taco or Crepe and get a picture of the food to come up along with a message box that gives the country.[code]

View 3 Replies

Select Case Versus If Statement?

Oct 20, 2009

I am not really a fan of if statements. I think they should only be used when comparing different values like this:

Dim status as boolean = false
Dim number as integer = 5
if status.equals(true) then

[Code]....

or msgbox on a different line whatever you want.... What is this rule about that select case should only be used if there more then 2-3 options. Is it wrong to use a select case instead?

View 23 Replies

Set Value To The Combo Box Using Select Case Or If Statement In?

Sep 1, 2010

in combo box string is xxx and yyy and zzz.we have to store the value to each string like xxx=10, yyy=20 and zzz=30. formula is string(xxx)/1.71^(1/2).. if we select xxx formula have to take value 10 or yyy means formula have to take value 20.

View 2 Replies

Use .Contains(string) With A Select Case Statement?

Apr 15, 2010

Is there anyway I can build a Select statement that uses the Contains function? Like this:

Select commentStr
Case commentStr.Contains("10")
Case commentStr.Contains("15")

View 1 Replies

Use A Select Case Statement In A Method Or Sub?

Mar 10, 2009

am using VB.NET 2008 and am a complete beginner. am writing a programme that requires the user to select a number from a NumericUpDown control and the number selected will enable the equivalent number of GroupBoxes on a form following a click event.

[Code]...

think that the argument to be passed to the method or sub will be the Case condition but how do I return the corresponding code to enable the GroupBoxes? I have the same issue with resetting all my textboxes to some default text then the user activates more then one event.

View 6 Replies

Use Combo Box In Select Case Statement?

Nov 21, 2009

I am a noob and I am trying to make a simple resistance calculator for practice. I use text boxes to let the user input the current and voltage, and then a combo box for the units and then a list box to display the results. For some reason no matter which units I select it doesn't convert at all. For example 1/2 will always show up as 0.5 in the list box no matter which units are selected from the combo box. Here is my code.....I know that there is more cases but I only put one to see if it

Public Class Form1
Dim unitsA As String
Dim unitsV As String

[code].....

View 1 Replies

Use Select Case Instead Of If (condition)statement

Mar 23, 2009

My code is:

CODE:

Now i want to know can i use select case instead of if (condition)statement in this code?

View 4 Replies

Writing Select Case Statement?

Oct 17, 2009

I have trouble of writing the select case statement. I am trying to select the first case to change the labels text and if I select the case again then show up the messagebox.

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Select Case test
Case test
Label1.Text = "test"

[code]....

When I selected the button which the labels text have changed and I have selected the button again, but the messagebox doesn't appear on the screen.

View 3 Replies

[2008] Select Case Statement?

Dec 10, 2007

what is the propert way to use Case statement for;When user click on a button it will show different picture everytime.I do not want a random generator. Just show pictures in order

View 10 Replies

.net - NullReferenceException Thrown On A Select Case Statement?

Sep 6, 2011

This error occurs occasionally in Production but I can't reproduce it in DEV

System.NullReferenceException: Object reference not set to an instance of an object.
at CommandCenterHeader.ascx.vb:line 23
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()

[Code]...

View 3 Replies

.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

Can't Get Select Case Statement To Work Properly

Aug 19, 2009

I'm working through a programming project, which should be quite easy but im stuck right at the start (relatively new to VB). I have a textbox (named textbox1) and a checkbox next to it. I want the checkbox to be ticked (.checked) when ever the value in the textbox is between 1 and 100, the checkbox to not be ticked when theres nothing in there, and for it not to be ticked when the value is < 1 and > 100. Figured a case statement would be the easiest. (this piece of code is just a validation check, basically in the real thing the user would have to enter in a value between 1 and a given number, and need to tell the user if that value is valid).

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Select Case TextBox1.Text
Case Is = ""

[code]....

But what happens is, if I enter in the value 1 in the textbox, the checkbox becomes ticked, as it should. It tick with any values between 2 and 99 (any number not starting with 1) but the checkbox becomes ticked again when the value is 100. For any other range, say 1 to 70, the checkbox would be ticked if the value in the textbox is 1 to 7, or any number starting with 1 or 7, but not 8 or 9, or any number starting with 8 or 9.

View 3 Replies

Creating Array From Select Case Statement?

Jan 10, 2012

Is there a way to pass data from a Select Case statement to an array? i.e. I have a gradebook program I'm working on which specifies that I'm to create a form with a menu that will open another form which has textboxes for 5 student names and 5 grades for each. I need to use an array that holds 5 student names (done), an array of 5 strings to hold each students' letter grade (?) and 5 arrays of 5 numbers to hold each student's set of test scores (done). What I can't figure out is how to get th

Public Class StudentData
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

[code]......

View 8 Replies

Put It Into A Select Case Statement That Will Let Me Display The Results?

Oct 13, 2009

i have a table with information on how much tax a company has to pay, and i need to put it into a select case statement that will let me display the results, but i have no idea how to do that.
this is the table:

Sales Income OverBut Not OverCompany Tax IsOf the Amount Over
$0 $50,000 1% $0
$50,000 $150,000 $500 + 2% $50,000
$150,000 $300,000 $3,000 + 3% $150,000
$300,000 $500,000 $9,000 + 4% $300,000
$500,000 - $20,000 + 5% $500,000

how do i display this? i have no clue where to start..

View 5 Replies

Select Case Statement With Constant Variables

Nov 18, 2009

While measuring the select case performance I encounter a strange behavior of Select Case statement with the constant expression. I don't understand why its behavior is dependent on the values to be compared.

[Code]...

View 3 Replies

Use The IF ELSE Statements OR The Select Case Statement To Write?

Oct 7, 2011

Im trying to figure how to use the IF, ELSE statements OR the Select Case statement to write this program.I'm using Visual Studio 2010. The program is suppose to allow the user to input their weight in a text box and from group box 1 the select whether theyre male or female using the radios and they select inactive or active from group box two and the calculate but will determine how many calories they should intake based on the criteria below.

[Code]...

View 14 Replies

[2005] Unable To Select Case Statement

Jan 14, 2009

I have problem with select case statement. When I click the button, nothing have happens.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim google As String
Select Case google
Case 0

[code]....

View 39 Replies

.net - Switch/Select Statement Jump To A Different Case Clause?

Oct 18, 2011

Say I have this in VB.NET:

Dim executeB As Boolean
Select Case myVariable
Case "a"
'some code
Case "b"
'some code
Case Else
End Select

If myVariable is "a", control will go into the first case statement. Now let's say if myVariable = "a", but inside a's case block, I find that executeB is true, is it then possible to jump to the second case?

View 5 Replies

Select Case Statement Based On Data Type

Oct 20, 2009

I want to be able to have a case for each data system data type. Obviousely the code below doesnt work but it should make it easier to understand my question.

[Code]...

View 4 Replies

Select Case Statement Using The First (left) Characters In A String?

Feb 21, 2011

I have a lot of really long strings that I want to test. Is it possible to use the CASE statement and compare it to the first 25 characters of the string to get a match?

View 14 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

Use A Select Case Statement That Evaluates PostDiscountCost Based On The Value 0 To 999.99?

Oct 1, 2011

I need to use a select case statement that evaluates PostDiscountCost based on the value 0 to 999.99, 1000.00 to 1499.99, 1500.00 to 2499.99 and one that doesn't fall within the others. The message box's going to be triggered by the vbYes in the confirm exit message box. Im not asking anyone to do it for me, I just have no idea where to start it, if I need to declare anything else and if I'm on the right track. Code Attached.

View 1 Replies

User To Input Created Select Case Statement?

Apr 18, 2012

I just started in VB, I have created select...case statement to do some input validation.

Everything apart from the works. Its an extended ASCII character, can this be the cause?

[Code]...

View 1 Replies

VS 2008 Select Case Statement For A 2 Dimensional Array?

Aug 20, 2011

I'm in the middle of making a battleship game, and I'm trying to get picture boxes .visible=True based on the coordinates (that have already been given a nice Try/Catch/Finally error handeling block) of the ships. Example: I have picture boxes in a grid formation that are all red, and my naming convention for them is picR00 for the coordinates (0,0), picR01 for the coordinates (0,1)... et al. Because I'm using a(10,10) for my boolean array, I want the stuff thats false (not marked), those coordinates' red picture box to become visible, and the true have the green ones become visible. Here is what i have so far:

Dim a(10, 10) As Boolean, b(10, 10) As Boolean, c As Integer, x As Integer, y As Integer, ox As Integer, oy As Integer
For c = 1 To 3

[Code].....

View 12 Replies

Create A Select Case Statement To Assign The Per Check Processing Fee?

Apr 8, 2011

I need to create a Select Case statement to assign the per check processing fee:user inputs number of cks into textbox that i need to validate the input if user puts in a negative amount.

10 cents for <=20 cks written ea month
8 cents <= 20 to 39 cks written ea mo
6 cents <= 40 to 59 cks written ea mo
4 cents for 60 or more cks written ea mo.

Also, I have a label programmed to display the $10 monthly fee thats has to be included into the: Total monthly fees.
Here's the coding I have so far:

Const decSERVICE_FEE As Decimal = 10D
Const decTWENTY_OR_LESS_CHECKS As Decimal = 0.1D
Const decTWENTY_THRU_THIRTYNINE_CHECKS As Decimal = 0.08D

[code].....

View 5 Replies







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