locked
not equal RRS feed

  • Question

  • HI All.

    In VB2010 I would like to say value not equal Max (value <> Max) but that line doesn't work. Why and how to say in correct way?

    Thanks.

    Wednesday, August 8, 2012 2:18 PM

Answers

  • Even if the "value" variable is an Object, you can't use it directly :

    Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As System.Globalization.CultureInfo) As System.Windows.Controls.ValidationResult
    
    if value.ToString.Length = 0 then
                    Return New ValidationResult(False, "Data is required.")
    endif
    
    Dim numvalue as integer
    If Int32.Tryparse(value,numvalue) = false then
                    Return New ValidationResult(False, "Not a numeric value.")
    endif
    
    if numvalue <> Max then
                    Return New ValidationResult(False, "Length field is invalid")
    endif
    
    if value < Min OrElse value > Max then
                    Return New ValidationResult(False, "Length field is invalid")
    endif
    
    Return New ValidationResult(True, "")
    
    End Function
    

    • Marked as answer by Sheldon _Xiao Friday, August 17, 2012 7:18 AM
    Wednesday, August 8, 2012 3:15 PM

All replies

  • value != Max

     

    Regards,
    Pete


    #PEJL

    Wednesday, August 8, 2012 2:25 PM
  • Hello,

    Please let us know what doesn't work. The "not equal" sign is  "<>", so it should work, if "value" and "max" can be compared.

    Wednesday, August 8, 2012 2:28 PM
  • Hi Pete. Thnaks for replay.

    That is OK for C# not for VB.

    Thanks.

    Wednesday, August 8, 2012 2:28 PM
  • Hi Sygrien.

    I used for validation If say = or < or > I see according validation reaction. If I say <> in that case nothing validated.

    Thanks.

    Wednesday, August 8, 2012 2:32 PM
  • What is the type of the "value" variable ?

    What is the type of the "max" variable ?

    Is there an error at runtime ? Do you have the option "Strict" on ?
    • Edited by Sygrien Wednesday, August 8, 2012 2:35 PM
    Wednesday, August 8, 2012 2:34 PM
  • My Overrides function:
    Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As System.Globalization.CultureInfo) As System.Windows.Controls.ValidationResult
            Select Case True
                Case value = 0
                    Return New ValidationResult(False, "Data is required.")
                Case Not IsNumeric(value)
                    Return New ValidationResult(False, "Not a numeric value.")
                Case (value <> Max)
                    Return New ValidationResult(False, "Length field is invalid")
                Case (value < Min) OrElse (value > Max)
                    Return New ValidationResult(False, "Length field is invalid")
                Case Else
                    Return New ValidationResult(True, "")
            End Select
    End Function

    Wednesday, August 8, 2012 2:51 PM
  • Even if the "value" variable is an Object, you can't use it directly :

    Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As System.Globalization.CultureInfo) As System.Windows.Controls.ValidationResult
    
    if value.ToString.Length = 0 then
                    Return New ValidationResult(False, "Data is required.")
    endif
    
    Dim numvalue as integer
    If Int32.Tryparse(value,numvalue) = false then
                    Return New ValidationResult(False, "Not a numeric value.")
    endif
    
    if numvalue <> Max then
                    Return New ValidationResult(False, "Length field is invalid")
    endif
    
    if value < Min OrElse value > Max then
                    Return New ValidationResult(False, "Length field is invalid")
    endif
    
    Return New ValidationResult(True, "")
    
    End Function
    

    • Marked as answer by Sheldon _Xiao Friday, August 17, 2012 7:18 AM
    Wednesday, August 8, 2012 3:15 PM
  • Hi eugzl,

    You can use like this

    If Not value = Max Then

    Happy Coding!!!


    • Edited by Srithar Thursday, August 9, 2012 5:22 AM
    Thursday, August 9, 2012 5:22 AM
  • Hi eugzl,
     
    I am marking your issue as "Answered", if you have new findings about your issue, please let me know.


    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 17, 2012 7:18 AM