OberonPlace.com Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 17-11-2004, 15:22
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 Creating new document problems

This code is supposed to take info from the form for finished height and width and the sleeve size, and create a document that is (height x2 + sleeve size + .5 inches) in hieght and width is increased by 1 inch

Two problems.
1. The document doesn't get the .5" added to it and
2. The info bar still shows the document as 8.5"x11"
Code:
Option Explicit
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
    Alias "GetOpenFileNameA" _
    (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type
Private Function GetValue(ByVal sValue As String) As Integer
    If sValue = "" Then
        GetValue = 0
    Else
        GetValue = Val(sValue)
    End If
End Function

Private Sub buttonCancel_Click()
    Unload Me
End Sub

Private Sub buttonOK_Click()
    If ValidateParams Then
        CreateVinylStreetBanner.Hide
        CreatePageLayout
    End If
End Sub
Private Sub BoxSpace_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  If Not ((Chr(KeyAscii) >= 0 And Chr(KeyAscii) <= 9) Or (Chr(KeyAscii) = ".")) Then
    KeyAscii = 0
  End If
End Sub
Private Function ValidateParams() As Boolean
    ValidateParams = True

    If (IsNumeric(boxWidth.Text) = False) Then GoTo ErrWidth
    If (IsNumeric(boxHeight.Text) = False) Then GoTo ErrHeight
    If (IsNumeric(boxSleeve.Text) = False) Then GoTo ErrSleeve
    Exit Function
    
ErrWidth:
    MsgBox "Spacing not numeric : " & boxWidth.Text
    boxWidth.SetFocus
    ValidateParams = False
    Exit Function
ErrHeight:
    MsgBox "Spacing not numeric : " & boxHeight.Text
    boxHeight.SetFocus
    ValidateParams = False
    Exit Function
ErrSleeve:
    MsgBox "Spacing not numeric : " & boxSleeve.Text
    boxSleeve.SetFocus
    ValidateParams = False
    Exit Function

End Function
Private Sub ShowOpenFile()
Dim OFName As OPENFILENAME
Dim sPath As String
Dim GetBackEnd As String
Dim BrowseOpenFile As String
Dim n As String

    OFName.lStructSize = Len(OFName)
    OFName.hwndOwner = 0&
    OFName.hInstance = 0&
    OFName.lpstrFilter = "Image Files" + Chr$(0) + "*.ai;*.cdr;*.eps;*.pdf;*.cmx"
    OFName.lpstrFile = Space$(254)
    OFName.nMaxFile = 255
    OFName.lpstrFileTitle = Space$(254)
    OFName.nMaxFileTitle = 255
    sPath = GetBackEnd
    If sPath = vbNullString Then
        OFName.lpstrInitialDir = "c:\SharedImages\"
    Else
        sPath = Left(sPath, InStrRev(sPath, "\") - 1)
        If Len(Dir(sPath, vbDirectory)) > 0 Then
            OFName.lpstrInitialDir = sPath
        Else
            OFName.lpstrInitialDir = "c:\SharedImages\"
        End If
    End If
    OFName.lpstrTitle = "Select an image File (*.ai), (*.cdr), (*.cmx), (*.eps), (*.pdf)"
    OFName.flags = 0

    If GetOpenFileName(OFName) Then
        BrowseOpenFile = OFName.lpstrFile
    Else
        BrowseOpenFile = vbNullString
        MsgBox "No file Selected."
    End If

End Sub
Private Sub CreatePageLayout()
    Dim doc As Document
    Dim BrowseOpenFile As String
    Dim docH As Long
    Dim docW As Long
    Dim dw As Integer
    Dim dh As Integer
    Dim sl As Integer
    Dim sewn As Integer
    sewn = 0.5
    dw = GetValue(boxWidth.Value)
    dh = GetValue(boxHeight.Value)
    sl = GetValue(boxSleeve.Value)
    docH = dh + dh + sl + sewn
    docW = dw + 1
    Set doc = CreateDocument()
    doc.Unit = cdrInch
    
    'MsgBox "W:" & docW & " H:" & docH & " Sleeve:" & sl
    
    With ActivePage
        .Orientation = cdrPortrait
        .SizeWidth = docW
        .SizeHeight = docH
        .PrintExportBackground = False
        .Bleed = 0#
        .Background = cdrPageBackgroundNone
    End With
    
    If checkAddFile.Value = True Then
        ShowOpenFile
    End If
    
    If BrowseOpenFile <> "" Then
        Dim s5 As Shape
        Dim x As Double, y As Double
        Dim nsy As Double
        ActiveLayer.Import BrowseOpenFile
        Set s5 = ActiveSelection
        s5.Move 0#, 0#
        ActiveDocument.ReferencePoint = cdrCenter
        s5.GetPosition x, y
        If s5.SizeWidth > (2.14 * s5.SizeHeight) Then
            nsy = (7.5 / s5.SizeWidth) * s5.SizeHeight
            s5.SetSizeEx x, y, , nsy
        ElseIf s5.SizeWidth < (2.14 * s5.SizeHeight) Then
            s5.SetSizeEx x, y, , 3.5
        End If
        s5.PositionX = 6.797
        s5.PositionY = 2.154
    End If

End Sub
I'm also adding some guidelines to this document, but that's down the road...
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 20-11-2004, 00:09
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Creating new document problems

I think you are doing everything correctly (at least from a quick glance), however are you sure the page size is not changing? You know that CorelDRAW can show either the size of the current page or the default document page (master page) depending on the settings in the property bar? Could it be that you are changing the current page size while viewing the size of the default page size?

Here are some earlier discussions on the issue for more details:

- Property Bar Refresh
- setsize or setpagesize, question...
Reply With Quote
  #3  
Old 20-11-2004, 17:11
Anonymous
Guest
 
Posts: n/a
Default

Thanks Alex, this helped a lot. I'm sorry if I seemed like a nuisance on this topic, I was just giong crazy. Thanks again.
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
New document creation problem ddonnahoe CorelDRAW/Corel DESIGNER VBA 2 20-11-2004 00:26
Document not open... ddonnahoe CorelDRAW/Corel DESIGNER VBA 4 29-10-2004 14:13
Generic code to process all shapes in a document glennwilton CorelDRAW/Corel DESIGNER VBA 0 05-09-2003 03:13
Page selection and object moving problems wbochar CorelDRAW/Corel DESIGNER VBA 1 15-04-2003 09:10
Active document issues.. wbochar CorelDRAW/Corel DESIGNER VBA 2 19-03-2003 15:15


All times are GMT -5. The time now is 10:11.


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