最近,我也编了一个关于批处理的程序,但不知道为什么有时候可以运行,有时候就不可以!程序如下:
Private Sub cmdOk_Click() Dim i As Integer Dim ii As Integer Dim zz As Integer Dim drn As String Dim drn1 As String If lstFile.ListCount = 0 Then MsgBox "请添加所要操作的图形!" Exit Sub End If frmMain.hide For i = 0 To lstFile.ListCount - 1 drn1 = lstFile.List(i) Application.Documents.Open drn1 Dim ptmin(0 To 1) As Double: Dim ptmax(0 To 1) As Double ptmin(0) = -257: ptmin(1) = -271 ptmax(0) = -1099: ptmax(1) = 324 Dim currentPlot As AcadPlot Set currentPlot = ThisDrawing.Plot ThisDrawing.ActiveLayout.SetWindowToPlot ptmin, ptmax ThisDrawing.ActiveLayout.PlotType = acWindow If ComboBox1.Text = "ScaleToFit" Then ThisDrawing.ActiveLayout.StandardScale = acScaleToFit ThisDrawing.ActiveLayout.StyleSheet = TextBox2.Text Else ThisDrawing.ActiveLayout.StandardScale = ac1_1 ThisDrawing.ActiveLayout.StyleSheet = TextBox2.Text End If currentPlot.PlotToDevice TextBox1.Text Application.ActiveDocument.Close True, drn1 Next i
End Sub
Private Sub cmdOpen_Click() On Error GoTo errHandle Dim i As Integer Dim Y As Integer Dim z As Integer Dim FileNames() As String With comDlg .CancelError = True .MaxFileSize = 32767 .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks .DialogTitle = "选择图形文件" .filter = "图形文件(*.dwg)|*.dwg|所有文件(*.*)|*.*" .FileName = "" .ShowOpen End With comDlg.FileName = comDlg.FileName & Chr(0) '这些文件名是用空字符Chr(0)分隔符,而不是空格分隔符隔开 z = 1 For i = 1 To Len(comDlg.FileName) 'InStr函数,返回 Variant (Long),指定一字符串在另一字符串中最先出现的位置。 '语法 InStr(起点位置, string1, string2) i = InStr(z, comDlg.FileName, Chr(0)) If i = 0 Then Exit For ReDim Preserve FileNames(Y) 'Mid函数,返回 Variant (String),其中包含字符串中指定数量的字符。 '语法 Mid(string, start[, length]) FileNames(Y) = Mid(comDlg.FileName, z, i - z) z = i + 1 Y = Y + 1 Next i
'向列表框中添加对象 Dim count As Integer count = lstFile.ListCount If Y = 1 Then lstFile.AddItem FileNames(count), 0 Else For i = 1 To Y - 1 FileNames(i) = FileNames(0) & "\" & FileNames(i) lstFile.AddItem FileNames(i), i - 1 + count Next i End If errHandle: End Sub
Private Sub CommandButton1_Click() On Error GoTo errHandle Dim i As Integer Dim Y As Integer Dim z As Integer Dim FileNames() As String With comDlg .CancelError = True .MaxFileSize = 32767 .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks .DialogTitle = "选择PC3文件" .filter = "数据文件(*.pc3)|*.pc3|所有文件(*.*)|*.*" .FileName = "" .ShowOpen End With TextBox1.Text = comDlg.FileName errHandle: End Sub
Private Sub CommandButton2_Click() On Error GoTo errHandle Dim i As Integer Dim Y As Integer Dim z As Integer Dim FileNames() As String With comDlg .CancelError = True .MaxFileSize = 32767 .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks .DialogTitle = "选择CTB文件" .filter = "数据文件(*.ctb)|*.ctb|所有文件(*.*)|*.*" .FileName = "" .ShowOpen End With TextBox2.Text = comDlg.FileName errHandle: End Sub
Private Sub UserForm_Initialize() lstFile.Clear ComboBox1.AddItem ("ScaleToFit") ComboBox1.AddItem ("1:1") End Sub 出错提示为:Run-time error '_2154386493(80200003)'
Invalid input
不知道为什么,请高手分析一下,谢谢! |