• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

Question rephrased II - ActiveX controls limitations

Could somebody kindly provide some B-Tree Algor. and source code which is used for searching a particular component in an array? Homepages are as good as this..
Thanks a trillion times
Jack

==========================================================

There seems to be a limitation on how many homogeneous activex controls that can be living in one standard VB application. For more details, go to home.netvigator.com/~luckie/download.html
it is very slow when the no of controls incremented to 100 or so, please help me out. Thanks
Jack
0
luckie
Asked:
luckie
  • 27
  • 5
  • 2
  • +1
1 Solution
 
tetrodeCommented:
Why would you write your own B-Tree algorithm? You're better of using a collection or database.

Homework?

0
 
mlmccCommented:
listening
0
 
luckieAuthor Commented:
Not H.W... just some business matters.. What I'm trying to do is to search a component in an 123-sized array. I found that if i used sequential search everytime from the first element over (plus some timer loops) . It was terribly sluggish... What I'm looking for just an improvement for speed... Thanks
Jack
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
luckieAuthor Commented:
Here we go:

Public Sub pick_pigeonhole()
   Dim pickcount As Integer
   For pickcount = 1 To 123
      If (GoodsFlags(pickcount) = True) Then
          GoTo nextloc
      Else
          GoodsFlags(pickcount) = True
          Exit Sub
      End If
nextloc:
   Next pickcount
   
End Sub

Private Sub PutStk_Timer()
    If (VnaPutStkInc > 9) Then
        VnaPutStkInc = 1
    End If
    set_vna_images VnaPutStkInc
    PutStkVna.Left = PutStkVna.Left - 1
    pick_pigeonhole
    refresh_stk
   
    VnaPutStkInc = VnaPutStkInc + 1
End Sub

forget about the syntax... Even I don't understand it :)

0
 
deightonprogCommented:
try this, assumes your array is sorted into ascending order, performance will improve depending on the size of the array

Option Explicit

Private Sub Form_Load()

    Dim l(10) As Long
   
    l(1) = 5
    l(2) = 17
    l(3) = 23
    l(4) = 25
    l(5) = 29
    l(6) = 41
    l(7) = 42
    l(8) = 99
    l(9) = 102
    l(10) = 147
   
    MsgBox BinarySearch(l, 147)
   
   
   

End Sub

Public Function BinarySearch(vOrderedArray, vKey) As Long
    'searches an array sorted into increasing order
    Dim lTop As Long
    Dim lBot As Long
    Dim bFound As Boolean
    Dim lMid As Long

    lTop = UBound(vOrderedArray)
    lBot = LBound(vOrderedArray)
   
    If vOrderedArray(lBot) = vKey Then
       
        BinarySearch = lBot
        Exit Function
       
    End If
   
    If vOrderedArray(lTop) = vKey Then
       
        BinarySearch = lTop
        Exit Function
       
    End If

   
    Do Until bFound Or lTop - lBot <= 1
        lMid = (lTop + lBot) \ 2
        If vOrderedArray(lMid) = vKey Then
            bFound = True
        ElseIf vOrderedArray(lMid) > vKey Then
            lTop = lMid
        Else
            lBot = lMid
        End If
    Loop
       
    If bFound Then BinarySearch = lMid Else BinarySearch = -1

End Function

0
 
luckieAuthor Commented:
I want to get the closest no to 1 that is true...
Thanks
0
 
deightonprogCommented:
do you mean that if the array has say,

5,6,10,11 in it, and you are searching for '7' then it will return the array element that has '6' in it, as the nearest match?
0
 
deightonprogCommented:
ok, how about this

Option Explicit

Private Sub Form_Load()

   Dim l(10) As Long
   
   l(0) = 2
   l(1) = 5
   l(2) = 17
   l(3) = 23
   l(4) = 25
   l(5) = 29
   l(6) = 41
   l(7) = 42
   l(8) = 99
   l(9) = 102
   l(10) = 147
   
   MsgBox BinarySearch(l, 92)
   
   
   

End Sub

Public Function BinarySearch(vOrderedArray, vKey) As Long
   'searches an array sorted into increasing order
   Dim lTop As Long
   Dim lBot As Long
   Dim bFound As Boolean
   Dim lMid As Long

   lTop = UBound(vOrderedArray)
   lBot = LBound(vOrderedArray)
   
   If vOrderedArray(lBot) = vKey Then
       
       BinarySearch = lBot
       Exit Function
       
   End If
   
   If vOrderedArray(lTop) = vKey Then
       
       BinarySearch = lTop
       Exit Function
       
   End If

   
   Do Until bFound Or lTop - lBot <= 1
       lMid = (lTop + lBot) \ 2
       If vOrderedArray(lMid) = vKey Then
           bFound = True
       ElseIf vOrderedArray(lMid) > vKey Then
           lTop = lMid
       Else
           lBot = lMid
       End If
   Loop
       
   If bFound Then
        BinarySearch = lMid
   Else
        BinarySearch = lBot
        If vOrderedArray(lTop) - vKey < vKey - vOrderedArray(lBot) Then
            BinarySearch = lTop
        End If
   End If

End Function
0
 
luckieAuthor Commented:
Okay...
If I have an array like this
1
True

2
True

3
True

4
True

5
False

6
True

So I need to obtain '5' from your function
0
 
luckieAuthor Commented:
So the problem is when the array is big (like 123),and if i have to search everytime from the start, it will create a burden on the computer and running very slowly...
Hope you understand
Thanks
Jack
0
 
deightonprogCommented:
Unless you can explain some sort of 'order' to your array, there woulddn't seem to be any better way of searchin for the false value then reading through the array.

Instead maintain a  dictionary object of 'false values' then remove them when they become true, the false value you need will then be the first dictionary item.  Interested?  I could show you some code if you like.
0
 
tetrodeCommented:
came across a b-tree code sample, don't know what it is worth...


http://www.vb2themax.com/Item.asp?PageID=CodeBank&Cat=100&ID=303

have fun,

Mark
0
 
luckieAuthor Commented:
Yes, please.
0
 
deightonprogCommented:
example using dictionaries

you nead to add a reference to 'microsoft scripting runtime'
0
 
luckieAuthor Commented:
Dictionaries... oh fine... will come back ASAP
0
 
luckieAuthor Commented:
Just one extra q... as I couldn't find it in MSDN opening page ..., how do I install examples in MSDN?
0
 
luckieAuthor Commented:
Just one extra q... as I couldn't find it in MSDN opening page ..., how do I install examples in MSDN?
0
 
luckieAuthor Commented:
I think I got a brain problem.
I finally end up with a searching loop from the starting element even though I used Dictionary
I meant when I initialize the array this way
1  2  3  4
I remove 1 if I find it there and add it when it doesn't exist...

I end up with this

For i = 1 to 123
  if d.exists(i) then
     d.add i
  end if
next i

so the loop also makes a great burden on the machine. Any comments?
Thanks
Jack
0
 
luckieAuthor Commented:
should be
if Not d.exists(i)

and I can use gethead :) to get the first empty pigeonhole!
Thanks
Jack
0
 
luckieAuthor Commented:
Would it be faster than straight searching?
Thanks
Jack
0
 
luckieAuthor Commented:
my brain hurts :(
0
 
luckieAuthor Commented:
If I put the loop in a timer... you know the rest...
Thanks
Jack
0
 
luckieAuthor Commented:
Still a performance degrade when searching for large numbers (for example 120-123) in an 123 array
Thanks
Jack
0
 
luckieAuthor Commented:
This is really tedious, if I maintain an array of unoccupied pigeonhole, I have to shuffle the array each time a new item is added or an existing item is removed,
for example, 3,6,7 is unoccupied, when no.3 is removed, i have to move the array up so that the array becomes 6,7..
u see what I mean. On the other hand, if i don't shuffle it, I have to place a loop in the timer... for example
1 2 x 4 x 5
I have to search it everytime from the start when I need to, it would be very sluggish ... hope you understand...
do u have an ultimate solution for this?
Thanks
Jacky
0
 
luckieAuthor Commented:
I have thought out three solutions to this problem... pls give some comments

1. Maintain an array of flags (True or False), when the pigoenhole is picked, it's turned to TRUE, so next time for pick (some graphics), i look for the next pigeonhole which is false (very confusing indeed), then turn it to true again , the disadvantage is that the program has to search everytime from the start and that involves a timer in which the loop is wrapped.

2. Maintain 2 arrays which don't involve boolean values,
   When the true array is added, which means the    
   pigeonhole is picked. Also, when the pigeonhole
   is "swept", I'll remove that from the true array and add that no to the FALSE array. Don't seem too good at all?
and also the arrays have to be shuffled each time the arrays are affected...

3. keeping an array of identification nos...
e.g.
1  2  3   4
5  17  23 25
which means pigeonhole 5,17,23,25 are empty and i only maintain 20 elements... the sole disadvantage is i have to shuffle the array each time the arrays are affected!

What do u think? I would use Dictionary in all cases
Thanks
Jack
0
 
luckieAuthor Commented:
Hi, anyone there?
0
 
luckieAuthor Commented:
Discovering the fact that with 18.2 times interrupts occur in a second and 123 times per loop, we have about 2600 loops per second... just to search the unoccupied pigeonhole, could anyone please supply me a faster algorithm... I will be much obliged...
Thanks
Jack
0
 
luckieAuthor Commented:
Another problem I encountered was I need one timer to enable another timer and disable itself, and this timer enables the third timer and disable itself and so on...
Does it cause any problems to the program in terms of performance?
Thanks
Jack
0
 
luckieAuthor Commented:
I'm out of ideas, even in debug mode, module pages switching (when a call to another function which locates at different .BAS or property bags etc) was slow too.
Thanks
Jack
0
 
luckieAuthor Commented:
Sorry, it's no relation with the loops, it is because of the no. of activex controls, I will setup a homepage tonight and you can download the program and you might give me some fresh advice! Thanks
Jack
0
 
luckieAuthor Commented:
Some complements presented in the NG:

I got a performance degrade after setting up about 300 activeX
controls. It is plain to see it's because of the increasd number of
activeX controls. I will let you download after I return home tonight
and you might give me some advice.  Thanks
Jack
0
 
luckieAuthor Commented:
finally some good news, I have setup a homepage for this.
but remember to create a directory first, otherwise it will make your hd scrappy.
http://home.netvigator.com/~luckie/download.html
Thanks
Jack
0
 
luckieAuthor Commented:
the dir is called "C:\area a 2", because I have hardcoded it.
Thanks
0
 
luckieAuthor Commented:
Could I clear up all comments and restart?
Thanks
Jack
0
 
luckieAuthor Commented:
Great Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 27
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now