none
what type of variable can you store multiple (up to 15) boolean values under? RRS feed

  • Question

  • I have a project that I would like to store multiple boolean values (up to 15) with each change of a numericupdown (1-10)

    Thus I would like it to be possible to do something like this:

    Example only

    Dim AVal As Boolean

    BVal As Boolean

    (up to 15 dimentions)

    Type(1) = (AVal, BVal,EVal,OVal)

    Type(2) = (CVal, FVal, JVal, LVal)

    Do you get the idea?

    Monday, February 18, 2019 2:49 AM

All replies

  • Hi,

    I think you can use function,If the function has four parameters:

    Public Function Tval(ByVal a As Boolean, ByVal b As Boolean, ByVal c As Boolean, ByVal d As Boolean) As Boolean .....

    Return False End Function

    Method body you can write by yourself,return value you can also set your own.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 18, 2019 6:00 AM
  •  If all you need to do is store boolean values and you have some method to know what order they are in when you need to retrieve them for something,  then just use a List(Of Boolean) or an Array of Boolean.  A List is better if you need to add/remove some of the boolean values to/from the List at a later point in your app.

            Dim Type1 As List(Of Boolean) = {AVal, BVal, EVal, OVal}.ToList
            Dim Type2 As List(Of Boolean) = {CVal, FVal, JVal, LVal}.ToList
    
            'Or...
    
            Dim Type1() As Boolean = {AVal, BVal, EVal, OVal}
            Dim Type2() As Boolean = {CVal, FVal, JVal, LVal}
    
     

     However,  if you need to have some way of knowing which boolean value is for what when you need to retrieve them,  I would create a small Class that has Properties for each value.  For a simple example...

    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim Type1 As New MyDataClass(AVal, BVal, EVal, CVal)
    
            'Or...
    
            Dim Type1 As New MyDataClass With {.A = AVal, .B = BVal, .C = CVal, .D = DVal}
    
            'Or...
    
            Dim Type1 As New MyDataClass
            Type1.A = AVal
            Type1.B = BVal
            Type1.C = CVal
            Type1.D = DVal
        End Sub
    
    End Class
    
    Public Class MyDataClass
        Public Property A As Boolean
        Public Property B As Boolean
        Public Property C As Boolean
        Public Property D As Boolean
    
        Public Sub New()
        End Sub
    
        Public Sub New(av As Boolean, bv As Boolean, cv As Boolean, dv As Boolean)
            A = av
            B = bv
            C = cv
            D = dv
        End Sub
    End Class

     

     It has a lot to do with how you are using the "Type1" and "Type2"  variables throughout your program that would determine which way would be easier and/or better.


    If you say it can`t be done then i`ll try it

    Monday, February 18, 2019 6:55 PM
  • I have a project that I would like to store multiple boolean values (up to 15) with each change of a numericupdown (1-10)

    Thus I would like it to be possible to do something like this:

    Example only

    Dim AVal As Boolean

    BVal As Boolean

    (up to 15 dimentions)

    Type(1) = (AVal, BVal,EVal,OVal)

    Type(2) = (CVal, FVal, JVal, LVal)

    Do you get the idea?

    My $0.02

        ''' <summary>
        ''' returns a list of Boolean
        ''' </summary>
        ''' <param name="SomeBools"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Function MultipleBooleans(ParamArray SomeBools() As Boolean) As List(Of Boolean)
            Dim rv As New List(Of Boolean)
            rv = SomeBools.ToList
            Return rv
        End Function
    
        '
        ' TO TEST
        '
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim test As List(Of Boolean)
            test = MultipleBooleans(True, False, True, True, True)
            Stop 'look at test
            test = MultipleBooleans(True, False, False, True, True, False, False, True, True, False, True, True, True)
            Stop 'look at test
        End Sub
    


    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Monday, February 18, 2019 8:15 PM