borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Broadcast address)Next Topic (login from web page....) New Topic New Poll Post Reply
AndreaVB Forum : VB General : store var in collection or in array
Poster Message
sal21
Level: Graduate

Registered: 13-06-2006
Posts: 9

icon store var in collection or in array

I loop with a for nex cicle a var similar:

for x=0 to 100
my_var="500"
next

now during this loop (the var is filled dinamicly and can assume a value 500,1458,500,478,1458,471 ...ecc)

i want to store in collection or in array, during the for next, only the var not duplicate...

in this case the array or collection contain 500,1458,478,471.

after the for next is finished looping the value in collection or array....
i hope i am be clear

____________________________
Sal

18-04-2009 at 06:39 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 601
icon Re: store var in collection or in array

thy this and tell me if it works for you


    Dim stored_var()
    Dim x As Integer
    Dim j As Integer
    Dim bFound As Boolean
    Dim my_var
    
    ReDim stored_var(0 To 0)
    
    For x = 0 To 100
        my_var = 500
    
        'look to see if value already exists
        bFound = False
        For j = LBound(stored_var) To UBound(stored_var)
            If stored_var(j) = my_var Then
                bFound = True
                Exit For
            End If
        Next
        If Not bFound Then
            'if value is not found inside the array add the new value
            ReDim Preserve stored_var(0 To UBound(stored_var) + 1)
            stored_var(UBound(stored_var)) = my_var
        End If
    Next
    'stored value are found in array from 1 to uBound
    'array with index 0 is empty


____________________________
AndreaVB

21-04-2009 at 12:22 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
sal21
Level: Graduate

Registered: 13-06-2006
Posts: 9
icon Re: store var in collection or in array

quote:
admin wrote:
thy this and tell me if it works for you


    Dim stored_var()
    Dim x As Integer
    Dim j As Integer
    Dim bFound As Boolean
    Dim my_var
    
    ReDim stored_var(0 To 0)
    
    For x = 0 To 100
        my_var = 500
    
        'look to see if value already exists
        bFound = False
        For j = LBound(stored_var) To UBound(stored_var)
            If stored_var(j) = my_var Then
                bFound = True
                Exit For
            End If
        Next
        If Not bFound Then
            'if value is not found inside the array add the new value
            ReDim Preserve stored_var(0 To UBound(stored_var) + 1)
            stored_var(UBound(stored_var)) = my_var
        End If
    Next
    'stored value are found in array from 1 to uBound
    'array with index 0 is empty




hi frined... the code is great!

But in really code i loop ca. 80.000 value!
Id this a very fast metod or a collection is the best?

____________________________
Sal
21-04-2009 at 12:33 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 601
icon Re: store var in collection or in array

I don't think it would be faster using a collection but maybe I'm wrong...      

____________________________
AndreaVB

22-04-2009 at 06:59 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : store var in collection or in array
Previous Topic (Broadcast address)Next Topic (login from web page....) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder