Results 1 to 9 of 9

Thread: Few Questions

  1. #1
    ralphtodd
    Guest

    Question Few Questions

    How you doing, This is my first post and I have a few questions about VB

    1. Is there a way to tell if a program has been unloaded by pressing the 'x' at the top of the screen

    2. Can you sort arrays...eg:

    Ive got a type:

    Public Type something
    name as string
    num as integer
    etc
    etc
    End Type

    And then:

    Dim people(0 to 30) as something

    I add stuff to that array when something is selected. Name is added but also the order that the thing was selected. Can I then sort the array based on what number is in 'num'

    Thanks alot

  2. #2
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    1) If it's your program thats bieng unlaoded by the X then you can put:
    VB Code:
    1. Private Sub Form_Terminate()
    2. msgbox "Terminated by X"
    3. End Sub

    Thats a loose way of doing it i'm sure there's an api call as well!

    What part of Oz?

    later
    b

  3. #3
    ralphtodd
    Guest
    I live in Sydney

    So is the terminate event called when the 'x' is pressed

    Thanks alot

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Instead of using the Terminate event use the QueryUnload event.
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     If UnloadMode = vbFormControlMenu Then
    3.         MsgBox "I'm closing because you pressed the 'X' button"
    4.     End If
    5. End Sub
    By checking the UnloadMode you can determent why the form is unloading.
    Other values this argument can get is:
    vbFormCode = The Unload statement is invoked from code.
    vbAppWindows = The current Microsoft Windows operating environment session is ending.
    vbAppTaskManager = The Microsoft Windows Task Manager is closing the application.
    vbFormMDIForm = An MDI child form is closing because the MDI form is closing.
    vbFormOwner = A form is closing because its owner is closing.

    Best regards

  5. #5
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Bingo there ya go!

    Another NSWelshman geesh!

  6. #6
    ralphtodd
    Guest
    Thanks alot

    Anyone got an answer for my second question?

  7. #7
    gaffa
    Guest
    Here's a quicksort that's been modified for a UDT:
    VB Code:
    1. Private Sub QuicksortUDT(list() As SOMETHING, ByVal min As Integer, ByVal max As Integer)
    2.  
    3.     Dim med_value As SOMETHING
    4.     Dim hi As Integer
    5.     Dim lo As Integer
    6.     Dim i As Integer
    7.  
    8.     ' If the list has no more than CutOff elements,
    9.     ' finish it off with SelectionSort.
    10.     If max <= min Then Exit Sub
    11.  
    12.     ' Pick the dividing value.
    13.     i = Int((max - min + 1) * Rnd + min)
    14.     med_value = list(i)
    15.  
    16.     ' Swap it to the front.
    17.     list(i) = list(min)
    18.  
    19.     lo = min
    20.     hi = max
    21.     Do
    22.         ' Look down from hi for a value < med_value.
    23.         'COMPARISON
    24.         Do While list(hi).num>= med_value.num
    25.             hi = hi - 1
    26.             If hi <= lo Then Exit Do
    27.         Loop
    28.         If hi <= lo Then
    29.             list(lo).num= med_value.num
    30.             Exit Do
    31.         End If
    32.  
    33.         ' Swap the lo and hi values.
    34.         list(lo) = list(hi)
    35.        
    36.         ' Look up from lo for a value >= med_value.
    37.         lo = lo + 1
    38.         'COMPARISON
    39.         Do While list(lo).num< med_value.num
    40.             lo = lo + 1
    41.             If lo >= hi Then Exit Do
    42.         Loop
    43.         If lo >= hi Then
    44.             lo = hi
    45.             list(hi).num= med_value.num
    46.             Exit Do
    47.         End If
    48.        
    49.         ' Swap the lo and hi values.
    50.         list(hi) = list(lo)
    51.     Loop
    52.    
    53.     ' Sort the two sublists.
    54.     QuicksortUDT list(), min, lo - 1
    55.     QuicksortUDT list(), lo + 1, max
    56.    
    57. End Sub

    Hope that helps

    - gaffa

  8. #8
    ralphtodd
    Guest
    You are a legend. Thanks alot

  9. #9
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Originally posted by Beacon
    Bingo there ya go!

    Another NSWelshman geesh!
    The more, the merrier!


    What would be better - a Selection Sort, or a Bubble Sort?? I usually go for a bubble sort - if you want a code for this, do a quick search on sorting arrays, I wrote one a few days ago, but I'm on hols, so I can't do another...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

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