Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi can someone help me with a simple code, i am trying to write a code that says if textbox1 is equal to 0 between 10 then HandDecimal = 1 else if textbox1 is equal to 10.1 through 100 then HandDecimal = 3 else if texbox1 is equal to 100.1 and grater than HandDecimal = 5

here is the code i put, but it does not work for me.
VB
If WeightDecimal = 0 <= 10 Then

        HandDecimal = 1

    ElseIf WeightTextBox.Text = 10 <= 100 Then

        HandDecimal = 3

    ElseIf WeightTextBox.Text >= 100.1 Then

        HandDecimal = 5

    End If
thanks for your answers.
Posted
Updated 29-Nov-12 17:45pm
v2

Don't work with TextBox.Text: this is string, not a numeric value; work with, say, double.Parse(TextBox.Text) or double.TryParse(TextBox.Text):
http://msdn.microsoft.com/en-us/library/system.double.parse.aspx[^],
http://msdn.microsoft.com/en-us/library/system.double.tryparse.aspx[^].

What are you trying to say with your "… = 10 <= 100" is totally unclear. Are you trying to assign, compare to zero or check the order? If you need to check the order (as you say, "between 0 and 10"), it should be:
VB
if 0 <= someValue <= 10 then ...
' depending on what you want, omit one or both '=' from '<=' ...


I don't know what exactly to advise: perhaps, before going on, read on the syntax, look at most basic code samples in some manual…

—SA
 
Share this answer
 
v4
you probebly want to check WeightDecimal's value should be in 0 to 10
then write condition as below...
VB
If WeightDecimal >= 0 and WeightDecimal <= 10 Then

so that code should be like below,...
VB
If WeightDecimal >= 0 and WeightDecimal  <= 10 Then
          HandDecimal = 1
ElseIf Convert.ToDecimal(WeightTextBox.Text) > 10 and Convert.ToDecimal(WeightTextBox.Text) <= 100 Then
          HandDecimal = 3
ElseIf Convert.ToDecimal(WeightTextBox.Text) >= 100.1 Then
          HandDecimal = 5
End If


Happy Coding!
:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900