Non-AppFrame Question


Author
Message
Ben Kim
Ben Kim
StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)
Group: Forum Members
Posts: 99, Visits: 253
Also, since I am new to VB.NET and coming from Clarion, is there a way to check a single field for specific values instead of a long IF statement or Select...Case?

Example in Clarion:

IF INLIST(MyField, "Male", "Female", "Both")
    MESSAGE("Valid")
ELSE
    MESSAGE("INVALID")
END

In Clarion I could test for multiple values with a single statement as shown above (I believe up to 25 values at a time).  Is there a similar statement in VB.NET?  Currently I have code like:

IF MyField <> "Male" AND MyField <> "Female" AND MyField <> "Both"
...
END

Thank you for any ideas!

Ben

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Ben,



Did you know there was a general .NET forum here? Click on the home link (under your name above the Add Post, Reply buttons) and down at the bottom you'll see a .NET forum. Its just for this sort of thing. The SF developers don't care much were you post it, as they get emails for new posts (based on what Ben Chase has said), but for us normal uses, it helps Hehe



I'm really curious to know if this can happen in VB.NET, BTW BigGrin
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
There is not an INLIST method in VB.NET.  Generally when I have a situation like this, I would not use a String field.  This would be a integer field then I would create an Enum for each of the values.  You can then do a bitwise test depending upon how you create the enum. 
Ben Kim
Ben Kim
StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)
Group: Forum Members
Posts: 99, Visits: 253
Thanks Trent.  Unfortunately we have to support a legacy database that cannot be changed.

Ben

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
No fun.  You could easily create this type of functionality by creating a shared class and a collection.

Public Sub NotInheritable MyCommonTools
    Public Shared Function InList(ByVal TestValue as String, ParamArray TestItems() As String) As Boolean
       '-- Cycle through and test the values here and return out
    End Sub
End Sub

Ben Kim
Ben Kim
StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)
Group: Forum Members
Posts: 99, Visits: 253
Trent,

Thank you for your help.  I implemented the function in a common "module.vb" file and it works like a treat.  Here is the code if anyone else wants to implement the feature:

Module CommonTools

Public Function InList(ByVal TestValue As String, ByVal ParamArray TestItems() As String) As Boolean

Dim lLoop As Integer

Dim lResult As Boolean

lResult = False

For lLoop = LBound(TestItems) To UBound(TestItems)

If TestValue.Trim = TestItems(lLoop).Trim Then

lResult = True

Exit For

End If

Next

Return lResult

End Function

End Module

Here is an example on how to use the InList function:


If Not InList(Me.EventType, "FULL", "ACCD", "CIT", "PARK", "FI") Then
    Me.AddBrokenRule(IncdTypeBOFieldNames.PathOf, "Please choose a event type.")
End If

Thanks again!

Ben


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
It looks great.  The only suggestion I would make would be to replace the LBound and UBound functions as these are left in at the moment for backward compatability.  The array has all of this information already within it. 

For Each lcItem In TestItems
Next

or

For lnIndex = 0 To TestItems.Length-1
Next

Otherwise I think it looks great!

 


Steve L. Taylor
Steve L. Taylor
StrataFrame Developer (68 reputation)
Group: StrataFrame Developers
Posts: 40, Visits: 91
Ben another version:


''' <summary>
''' Accepts an expression and a list of values.
''' <example>
''' Inlist("FULL", "FULL", "ACCD", "CIT", "PARK", "FI") ' Returns true
''' InList(456, 23, 456, 44, 357) ' Returns true
''' </example>
''' </summary>
''' <param name="Expression"></param>
''' <param name="Items"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function InList(ByVal Expression As Object, ByVal ParamArray Items() As Object) As Boolean
     Return Array.IndexOf(Items, Expression) > -1
End Function

Ben Kim
Ben Kim
StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)
Group: Forum Members
Posts: 99, Visits: 253
Would I just Dim lcItem per your example as follows?

Dim lcItem As String

Sorry for the newbie questions!

Ben

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Yes.  You can also do it inline.

For Each lcItem As String IN TestItems
Next

Either case will work.  Steve's example is also a very good idea as well if you don't need to do any internal processing.  The only problem with using the IndexOf may be case-sensitivity.  Otherwise it is definitely the quickest route.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search