Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
thanks for your answers.
Posted 29-Nov-12 16:49pm
Edited 29-Nov-12 17:45pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

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!
Smile | :)
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 509
1 Nirav Prabtani 338
2 OriginalGriff 215
3 _Amy 165
4 Abhinav S 160
0 OriginalGriff 7,715
1 Sergey Alexandrovich Kryukov 6,911
2 Maciej Los 3,954
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100