Solved

Question rephrased II - ActiveX controls limitations

Posted on 2002-06-24
35
165 Views
Last Modified: 2010-05-02
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
Comment
Question by:luckie
  • 27
  • 5
  • 2
  • +1
35 Comments
 
LVL 1

Expert Comment

by:tetrode
ID: 7103720
Why would you write your own B-Tree algorithm? You're better of using a collection or database.

Homework?

0
 
LVL 100

Expert Comment

by:mlmcc
ID: 7103761
listening
0
 

Author Comment

by:luckie
ID: 7104018
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
 

Author Comment

by:luckie
ID: 7104026
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
 
LVL 18

Expert Comment

by:deighton
ID: 7104143
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
 

Author Comment

by:luckie
ID: 7106302
I want to get the closest no to 1 that is true...
Thanks
0
 
LVL 18

Expert Comment

by:deighton
ID: 7106870
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
 
LVL 18

Expert Comment

by:deighton
ID: 7106894
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
 

Author Comment

by:luckie
ID: 7106966
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
 

Author Comment

by:luckie
ID: 7106986
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
 
LVL 18

Expert Comment

by:deighton
ID: 7113015
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
 
LVL 1

Expert Comment

by:tetrode
ID: 7113032
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
 

Author Comment

by:luckie
ID: 7115511
Yes, please.
0
 
LVL 18

Accepted Solution

by:
deighton earned 50 total points
ID: 7115877
example using dictionaries

you nead to add a reference to 'microsoft scripting runtime'
0
 

Author Comment

by:luckie
ID: 7123771
Dictionaries... oh fine... will come back ASAP
0
 

Author Comment

by:luckie
ID: 7123784
Just one extra q... as I couldn't find it in MSDN opening page ..., how do I install examples in MSDN?
0
 

Author Comment

by:luckie
ID: 7123866
Just one extra q... as I couldn't find it in MSDN opening page ..., how do I install examples in MSDN?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:luckie
ID: 7128891
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
 

Author Comment

by:luckie
ID: 7128898
should be
if Not d.exists(i)

and I can use gethead :) to get the first empty pigeonhole!
Thanks
Jack
0
 

Author Comment

by:luckie
ID: 7128902
Would it be faster than straight searching?
Thanks
Jack
0
 

Author Comment

by:luckie
ID: 7128904
my brain hurts :(
0
 

Author Comment

by:luckie
ID: 7128939
If I put the loop in a timer... you know the rest...
Thanks
Jack
0
 

Author Comment

by:luckie
ID: 7128975
Still a performance degrade when searching for large numbers (for example 120-123) in an 123 array
Thanks
Jack
0
 

Author Comment

by:luckie
ID: 7129203
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
 

Author Comment

by:luckie
ID: 7131576
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
 

Author Comment

by:luckie
ID: 7136878
Hi, anyone there?
0
 

Author Comment

by:luckie
ID: 7142409
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
 

Author Comment

by:luckie
ID: 7142420
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
 

Author Comment

by:luckie
ID: 7145044
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
 

Author Comment

by:luckie
ID: 7148664
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
 

Author Comment

by:luckie
ID: 7148677
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
 

Author Comment

by:luckie
ID: 7152130
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
 

Author Comment

by:luckie
ID: 7152132
the dir is called "C:\area a 2", because I have hardcoded it.
Thanks
0
 

Author Comment

by:luckie
ID: 7164479
Could I clear up all comments and restart?
Thanks
Jack
0
 

Author Comment

by:luckie
ID: 7274080
Great Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now