- 积分
- 761
- 明经币
- 个
- 注册时间
- 2003-5-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2003-8-3 20:59:00
|
显示全部楼层
(续前贴)
'确定按钮代码
Private Sub ok_Button_Click()
'读取数据库数据
Dim Excel As Excel.Application
Dim ExcelWorkbook As Object
Dim FileName As String, SheetName As Variant
Dim Count As Integer, J As Integer, I As Integer
Dim Var_ie As Integer, Var_de As Integer, Var_te As Integer, Var_be As Integer '设置图数,说明书数,清册数和概算书数变量
Dim Var_ImgName(1 To 60) As Variant, Var_ImgNo(1 To 60) As Variant
On Error GoTo Err_Control
FileName = ACDTmainForm.Filename_TextBox.Text
SheetName = ACDTmainForm.table_Box.Text
Set Excel = New Excel.Application
Set ExcelWorkbook = Excel.Workbooks.Open(FileName)
ExcelWorkbook.Sheets(SheetName).Activate
Set ExcelSheet = ExcelWorkbook.ActiveSheet
Count = 0
J = 2
Var_ie = 0
Var_de = 0
Var_te = 0
Var_be = 0
While ExcelSheet.Cells(J, 1).Value <> ""
Count = Count + 1
J = J + 1
Wend
For I = 1 To Count
If ExcelSheet.Cells(I + 1, 4).Value = "d" Then
Var_de = Var_de + 1
End If '计算说明书数
If ExcelSheet.Cells(I + 1, 4).Value = "b" Then
Var_be = Var_be + 1
End If '计算概算书数
If ExcelSheet.Cells(I + 1, 4).Value = "t" Then
Var_te = Var_te + 1
End If '计算清册数
If ExcelSheet.Cells(I + 1, 4).Value = "i" Then
Var_ie = Var_ie + 1
End If '计算图纸数
If ExcelSheet.Cells(I + 1, 3).Value <> "" Then
Var_ImgName(I) = ExcelSheet.Cells(I + 1, 3).Value
Else
Var_ImgName(I) = " "
End If '读图名
If ExcelSheet.Cells(I + 1, 2).Value <> "" Then
Var_ImgNo(I) = ExcelSheet.Cells(I + 1, 2).Value
Else
Var_ImgNo(I) = " "
End If '读图号
Next I
ExcelWorkbook.Close False
Excel.Application.Quit
Err_Control:
Err.Clear
Set ExcelWorkbook = Nothing
Set Excel = Nothing
'插入一个块
Dim BasePnt(0 To 2) As Double, BasePnt1(0 To 2) As Double
Dim InsBlk1 As AcadBlockReference, InsBlk2 As AcadBlockReference
BasePnt(0) = ACDTmainForm.X_TextBox.Text
BasePnt(1) = ACDTmainForm.Y_TextBox.Text
BasePnt(2) = ACDTmainForm.Z_TextBox.Text
Set InsBlk1 = ThisDrawing.ModelSpace.InsertBlock(BasePnt, "mlb-1.dwg", 1, 1, 1, 0)
If Count > 28 Then
BasePnt1(0) = ACDTmainForm.X_TextBox.Text + 210
BasePnt1(1) = ACDTmainForm.Y_TextBox.Text
BasePnt1(2) = ACDTmainForm.Z_TextBox.Text
Set InsBlk2 = ThisDrawing.ModelSpace.InsertBlock(BasePnt1, "mlb-2.dwg", 1, 1, 1, 0)
End If
'给块属性赋值的定义部分
Dim Str_pn, Str_ds, Str_zl, Str_zno, Str_cno, Str_zcn As String
Dim Str_ino, Str_pag As String, Var_y, Var_m
Dim Str_ie As String, Str_de As String, Str_te As String, Str_be As String
Dim Ind_pl, Ind_ev, Ind_pno, Ind_ds, Ind_zl, Ind_zno, Ind_cno As String
'给块属性赋值
If ACDTmainForm.TextBox_pn.Text <> "" Then
Str_pn = ACDTmainForm.TextBox_pn.Text
Else
Str_pn = " "
End If '工程名称
If ACDTmainForm.ComboBox_ds.Text <> "" Then
Str_ds = ACDTmainForm.ComboBox_ds.Text
Else
Str_ds = " "
End If
Select Case Str_ds
Case "初步设计"
Ind_ds = "C"
Case "可行性研究"
Ind_ds = "G"
Case "施工图设计"
Ind_ds = "S"
Case Else
Ind_ds = "*"
End Select '设计阶段
If ACDTmainForm.ComboBox_zl.Text <> "" Then
Str_zl = ACDTmainForm.ComboBox_zl.Text
Else
Str_zl = " "
End If
Select Case Str_zl
Case "电气"
Ind_zl = "D"
Case "综合"
Ind_zl = "A"
Case "土建"
Ind_zl = "T"
Case "线路"
Ind_zl = "V"
Case Else
Ind_zl = "*"
End Select '专业类别
If ACDTmainForm.ComboBox_zno.Text <> "" Then
Str_zno = ACDTmainForm.ComboBox_zno.Text
Else
Str_zno = " "
End If
Select Case Str_zno
Case "一"
Ind_zno = "01"
Case "二"
Ind_zno = "02"
Case "三"
Ind_zno = "03"
Case "四"
Ind_zno = "04"
Case "五"
Ind_zno = "05"
Case "六"
Ind_zno = "06"
Case "七"
Ind_zno = "07"
Case "八"
Ind_zno = "08"
Case Else
Ind_zno = "**"
End Select '卷号
If ACDTmainForm.ComboBox_cno.Text <> "" Then
Str_cno = ACDTmainForm.ComboBox_cno.Text
Else
Str_cno = " "
End If
Select Case Str_cno
Case "一"
Ind_cno = "01"
Case "二"
Ind_cno = "02"
Case "三"
Ind_cno = "03"
Case "四"
Ind_cno = "04"
Case "五"
Ind_cno = "05"
Case "六"
Ind_cno = "06"
Case "七"
Ind_cno = "07"
Case "八"
Ind_cno = "08"
Case Else
Ind_cno = "**"
End Select '册号
If ACDTmainForm.TextBox_zcn.Text <> "" Then
Str_zcn = ACDTmainForm.TextBox_zcn.Text
Else
Str_zcn = " "
End If '卷册名称
Select Case CStr(Var_ie)
Case "0"
Str_ie = " "
Case Else
Str_ie = CStr(Var_ie)
End Select '设置图纸数
Select Case CStr(Var_de)
Case "0"
Str_de = " "
Case Else
Str_de = CStr(Var_de)
End Select '设置说明书数
Select Case CStr(Var_te)
Case "0"
Str_te = " "
Case Else
Str_te = CStr(Var_te)
End Select '设置清册数
Select Case CStr(Var_be)
Case "0"
Str_be = " "
Case Else
Str_be = CStr(Var_be)
End Select '设置概算书数
Select Case ACDTmainForm.ComboBox_pl.Text
Case "变电工程"
Ind_pl = "B"
Case "输电工程"
Ind_pl = "S"
Case Else
Ind_pl = "*"
End Select '读工程类别
Select Case ACDTmainForm.ComboBox_ev.Text
Case "0.4kV"
Ind_ev = "1"
Case "6kV"
Ind_ev = "2"
Case "10kV"
Ind_ev = "3"
Case "35kV"
Ind_ev = "4"
Case "110kV"
Ind_ev = "5"
Case "220kV"
Ind_ev = "6"
Case Else
Ind_ev = "*"
End Select '读电压等级
If ACDTmainForm.TextBox_pno.Text <> "" Then
Ind_pno = ACDTmainForm.TextBox_pno.Text
Else
Ind_pno = "***"
End If '读工程序号
Str_ino = Ind_pl + Ind_ev + Ind_pno + Ind_ds + "-" + Ind_zl + Ind_zno + Ind_cno '设置卷册检索号
If Count < 28 Then
Str_pag = "1"
Else
Str_pag = "2"
End If '设置总页数
Var_y = Year(Now) '设置年
Var_m = Month(Now) '设置月
'更改块属性
Dim Att_Var1 As Variant, Att_Var2 As Variant
Att_Var1 = InsBlk1.GetAttributes
Att_Var1(0).TextString = Str_pn
Att_Var1(1).TextString = Str_ds
Att_Var1(2).TextString = Str_zl
Att_Var1(3).TextString = Str_zno
Att_Var1(4).TextString = Str_cno
Att_Var1(5).TextString = Str_zcn
Att_Var1(6).TextString = Str_ie
Att_Var1(7).TextString = Str_de
Att_Var1(8).TextString = Str_te
Att_Var1(9).TextString = Str_be
Att_Var1(10).TextString = Str_ino
Att_Var1(11).TextString = "1"
Att_Var1(12).TextString = Str_pag
Att_Var1(13).TextString = CStr(Var_y)
Att_Var1(14).TextString = CStr(Var_m)
If Count > 28 Then
Att_Var2 = InsBlk2.GetAttributes
Att_Var2(0).TextString = Str_pn
Att_Var2(1).TextString = Str_ds
Att_Var2(2).TextString = Str_zl
Att_Var2(3).TextString = Str_zno
Att_Var2(4).TextString = Str_cno
Att_Var2(5).TextString = Str_zcn
Att_Var2(6).TextString = Str_ino
Att_Var2(7).TextString = "2"
Att_Var2(8).TextString = Str_pag
Att_Var2(9).TextString = CStr(Var_y)
Att_Var2(10).TextString = CStr(Var_m)
End If
'写目录数据
Dim TextObj As AcadText
Dim Num_Str As String
Dim Ins_Pnt1(0 To 2) As Double, Ins_Pnt2(0 To 2) As Double
Dim Ins_Pnt3(0 To 2) As Double, Ins_Pnt4(0 To 2) As Double
Dim Height As Double
Height = 2.5 '确定字体高度
'确定文字初始位置
Ins_Pnt1(0) = BasePnt(0) + 40
Ins_Pnt1(1) = BasePnt(1) + 207
Ins_Pnt1(2) = 0
Ins_Pnt2(0) = Ins_Pnt1(0) + 25
Ins_Pnt2(1) = Ins_Pnt1(1)
Ins_Pnt2(2) = 0
Ins_Pnt3(0) = Ins_Pnt2(0) + 22
Ins_Pnt3(1) = Ins_Pnt1(1)
Ins_Pnt3(2) = 0
Ins_Pnt4(0) = Ins_Pnt3(0) + 83
Ins_Pnt4(1) = Ins_Pnt1(1)
Ins_Pnt4(2) = 0
If Count < 28 Then '如果只有一页目录
For I = 1 To Count '写第一页目录
Set TextObj = ThisDrawing.ModelSpace.AddText(CStr(I), Ins_Pnt1, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt1
Set TextObj = ThisDrawing.ModelSpace.AddText(Var_ImgNo(I), Ins_Pnt2, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt2
Set TextObj = ThisDrawing.ModelSpace.AddText(Var_ImgName(I), Ins_Pnt3, Height)
TextObj.Alignment = acAlignmentMiddleLeft
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt3
Set TextObj = ThisDrawing.ModelSpace.AddText("1", Ins_Pnt4, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt4
Ins_Pnt1(1) = Ins_Pnt1(1) - 7
Ins_Pnt2(1) = Ins_Pnt2(1) - 7
Ins_Pnt3(1) = Ins_Pnt3(1) - 7
Ins_Pnt4(1) = Ins_Pnt4(1) - 7
Next I
Else '如果存在第二页目录
For I = 1 To 28 '先写第一页目录
Set TextObj = ThisDrawing.ModelSpace.AddText(CStr(I), Ins_Pnt1, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt1
Set TextObj = ThisDrawing.ModelSpace.AddText(Var_ImgNo(I), Ins_Pnt2, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt2
Set TextObj = ThisDrawing.ModelSpace.AddText(Var_ImgName(I), Ins_Pnt3, Height)
TextObj.Alignment = acAlignmentMiddleLeft
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt3
Set TextObj = ThisDrawing.ModelSpace.AddText("1", Ins_Pnt4, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt4
Ins_Pnt1(1) = Ins_Pnt1(1) - 7
Ins_Pnt2(1) = Ins_Pnt2(1) - 7
Ins_Pnt3(1) = Ins_Pnt3(1) - 7
Ins_Pnt4(1) = Ins_Pnt4(1) - 7
Next I
Ins_Pnt1(0) = Ins_Pnt1(0) + 210
Ins_Pnt1(1) = Ins_Pnt1(1) + 217
Ins_Pnt2(0) = Ins_Pnt2(0) + 210
Ins_Pnt2(1) = Ins_Pnt2(1) + 217
Ins_Pnt3(0) = Ins_Pnt3(0) + 210
Ins_Pnt3(1) = Ins_Pnt3(1) + 217
Ins_Pnt4(0) = Ins_Pnt4(0) + 210
Ins_Pnt4(1) = Ins_Pnt4(1) + 217
For I = 29 To Count '写第二页目录
Set TextObj = ThisDrawing.ModelSpace.AddText(CStr(I), Ins_Pnt1, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt1
Set TextObj = ThisDrawing.ModelSpace.AddText(Var_ImgNo(I), Ins_Pnt2, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt2
Set TextObj = ThisDrawing.ModelSpace.AddText(Var_ImgName(I), Ins_Pnt3, Height)
TextObj.Alignment = acAlignmentMiddleLeft
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt3
Set TextObj = ThisDrawing.ModelSpace.AddText("1", Ins_Pnt4, Height)
TextObj.Alignment = acAlignmentMiddle
TextObj.ScaleFactor = 0.9
TextObj.ObliqueAngle = 0.175
TextObj.TextAlignmentPoint = Ins_Pnt4
Ins_Pnt1(1) = Ins_Pnt1(1) - 7
Ins_Pnt2(1) = Ins_Pnt2(1) - 7
Ins_Pnt3(1) = Ins_Pnt3(1) - 7
Ins_Pnt4(1) = Ins_Pnt4(1) - 7
Next I
End If
'关闭本窗口
Unload Me
End Sub |
|