OberonPlace.com Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-04-2004, 07:24
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default CD11: Adding input from user form to document

This little snippet is being used to place inputs from the user form to a blank order form. There is quite a bit more code (lots of user input) that goes after this, but you get the idea from all the If..then statements. I wanted to know if this was the most efficient way to go about this or if there was some function that I could use to make it clean-up a little.

Code:
' Add input from form to page
    If RushCheckBox1.Value = True Then
        Dim s888 As Shape
        Set s888 = ActiveLayer.CreateRectangle(6.548315, 7.274756, 7.852031, 6.955921, 0, 0, 0, 0)
        s888.OrderToBack
        s888.Fill.UniformColor.CMYKAssign 0, 0, 100, 0
        s888.Outline.Type = cdrNoOutline
    End If
    
    If optCOD.Value = True Then
        ActiveLayer.CreateArtisticText 8.343, 6.75, "ü", cdrEnglishUS, , "Wingdings", 18, cdrTrue, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If optAcct.Value = True Then
        ActiveLayer.CreateArtisticText 9.468, 6.75, "ü", cdrEnglishUS, , "Wingdings", 18, cdrTrue, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If methUPS.Value = True Then
        ActiveLayer.CreateArtisticText 5.3865, 5.141, "ü", cdrEnglishUS, , "Wingdings", 18, cdrTrue, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If methUPSCOD.Value = True Then
        ActiveLayer.CreateArtisticText 5.3865, 4.969, "ü", cdrEnglishUS, , "Wingdings", 18, cdrTrue, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If methPickUp.Value = True Then
        ActiveLayer.CreateArtisticText 6.792, 5.141, "ü", cdrEnglishUS, , "Wingdings", 18, cdrTrue, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If methDeliver.Value = True Then
        ActiveLayer.CreateArtisticText 6.792, 4.969, "ü", cdrEnglishUS, , "Wingdings", 18, cdrTrue, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If chkKeepScreen.Value = True Then
        ActiveLayer.CreateArtisticText 6.05, 5.718, "ü", cdrEnglishUS, , "Wingdings", 18, cdrTrue, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If methUPSCOD.Value = True Then
        ActiveLayer.CreateArtisticText 5.3865, 4.969, "ü", cdrEnglishUS, , "Wingdings", 18, cdrTrue, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If txbItem.Text > "" Then
        ActiveLayer.CreateArtisticText 9, 6.032, txbItem.Text, cdrEnglishUS, , "Tahoma", 10, cdrFalse, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If txbScreen.Text > "" Then
        ActiveLayer.CreateArtisticText 9, 5.718, txbScreen.Text, cdrEnglishUS, , "Tahoma", 10, cdrFalse, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
    
    If txbArt.Text > "" Then
        ActiveLayer.CreateArtisticText 9, 5.375, txbArt.Text, cdrEnglishUS, , "Tahoma", 10, cdrFalse, cdrFalse, cdrNoFontLine, cdrLeftAlignment
    End If
As you can see by the form screen shot below, there are a lot of fields to input...
Attached Images
 
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 09-04-2004, 11:30
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: CD11: Adding input from user form to document

I think you are doing it OK. However if anything I would change the absolute positioning of the checkmarks on the document. I assume that your black form is a CDR document with empty squares and some text, and you place the checkmarks in them using the Wingdings font. Right now you specify the absolute page coordinates for the text object. This could be difficult to maintain if you need to change your form.

I would give a unique name to each of the checkbox rectangles in the document, then find them by name in VBA and place the checkmark on top of them when needed.

Ok, let's assume that you have two checkbox rectangles as empty checkboxes for your COD and Account input fields. I would open up the Object Manager docker in CorelDRAW and gave the two rectangles the respective names, let's say "COD" and "Account". Then when I would create a function which would put a checkmark in the rectangle given the rectangle name.

I played with the text object, its size and position relative to the checkbox and determined that it looks OK on 1" x 1" checkbox if the text is about 110 pt size and has vertical offset about -0.16" (1/6"). So I calculated the required checkmark size and postion based on the checkbox size, which is another benefit - your program will not be dependent on checkbox sizes and positions on the page.

Here is the function which places a checkmark into a checkbox given the checkbox name:

Code:
Private Sub PutCheckmark(ByVal BoxName As String)
    Dim sBox As Shape
    Dim x As Double, y As Double, sx As Double, sy As Double
    Dim nSize As Single
    
    Set sBox = ActivePage.FindShape(BoxName)
    If Not sBox Is Nothing Then
        sBox.GetBoundingBox x, y, sx, sy
        x = x + sx / 2 ' Middle of box
        y = y - sy / 6 ' Offset by 1/6" downward
        nSize = sy * 110 ' Font size
        ActiveLayer.CreateArtisticTextWide x, y, ChrW$(252), Font:="Wingdings", Size:=nSize, Alignment:=cdrCenterAlignment
    End If
End Sub
And here is how you can call the function:

Code:
If optCOD.Value Then PutCheckmark "COD"
If optAcc.Value Then PutCheckmark "Account"
...
You can use the same approach to put text fields inside textboxes, etc (using reference objects in the document and finding them by name).

Also I feel it is a better style to check for an empty string by using "not equal to" operator "<>" rather than greater than ">":

Code:
If txtName.Text <> "" Then ...
I hope this is useful.
Reply With Quote
  #3  
Old 09-04-2004, 12:43
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Thanks, that could really save some time. If you can believe it, I was actually drawing the form each time until Shelby gave me the idea of creating a blank form template and opening that instead. It saved a lot of time there as well.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
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
Active document issues.. wbochar CorelDRAW/Corel DESIGNER VBA 2 19-03-2003 15:15


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