12,697,801 members (25,837 online)
Rate this:
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.
```    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
```
Posted 29-Nov-12 17:49pm
Updated 29-Nov-12 18:45pm
v2

Rate this:

## Solution 1

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:
```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
v4
Rate this:

## Solution 2

you probebly want to check WeightDecimal's value should be in 0 to 10
then write condition as below...
`If WeightDecimal >= 0 and WeightDecimal <= 10 Then`

so that code should be like below,...
```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!
:)
v2

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

Top Experts
Last 24hrsThis month
 ppolymorphe 170 Asgard25 130 OriginalGriff 115 Richard MacCutchan 99 Dave Kreskowiak 70
 OriginalGriff 3,751 Peter Leow 2,268 ppolymorphe 1,757 Mika Wendelius 1,753 Jochen Arndt 1,479

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 13 Feb 2013