Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need recommendation on weird behavior
Message
De
07/06/2006 19:33:01
 
 
À
07/06/2006 19:00:20
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01127533
Message ID:
01127725
Vues:
9
>It looks weird at first but numeric 1 (System.Decimal) is not equal to integer 1. Silly computers:)
>If you had 1.0,3.0 in your list it would do. I tried to write a generic version of InList in VB < vbg >
>
>
>    Private Function InList(ByVal searchFor As Object, ByVal ParamArray paramList() As Object) As Boolean
>        Try
>            Dim local As Object = Convert.ChangeType(searchFor, paramList(0).GetType())
>            Return (Array.IndexOf(paramList, local) <> -1)
>        Catch ex As Exception
>            MessageBox.Show(ex.Message)
>        End Try
>        Return False
>    End Function
>
>
>This is not "generic" as I wrote yesterday (I mean it is not utilizing System.Collections.Generic with strong type support).
>Second what I don't really like is that it uses ParamArray with object type. Objects might be from different types and no check for that. ie: Consider these calls:
>
>1) If InList(loRow("Type"), 1,3,DateTime.Now,"2.00") Then
>
>2) If InList(loRow("Type"), "1.00",3,DateTime.Now,"2.00") Then
>
>3) If InList(loRow("Type"), DateTime.Now, 1, 3) Then
>
>and let loRow("Type") was decimal 1,2,3 or 5.
>1) 1 and 3 would be in list.
>2) 1 and 2 would be in list
>3) InvalidCastException
>
>IOW first parameter in ParamArray is assumed to be the same for all array elements. It still covers VFP Inlist IMHO (with one exception - it lets you compare a decimal to a string as in case# 2).
>Anyway I couldn't do something more elegant in VB:)

Thanks for the additional information

I think I will keep it as is. To accomodate the situation of yesterday, I will simply convert to the proper type before verification.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform