Page 1 of 2 12 LastLast
Results 1 to 40 of 49

Thread: Favorite Functions Part #4 < Please post your's too!

  1. #1

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    My Favourite Functions Part #4

    Since I really enjoyed the "My Favorite Functions" on Vb-World and learned a lot of it, I thought it would be cool to make a fourth part, so guys/girls, go ahead and post your favorite functions here! (API's are welcome too!)
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  2. #2
    Guest
    One of my favorite API Functions is FindWindow



    well, actually its a tie between FindWindow, CallWindowProc, and SetWindowLong



    Code:
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

  3. #3

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    what are the last 2 for?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4
    Guest
    They are used for subclassing,
    SetWindowLong sets which function is used in a window's procedure, it has to be a public function inside a module, to get the address of this function you use, the AddressOf Operator, CallWindowProc is used so when you subclass the window still does what it is supposed to do, I have found if I dont use CallWindowProc VB Freezes.

  5. #5

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Ok thanx,

    can someone please explain what the
    - Like operator exactely does? (and give me an example please)
    - Mod operator is used for? (it seems to be some mathematical thingy, and I hate maths )

    Thanx
    BTW, one of my favorite VB functions is still IsNummeric, many programmers aren't aware of this handy function, you could do some complicated loop thingy's to check for the ASCII nr's, but this one is easier.

    example:
    Code:
    Dim MyVar As String, MyVar2 As String
    
    MyVar = 129937
    MyVar2 = "hello"
    'IsNummeric Returns true if the passed variable is Nummeric
    MsgBox IsNummeric(MyVar) 'True
    MsgBox IsNummeric(MyVar2) 'False
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Some developers suggest putting DoEvents in long loops to keep your application responsive.
    This is never a good idea because you take an (in my opinion) unacceptable performance hit.
    If your users must be able to click on a cancel button while your loop is executing use the GetInputState function instead.
    This API function returns 1 if the user has pressed a mouse button or hit a key on the keyboard.
    The overhead for GetInputState is much lower than for DoEvents.
    If a keyboard or a mouse event occurs, then and only then you call DoEvents.
    Code:
    Private Declare Function GetInputState _
     Lib "user32" () As Long
    
    Private m_blnCancel As Boolean
    
    Private Sub cmdCancel_Click()
        m_blnCancel = True
    End Sub
    
    Private Sub cmdStartLoop_Click()
        Dim lngCounter As Long
    
        m_blnCancel = False
        For lngCounter = 0 To 10000000
            'do a lot of stuff here
            If lngCounter Mod 100 = 0 Then 
                If GetInputState <> 0 Then
                    'a mouse or keyboard event is in
                    'the message queue so we call DoEvents
                    DoEvents
                    If m_blnCancel = True Then
                        Exit Sub
                    End If
                End If
            End If
        Next
    End Sub
    Best regards

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The Mod operator perform a modulus operation.
    It returns the remainder when you devide two integers.

    5 Mod 2 = 1 (5/2=2, 2*2=4, 5-4=1)
    6 Mod 2 = 0 (6/2=3, 3*2=6, 6-6=0)

    The Like operator is used to compare two strings.

    string Like pattern

    In the pattern string you can have wildcard characters like this:
    Code:
    If "Joacim Andersson" Like "*ss*" Then
    The above code compares my name with *ss* which means that there can be any number of characters before and after the two s characters.
    In this case the line would return True.

  8. #8
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    The mod operator is useful for performing a task every x number of loops (like mentioned above).

    One place I often use it is to update a progress bar. On an intensive loop, having a graphic control updated is often a performance drag and unnecessary. so to have it update only every 50 loops you can add...

    Code:
    For X = 1 to 10000
    
       ' Do normal loop code
    
       If X Mod 50 = 0 Then
          ProgressBar1.Value = X
       End If
    
    Next
    It's like having "Step 50" on the loop for the progress bar update but not for the rest of the loop.

    I also used it in a database call in an ASP page to change the background colour of every 4th row to light blue so that the dynamic table was easier to reference.

    Very useful

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    With mod operator you can split up values in factors

    ?3 mod 2
    1
    ?int(3/2) mod 2
    1

    so 3 is binary 11. You'll find mod's in all base converters - splitting up a color long into red green and blue is the same technique. 256 is the base

    Also for counters you could use mod's to reset to 0 after a certain value

    n=(n+1) mod 10

    For Like, check out vb-help, the comparations are much like the file matching done in dos like "*.*" you remember, but like has more features
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Originally posted by Jop
    BTW, one of my favorite VB functions is still IsNummeric
    It's spelt:

    Code:
    IsNumeric
    Shish. Typical.

    Anyway, my favourite APIs follow:

    Code:
    'Makes any app look really Microsofty:
    Public Declare Function DrawEdge Lib "user32" Alias "DrawEdge" (ByVal hdc As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long
    'Gets your own back on VB's attempt to make ActiveX controls useless:
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    'Nice for tooblars
    Public Declare Function DrawIconEx Lib "user32" Alias "DrawIconEx" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
    'Basic move memory with VB:
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    'These go together (for creating special windows):
    Public Declare Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Public Declare Function CreateRectRgn Lib "gdi32" Alias "CreateRectRgn" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Non API:
    Code:
    'Pointers do exist in VB :)
    VarPtr()
    'Good for strings
    Like
    Oh, well.

    They're my favourite functions. (Well, CopyMemory's a Sub, and Like is an more of an operator)

    Enough of this gay banter.

    Au revoir (as Ms Le Pont would have us say)

    [Edited by V(ery) Basic on 08-28-2000 at 05:19 AM]
    Courgettes.

  11. #11

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    Oops :) Shame on me!

    It's spelt:
    Code:
    IsNumeric
    Let's say I was tired
    hehe anyway, anyone thanks for the info about mod.

    More favourite functions, operators, api-calls?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  12. #12
    Guest
    V(ery):
    how do you use DrawEdge? I tried once, but it didnt work.

  13. #13
    Guest
    my fave functions are PARAMARRAY, REPLACE, LIKE, ISMISSING and in joint 5th place: SPLIT and JOIN

    (Check out Paramarray especially)

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    V(ery) - you can also use StrPtr() for string pointers.

    Favourite API function, glutSolidSphere.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15
    Guest
    after you get the pointer to a string or variable, what do you do with it?
    how do you use it? in C++ I know, but not in VB.

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Some API functions require it, like OpenGL. Also, you can use it with other API functions to do optimised string handling functions, which require an absolute memory address.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  17. #17

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    What are ParamArray and IsMissing for?
    Sounds quite interesting!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  18. #18
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ParamArray is a keyword you place in a function delcaration before the last argument, which should be an array.
    Then you can pass as many arguments as you like, for instance like array() function, and the arguments will be in the last array.

    Ismissing is a function that returns true if a variable, an optional argument passed to a procedure is omited.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  19. #19
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    IsMissing can only be used with Variants so in my humble opinion I think it’s a bit obsolete.
    When the Optional keyword was first introduced you could only use it with Variants but today you can use it with any data type.
    Code:
    Private Sub AnExample(A As Integer, Optional B As Integer)
        'do some stuff
    End Sub
    If you should use IsMissing on the optional argument B it would always return False, because if you omit that argument B would be zero.

  20. #20
    Guest
    V(ery) I am gonna look at it, just havent needed menu's for a while


  21. #21
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    V(ery),
    I used your DrawEdge rutine to get that 'Microsofty' look. I set a menu at design time and called your rutine. The rectangle looks good but it's drawn below my menu. How can I use it to get the menu on top of the rectangle?

    Thanks
    Thanks

    Tomexx.

  22. #22
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Originally posted by V(ery) Basic
    parksie, ObjPtr gets the pointer of an object. I'm one up on you now boy and since there aren't any more, I've won.
    V(ery): You lose.
    Code:
    Declare Function ArrPtr Lib "msvbvm50.dll" Alias "VarPtr" (Arr() As Any) As Long
    Well, it is an expansion of VarPtr but I think it still counts.

  23. #23
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yonatan, you're too sneaky at this. BTW - do you have any info on asm and functions?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  24. #24

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Any more functions? I'm still hungry!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  25. #25
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Originally posted by Yonatan
    Originally posted by V(ery) Basic
    parksie, ObjPtr gets the pointer of an object. I'm one up on you now boy and since there aren't any more, I've won.
    V(ery): You lose.
    Code:
    Declare Function ArrPtr Lib "msvbvm50.dll" Alias "VarPtr" (Arr() As Any) As Long
    Well, it is an expansion of VarPtr but I think it still counts.
    Bugger.

    I won't comment on the fact that the Alias is actually VarPtr.


    Anyway (sees an opportunity to give his app to another innocent victim ) :
    Tomexx: Windows changes the coordinate system when it adds a menu. I have
    (turns to his oven) made one earlier and I'm gonna e-mail it to you whether
    you like it or not





    Probably not, but I don't care.
    Courgettes.

  26. #26
    Guest
    I like DrawFocusRect

    Code:
    Public Declare Function DrawFocusRect Lib "user32" Alias "DrawFocusRect" (ByVal hdc As Long, lpRect As RECT) As Long

    PS:
    Does anybody know how to draw the focus thing, but not in a rectangle shape(for example, like a circle or something)??


  27. #27
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Maybe you just draw two circles on each other, which starts from 7/4 pi radians and goes to 3/4 pi radians + vice versa in the right system colors..
    couldn't be hard
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  28. #28
    Member
    Join Date
    Aug 2000
    Posts
    32
    I kinda found this to be very usefull when you have people using a common machine.

    Public Declare Function SwapMouseButton Lib "user32" Alias "SwapMouseButton" (ByVal bSwap As Long) As Long
    VB 6, SQL, Java, AutoLISP, Avenue and on a good day AML

  29. #29
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Well, well well, aren't we all in love with the API.
    I personally am rubbish at the API, so my favourite
    functions are standard VB ones.

    My favourite functions then, as no one else has mentioned
    them.

    InStr The basis for all string manipulation.
    Mid$ Goes with InStr, you can forget about Left$()
    and Right$(), you dont need them

    Get #1, , variable Wonderful for fast file access.
    You can also control the file in manageable chunks. If you
    get the chunk sizes right, you can manipulate files much
    quicker than with the FSO, and slightly faster than the
    Input functions.
    Put #1, , variable Obviously paired with Get
    Iain, thats with an i by the way!

  30. #30
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    Hey Very!!


    I am getting a bit jealous here. Can I get a look at this app of yours?

    [email protected]

    Thanks

  31. #31
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    *Smiles smugly*

    Certainly.
    Courgettes.

  32. #32
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    My favorite must be Rnd, or maybe Int, but i think i use Int most oftenly, hehe why do we love API?

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  33. #33
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Exclamation Hey!

    You all forgot about GetWindowThreadProcessId!
    I like it because I find API functions with long names intriguing.

  34. #34

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    What does GetWindowThreadProcessId do then?
    Never used it before!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  35. #35
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post GetWindowThreadProcessId

    To find out, click this smiley:
    Basically, you give it a window (hWnd) and it gives you the ThreadID and the ProcessID.
    (Returns the ThreadID in the return value, and the ProcessID in a "ByRef" parameter)
    VB declaration: (You might want this )
    Code:
    Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long

  36. #36
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    I use a lot of functions and subs in my own functions

    Code:
    '-- Useful --
    Private Function Random(ByVal Min as Integer, ByVal Max as Integer) as Integer
        Randomize Timer
        Random = Int(Val(Rnd * Max) + Min)
    End Function
    
    Private Function IsOdd(ByVal n as Long) as Boolean
        IsOdd = True
        If n mod 2 = 0 then
            IsOdd = False
        End If
    End Function
    '-- Fun --
    Private Function Leeto(ByVal txt as string) as string
        Dim tmpTxt as string
        Dim i as Integer
        tmpTxt = ""
        For i = 1 to Len(txt)
            If IsOdd(i) then
                tmpTxt = tmpTxt & UCase(Mid(txt, i, 1))
            Else
                tmpTxt = tmpTxt & LCase(Mid(txt, i, 1))
            End If
        Next
    
        Leeto = tmpTxt
    End Function

    r0ach™
    Don't forget to rate the post

  37. #37
    Lively Member The_Fog's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Posts
    65

    Thumbs up

    My fav. functions are:

    split ->Turns a string into an array
    Ubound ->Returns the number of posts in an array
    Len ->Return the lenght of a string
    FileLen ->Returns the lenght of a file

    Do/Loop

    Select case

    fav. APIs:

    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

    Declare Function Shell_NotifyIcon Lib "shell32.dll" (ByVal dwMessage As Long, lpDate As NOTIFYICONDATA) As Long

    Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long


    They will try to steal everything you own,
    It goes on and on and on...


    Pain - On and On

  38. #38

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I use this Function from the book SAMS Teach Yourself Internet Programming with Visual Basic 6 in 21 days so all credits go to them, they rule I don't and I really recommend this book. (Ok enough commercial brabbling)

    Code:
    Option Explicit
    
    
    Public Function GetLinks(s As String, baseUrl As String)
    Dim pos As Long, pos1 As Long, pos2 As Long
    Dim buf As String, temp As String
    Dim sq As String, dq As String
    Dim qc As String, Start As Long
    
    buf = ""
    
    'Make sure a nonempty string has been passed.
    If s = Null Or Len(s) = 0 Then
        GetLinks = buf
        Exit Function
    End If
    
    'Make sure there is at least one link
    Start = InStr(1, s, "<a href=", vbTextCompare)
    If Start = 0 Then
        GetLinks = buf
        Exit Function
    End If
    
    'Define the single
    dq = Chr$(34)
    sq = Chr$(39)
    
    Do
        'get the first Dq or Sq
        pos = InStr(Start, s, dq, vbTextCompare)
        pos2 = InStr(Start, s, sq, vbTextCompare)
        If pos = 0 And pos2 = 0 Then Exit Do 'Nothing found
        
        If pos > 0 And pos2 > 0 Then
            If pos < pos2 Then 'It's a Dq
                qc = dq
            Else
                qc = sq
                pos = pos2
            End If
        ElseIf pos = 0 Then 'Only Signle
            qc = sq
            pos = pos2
        ElseIf pos2 = 0 Then
            qc = dq
        End If
        
        pos1 = InStr(pos + 1, s, qc, vbTextCompare)
        If pos1 = 0 Then Exit Do
        temp = Mid$(s, pos + 1, pos1 - pos - 1)
        'Forget about FTP and Mailto links
        If LCase(Left(temp, 7)) = "mailto:" Or LCase(Left(temp, 3)) = "ftp" Then
            GoTo DoNotAdd
        End If
        'See if it's a full URL, if not add the base Url
        If LCase(Left(temp, 7)) <> "http://" Then
            temp = baseUrl & temp
        End If
        'Strip off anything following a # or ?
        pos = InStr(1, temp, "#")
        If pos > 0 Then
            temp = Left(temp, pos - 1)
        End If
        pos = InStr(1, temp, "?")
        If pos > 0 Then
            temp = Left(temp, pos - 1)
        End If
        buf = buf & temp & "|"
    DoNotAdd:
        'Locate the next link
        pos = InStr(pos1, s, "<a href=", vbTextCompare)
        Start = pos
        'If there a no more links then quit
        If pos = 0 Then Exit Do
        DoEvents
    Loop While True
    
    'Strip off the trailing |
    GetLinks = Left(buf, Len(buf) - 1)
    'MsgBox buf
    End Function
    Hope it's of use for someone.
    Again, all respect, flowers, presents, money, kisses, pies and ofcourse the new ferrari goes to the great [/i]Peter Aitken[/i], the author of the book Sams Teach Yourself Internet Programming with VB6 in 21 days! BUY IT!!!

    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  39. #39
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Thumbs up BINARY SEARCHING OF SORTED LISTS

    will search a sorted list of 1,000,000 in 20 jumps max (instead of 1,000,000)

    It's set up for LONG data types but it'll work for strings etc with little modification, it's the idea of the search technique rather than this code per se which is clever

    Code:
    Public Function BinarySearch(target As Long, List() As Long, NumItems As Long) As Long
    Dim min As Long
    Dim max As Long
    Dim middle As Long
     
        NumSearches = 0
     
        ' During the search the target's index will be
        ' between Min and Max: Min <= target index <= Max
        min = 1
        max = NumItems
        Do While min <= max
            NumSearches = NumSearches + 1
            
            middle = (max + min) / 2
            If target = List(middle) Then     ' We have found it!
                BinarySearch = middle
                Exit Function
            ElseIf target < List(middle) Then ' Search the left half.
                max = middle - 1
            Else                              ' Search the right half.
                min = middle + 1
            End If
        Loop
        
        ' If we get here the target is not in the list.
        BinarySearch = 0
    End Function


    Can you use "As Any" in this sort of function or should you use Variant to make it generic?










    [Edited by Paul282 on 09-01-2000 at 10:07 AM]
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  40. #40
    Hyperactive Member Warmaster199's Avatar
    Join Date
    Aug 2000
    Location
    Canada
    Posts
    306

    DirectX

    I Need to use DirectX anyway for what I'm doing. I need Direct Draw to create the app in fullscreen and then use Direct 3D. I Initialize Direct 3D and make it run in Direct 3D HAL(Hardware Abstract Layer for those who don't know what HAL is). Then, In the D3D Initialization sub, nefore I Init the device, I add a Z-Buffer. I won't bother posting these HUGE functions here, but, If you want to see them and other 3D related things, got to my Homepage and go to the I3D section. I3D is a graphics engine that I made myself and Comtech is my company(So far, I'm the only one in it, heh heh heh). In the I3D section you'll find new stuff and the I3D Features page. Don't forget to download the engine(what price is better than FREE!!!). P.S. I would like some feedback on I3D.
    Designer/Programmer of the Comtech Operating System(CTOS)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width