MickD 发表于 2006-6-21 14:35:28

更好的书写方式

本人'我试图压缩我的dvb文件,使事情更简单,并想知道是否有人可以压缩这个子更小&nbsp 此接头使用Select Case替换6-8个其他接头 如果没有'没有意义,我'I’我会尽力解释得更好
Public Sub BATCHP(SIZE As String)
    Dim currentline As String
    Dim PLOTTYPE As String
    Open "c:\dwgnum.dat" For Input As 1
    While Not EOF(1)
      Line Input #1, currentline
      Documents.Open currentline
      Debug.Print currentline
      ThisDrawing.Regen acAllViewports
      Select Case SIZE
      Case "VA"
            Call SetupAndPlot("11x17Draft.pc3", "STANDARDS.ctb", "Business_Letter_(8.50_x_11.00_Inches)", ac1_1, ac0degrees)
            ThisDrawing.Plot.PlotToDevice
            ThisDrawing.Close (True)
      Case "V11"
            Call SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees)
            ThisDrawing.Plot.PlotToDevice
            ThisDrawing.Close (True)
      Case "VC"
            Call SetupAndPlot("OCE DesignJet 750C.pc3", "VENDOR MEDIUM.ctb", "ARCH_expand_C_(24.00_x_18.00_Inches)", acScaleToFit, ac0degrees)
            ThisDrawing.Plot.PlotToDevice
            ThisDrawing.Close (True)
      Case "VD"
            Call SetupAndPlot("OCE DesignJet 750C.pc3", "VENDOR MEDIUM.ctb", "ARCH_expand_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
            ThisDrawing.Plot.PlotToDevice
            ThisDrawing.Close (True)
      Case "T11"
            Call SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees)
            ThisDrawing.Plot.PlotToDevice
            ThisDrawing.Close (True)
      Case "TC"
            Call SetupAndPlot("OCE DesignJet 750C.pc3", "tep.ctb", "ARCH_expand_C_(24.00_x_18.00_Inches)", acScaleToFit, ac0degrees)
            ThisDrawing.Plot.PlotToDevice
            ThisDrawing.Close (True)
      Case "TD"
            Call SetupAndPlot("OCE DesignJet 750C.pc3", "tep.ctb", "ARCH_expand_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
            ThisDrawing.Plot.PlotToDevice
            ThisDrawing.Close (True)
      Case Else
            Call Vendor1117
      End Select
    Wend
    Close 1
End Sub

Bryco 发表于 2006-6-21 14:36:14

这是SetupAndPlot子菜单Public Sub SetupAndPlot(ByRef Plotter As String, CTB As String, SIZE As String, PSCALE As String, ROT As String)
    Dim Layout As AcadLayout
    On Error GoTo Err_Control
    Set Layout = ThisDrawing.ActiveLayout
    Layout.RefreshPlotDeviceInfo
    Layout.ConfigName = Plotter    ' CALL PLOTTER
    Layout.PLOTTYPE = acExtents
    Layout.PlotRotation = ROT    ' CALL ROTATION
    Layout.StyleSheet = CTB    ' CALL CTB FILE
    Layout.PlotWithPlotStyles = True
    Layout.CanonicalMediaName = SIZE    ' CALL SIZE
    Layout.PaperUnits = acInches
    Layout.StandardScale = PSCALE    'CALL PSCALE
    Layout.ShowPlotStyles = False
    ThisDrawing.Plot.NumberOfCopies = 1
    Layout.CenterPlot = True
    Layout.ScaleLineweights = False
    Layout.RefreshPlotDeviceInfo
    ThisDrawing.Regen acAllViewports
    ZoomExtents
    Set Layout = Nothing
    ThisDrawing.Save
Exit_Here:
    Exit Sub
Err_Control:
    Select Case Err.Number
    Case "-2145320861"
      MsgBox "Unable to Save Drawing- " & Err.Description
    Case "-2145386493"
      MsgBox "Drawing is setup for Named Plot Styles." & (Chr(13)) & (Chr(13)) & "Run CONVERTPSTYLES command", vbCritical, "Change Plot Style"
    Case Else
      MsgBox "Unknown Error " & Err.Number
    End Select
End Sub

Bryco 发表于 2006-6-21 14:53:35

这就是我要替换的内容Public Sub BATCHPLOT1824()
    Dim currentline As String
    Open "c:\dwgnum.dat" For Input As 1
    While Not EOF(1)
      Line Input #1, currentline
      Documents.Open currentline
      Debug.Print currentline
      ThisDrawing.Regen acAllViewports
      Call VendorQuickPlotC
    Wend
    Close 1
End Sub
Public Sub BATCHPLOT2436()
    Dim currentline As String
    Open "c:\dwgnum.dat" For Input As 1
    While Not EOF(1)
      Line Input #1, currentline
      Documents.Open currentline
      Debug.Print currentline
      ThisDrawing.Regen acAllViewports
      ThisDrawing.MSpace = False
      Call VendorQuickPlotD
    Wend
    Close 1
End Sub

Bryco 发表于 2006-6-21 16:09:50

在我看来,它看起来很流线型;您可以移动绘图并靠近SetupandPlot sub;再说一次,你可以离开他们 看起来不错。

Bryco 发表于 2006-6-21 16:15:04


你听起来像个气象员
今天可能会下雨,但又可能不会下雨

Bryco 发表于 2006-6-21 18:41:42

有单独的函数并没有什么错,事实上它是35;039;s可能更快,因为测试更少(您的switch语句包含许多测试),其中作为单独的函数直接调用函数的地址偏移量
如果你想简化开关,请按最常用的顺序排列。i、 e.如果BATCHPLOT1824是最常用的,将其作为第一个开关,这样您就可以退出开关,以避免测试更频繁
为了串列现有函数,我看到在每个函数中重复了相同的代码行(注意:更多的是作为一个示例,而不是这个特定代码段的要求)
    Dim currentline As String
    Open "c:\dwgnum.dat" For Input As 1
    While Not EOF(1)
      Line Input #1, currentline
      Documents.Open currentline
      Debug.Print currentline
也许这可以放在自己的子系统中,并将其减少到每个工作子系统中的一行,这样每个子系统都会重新使用相同的代码(内存中的相同地址可以节省空间)
这可能并不适用于所有情况,但你明白了
这也是为什么几乎所有的应用程序都需要在你'我已经完成了第一个版本或beta版

Bryco 发表于 2006-6-21 23:46:27

我不知道'我不知道这是否适用于你,但我使用goto很多,试图缩短我的代码
Public Sub BATCHP(SIZE As String)
    Dim currentline As String
    Dim PLOTTYPE As String
    Open "c:\dwgnum.dat" For Input As 1
    While Not EOF(1)
      Line Input #1, currentline
      Documents.Open currentline
      Debug.Print currentline
      ThisDrawing.Regen acAllViewports
      Select Case SIZE
      Case "VA"
            Call SetupAndPlot("11x17Draft.pc3", "STANDARDS.ctb", "Business_Letter_(8.50_x_11.00_Inches)", ac1_1, ac0degrees)
      Case "V11"
            Call SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees)
      Case "VC"
            Call SetupAndPlot("OCE DesignJet 750C.pc3", "VENDOR MEDIUM.ctb", "ARCH_expand_C_(24.00_x_18.00_Inches)", acScaleToFit, ac0degrees)
      Case "VD"
            Call SetupAndPlot("OCE DesignJet 750C.pc3", "VENDOR MEDIUM.ctb", "ARCH_expand_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
      Case "T11"
            Call SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees)
      Case "TC"
            Call SetupAndPlot("OCE DesignJet 750C.pc3", "tep.ctb", "ARCH_expand_C_(24.00_x_18.00_Inches)", acScaleToFit, ac0degrees)
      Case "TD"
            Call SetupAndPlot("OCE DesignJet 750C.pc3", "tep.ctb", "ARCH_expand_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
      Case Else
            Call Vendor1117
            GoTo skip
      End Select
      ThisDrawing.Plot.PlotToDevice
      ThisDrawing.Close (True)
skip:
    Wend
    Close 1
End Sub

Bryco 发表于 2006-6-22 10:16:40

谢谢Bryco,我甚至没有看到我重复了8次的最后2行 这缩短了很多。

Bryco 发表于 2006-6-22 10:19:03

谢谢你,米克 在我开始把它压缩成可重复使用的部件之前,你应该已经看到这是多么的混乱 无论如何,你说的很有道理,所以我会试着把这些部分去掉;在我可以的地方。

Bryco 发表于 2006-6-22 10:44:10

那么Mick,你会用这个列表做什么
Public Sub VendorA()
    Call SetupAndPlot("11x17Draft.pc3", "STANDARDS.ctb", "Business_Letter_(8.50_x_11.00_Inches)", ac1_1, ac0degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub Vendor1117()
    Call SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub VendorQuickPlotC()
    Call SetupAndPlot("OCE DesignJet 750C.pc3", "VENDOR MEDIUM.ctb", "ARCH_expand_C_(24.00_x_18.00_Inches)", acScaleToFit, ac0degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub VendorQuickPlotD()
    Call SetupAndPlot("OCE DesignJet 750C.pc3", "VENDOR MEDIUM.ctb", "ARCH_expand_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub TEPQuickPlot11x17()
    Call SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub TEPQuickPlotC()
    Call SetupAndPlot("OCE DesignJet 750C.pc3", "tep.ctb", "ARCH_expand_C_(24.00_x_18.00_Inches)", acScaleToFit, ac0degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub TEPQuickPlotD()
    Call SetupAndPlot("OCE DesignJet 750C.pc3", "tep.ctb", "ARCH_expand_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub TEP9800D()
    Call SetupAndPlot("OCE 9800 DesignJet 750C.pc3", "tep.ctb", "ARCH_expand_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub TEPDWFD()    'Setups for C size and 11x17 do not exist, need to be created.
    Call SetupAndPlot("DWF6 ePlot.pc3", "tep.ctb", "ARCH_full_bleed_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True)
End Sub
Public Sub VENDORDWFD()    'Setups for C size and 11x17 do not exist, need to be created.
    Call SetupAndPlot("DWF6 ePlot.pc3", "VENDOR MEDIUM.ctb", "ARCH_full_bleed_D_(36.00_x_24.00_Inches)", ac1_1, ac0degrees)
    ThisDrawing.Plot.PlotToDevice
    ThisDrawing.Close (True) 既然它们都是独立的,你会保持原样还是试着压缩 所有这些都在同一个VBA模块中
页: [1] 2
查看完整版本: 更好的书写方式