OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > Code Critique

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-04-2005, 14:23
xombie
Guest
 
Posts: n/a
Default Complicated simplicity? (newbie)

Hello all. Following is a couple of related routines that I cant understand how to fix. The sub FlipMachine() takes an existing selection & flips it on its left or right side then flips it down its vertical center so its not mirrored. The sub works but I am tired of entering the little routine that is contained in the sub BogusSelection, everytime i need to check for invalid or null selections. Therefore, I am trying to write it once, call it, then return back to whatever routine called it. My problem is to get the sub BogusSelection() to exit the sub that called it not the called sub itself. The BogusSelection Sub() returns back to the sub flipMachines() right in the middle of a with / end with block of code which obviously results in a with block not set error.
Code:
  Sub BogusSelection()
 If ActiveSelectionRange.Count < 1 Then
    MsgBox "Invalid selection!"
    Exit Sub
    End If
End Sub
Sub FLIPMACHINE()
    Call BogusSelection
    ActiveDocument.BeginCommandGroup "Flipin Machines"
    Dim OrigSelection As ShapeRange
    Set OrigSelection = ActiveSelectionRange
    Dim dup1 As ShapeRange
    Set dup1 = OrigSelection.Duplicate()
    If IsShiftPressed() Then
     ActiveDocument.ReferencePoint = cdrMiddleLeft
     Else
    ActiveDocument.ReferencePoint = cdrMiddleRight
    End If
    With dup1
    .Stretch -1#, 1#
    .Flip cdrFlipHorizontal
    .CreateSelection
    End With
    
    ActiveDocument.EndCommandGroup
End Sub
Any advice is welcome.... Thanx
Andy.
Reply With Quote
  #2  
Old 07-04-2005, 20:41
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Complicated simplicity? (newbie)

xombie,

There are two possible solutions to your problem. First and brutal one is to use End statement. It will stop the macro execution at any point. So, instead of using Exit Sub, just use End:

Code:
Sub BogusSelection() 
    If ActiveSelectionRange.Count < 1 Then 
        MsgBox "Invalid selection!" 
        End 
    End If 
End Sub
But I personally don't like this approach. It is too drastic to my taste. I would make BogusSelection a function instead which would return True if the selection is invalid ("bogus") and False if everything is Ok:

Code:
Function BogusSelection() As Boolean
    If ActiveSelectionRange.Count < 1 Then 
        MsgBox "Invalid selection!" 
        BogusSelection = True
    Else
        BogusSelection = False
    End If 
End Function
Now you can check the selection and exit your main FlipMachine subroutine if the selection is wrong:

Code:
Sub FLIPMACHINE()
    If BogusSelection() Then Exit Sub
    ...
I think it's better this way

Hope this helps
Reply With Quote
  #3  
Old 08-04-2005, 22:15
xombie
Guest
 
Posts: n/a
Default

Thanx Alex. Im with you. Theres nothing like a little finesse.
Again, you've saved the day!
Best regards, Andy (xombie)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie questions Adrian Batchelor CorelDRAW/Corel DESIGNER VBA 2 15-11-2003 11:04
newbie question but hopefully easy to answer. cutter CorelDRAW/Corel DESIGNER VBA 0 05-11-2003 11:30


All times are GMT -5. The time now is 02:01.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com