Private Sub Command1_Click()
'---------------------------------------------------
'Еще один пример печати отчета без Crystal
Report.
'Интересен тем, что во втором столбце
печатаемой
'таблицы могут быть длинные строки, в
которых надо
'переносить слова не разрезая, но
нумерация в первом
'столбце должна появляться один раз.
Поскольку
'отчеты могут быть различны по объему,
организована
'постраничная печать с ориентацией на
количество
'строк, выдаваемых не лучшим принтером.
'---------------------------------------------------
DBGrid1.Visible = False
Dim c, r, n, s, p, sum, rab, raz, l As Integer
Dim str, str1, str2, str3, razstr1, razstr2, razstr3, str0 As String
Dim ch, ost As Currency
Printer.FontName = "Times New Roman cyr"
Printer.FontSize = 12
Printer.FontBold = False
Printer.CurrentX = Printer.Width * 0.02 * 12
Printer.CurrentY = Printer.Height * 0.02 * 1
Printer.Print "Сметная стоимость
выполнения ремонтно-отделочных работ"
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 *
3)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * 3)
Printer.DrawWidth = 1
Printer.CurrentX = Printer.Width * 0.02 * 6.2
Printer.CurrentY = Printer.Height * 0.02 * 3.2
Printer.Print "№"
Printer.CurrentX = Printer.Width * 0.02 * 8.2
Printer.CurrentY = Printer.Height * 0.02 * 3.2
Printer.Print "Вид работ"
Printer.CurrentX = Printer.Width * 0.02 * 30.2
Printer.CurrentY = Printer.Height * 0.02 * 3.2
Printer.Print "Цена"
Printer.CurrentX = Printer.Width * 0.02 * 35.2
Printer.CurrentY = Printer.Height * 0.02 * 3.2
Printer.Print "Количество"
Printer.CurrentX = Printer.Width * 0.02 * 41.2
Printer.CurrentY = Printer.Height * 0.02 * 3.2
Printer.Print "Сумма"
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 *
4)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * 4)
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 *
3)-(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * 4)
Printer.DrawWidth = 1
Printer.Line (Printer.Width * 0.02 * 8, Printer.Height * 0.02 *
3)-(Printer.Width * 0.02 * 8, Printer.Height * 0.02 * 4)
Printer.Line (Printer.Width * 0.02 * 30, Printer.Height * 0.02 *
3)-(Printer.Width * 0.02 * 30, Printer.Height * 0.02 * 4)
Printer.Line (Printer.Width * 0.02 * 41, Printer.Height * 0.02 *
3)-(Printer.Width * 0.02 * 41, Printer.Height * 0.02 * 4)
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 46, Printer.Height * 0.02 *
3)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * 4)
Printer.DrawWidth = 1
Printer.Line (Printer.Width * 0.02 * 35, Printer.Height * 0.02 *
3)-(Printer.Width * 0.02 * 35, Printer.Height * 0.02 * 4)
c = 0
r = 0
n = 0
s = 4
p = 1
sum = 0
30 Printer.FontBold = False
If c = 7 Then GoTo 35
DBGrid1.Col = c
On Error GoTo ColsError
DBGrid1.Row = r
If c > 0 Then
str = DBGrid1.Text
Else
c = c + 1
GoTo 30
End If
If str = "" Then GoTo 70
If c = 2 Then
n = 8
rab = Len(str)
If rab > 43 Then GoTo 51
GoTo 50
End If
If c = 3 Then
n = 30
'Перевод в денежную форму
ch = (Int(str * 100)) / 100
ost = str - ch
If ost >= 0.005 Then ch = ch + 0.01
str = ch
If InStr(1, str, ",") = 0 Then
str = str &
"-" & "00"
End If
If InStr(1, str, ",") > 0 Then
str = Left(str,
(InStr(1, str, ",")) - 1) & "-" & Right(str, Len(str) -
InStr(1, str, ","))
End If
If Len(Right(str, Len(str) - InStr(1, str,
"-"))) = 1 Then
str = Left(str,
InStr(1, str, "-")) & Right(str, Len(str) - InStr(1, str, "-"))
& "0"
End If
If InStr(1, str, "-") = 2 Then str =
" " & str
If InStr(1, str, "-") = 3 Then str =
" " & str
If InStr(1, str, "-") = 4 Then str =
" " & str
If InStr(1, str, "-") = 5 Then str =
" " & str
GoTo 52
End If
If c = 4 Then
n = 35
GoTo 52
End If
If c = 5 Then
n = 38
GoTo 52
End If
If c = 6 Then
n = 41
sum = sum + str
'Перевод в денежную форму
ch = (Int(str * 100)) / 100
ost = str - ch
If ost >= 0.005 Then ch = ch + 0.01
str = ch
If InStr(1, str, ",") = 0 Then
str = str &
"=" & "00"
End If
If InStr(1, str, ",") > 0 Then
str = Left(str,
(InStr(1, str, ",")) - 1) & "=" & Right(str, Len(str) -
InStr(1, str, ","))
End If
If Len(Right(str, Len(str) - InStr(1, str,
"="))) = 1 Then
str = Left(str,
InStr(1, str, "=")) & Right(str, Len(str) - InStr(1, str, "="))
& "0"
End If
If InStr(1, str, "=") = 2 Then str =
" " & str
If InStr(1, str, "=") = 3 Then str =
" " & str
If InStr(1, str, "=") = 4 Then str =
" " & str
If InStr(1, str, "=") = 5 Then str =
" " & str
GoTo 52
End If
If c = 1 Then
If s > 41 Then
s = s - 1
Printer.DrawWidth = 2
Printer.Line
(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s + 1))-(Printer.Width * 0.02 * 46,
Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 1
Printer.NewPage
s = 2
Printer.DrawWidth = 2
Printer.Line
(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * 1)-(Printer.Width * 0.02 * 46,
Printer.Height * 0.02 * 1)
Printer.DrawWidth = 1
Printer.CurrentX =
Printer.Width * 0.02 * 6.2
Printer.CurrentY =
Printer.Height * 0.02 * 1.2
Printer.Print
"№"
Printer.CurrentX =
Printer.Width * 0.02 * 8.2
Printer.CurrentY =
Printer.Height * 0.02 * 1.2
Printer.Print
"Вид работ"
Printer.CurrentX =
Printer.Width * 0.02 * 30.2
Printer.CurrentY =
Printer.Height * 0.02 * 1.2
Printer.Print
"Цена"
Printer.CurrentX =
Printer.Width * 0.02 * 35.2
Printer.CurrentY =
Printer.Height * 0.02 * 1.2
Printer.Print
"Количество"
Printer.CurrentX =
Printer.Width * 0.02 * 41.2
Printer.CurrentY =
Printer.Height * 0.02 * 1.2
Printer.Print
"Сумма"
Printer.DrawWidth = 2
Printer.Line
(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * 2)-(Printer.Width * 0.02 * 46,
Printer.Height * 0.02 * 2)
Printer.Line
(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * 1)-(Printer.Width * 0.02 * 6,
Printer.Height * 0.02 * 2)
Printer.DrawWidth = 1
Printer.Line
(Printer.Width * 0.02 * 8, Printer.Height * 0.02 * 1)-(Printer.Width * 0.02 * 8,
Printer.Height * 0.02 * 2)
Printer.Line
(Printer.Width * 0.02 * 30, Printer.Height * 0.02 * 1)-(Printer.Width * 0.02 * 30,
Printer.Height * 0.02 * 2)
Printer.Line
(Printer.Width * 0.02 * 41, Printer.Height * 0.02 * 1)-(Printer.Width * 0.02 * 41,
Printer.Height * 0.02 * 2)
Printer.DrawWidth = 2
Printer.Line
(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * 1)-(Printer.Width * 0.02 * 46,
Printer.Height * 0.02 * 2)
Printer.DrawWidth = 1
Printer.Line
(Printer.Width * 0.02 * 35, Printer.Height * 0.02 * 1)-(Printer.Width * 0.02 * 35,
Printer.Height * 0.02 * 2)
End If
If str1 = str Then
c = 2
GoTo 30
End If
End If
Printer.CurrentX = Printer.Width * 0.02 * 8.2
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
str3 = UCase(str)
Printer.FontBold = True
Printer.Print str3
Printer.FontBold = False
str1 = str
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s +
1))-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 46, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 1
Printer.Line (Printer.Width * 0.02 * 8, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 8, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 30, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 30, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 41, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 41, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 35, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 35, Printer.Height * 0.02 * (s + 1))
c = c + 1
s = s + 1
p = 1
GoTo 30
50 Printer.CurrentX = Printer.Width * 0.02 * (n + 0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
Printer.Print str
Printer.CurrentX = Printer.Width * 0.02 * (6 + 0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
Printer.Print p
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s +
1))-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 46, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 1
Printer.Line (Printer.Width * 0.02 * 8, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 8, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 30, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 30, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 41, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 41, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 35, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 35, Printer.Height * 0.02 * (s + 1))
c = c + 1
GoTo 30
'Операция разрезания строк в одном из
столбцов таблицы
51 str0 = Left(str, 43)
raz = InStr(40, str0, " ")
If raz = 0 Then
raz = InStr(37, str0, " ")
End If
If raz = 0 Then
raz = InStr(34, str0, " ")
End If
If raz = 0 Then
raz = InStr(31, str0, " ")
End If
razstr1 = Left(str, (raz - 1))
Printer.CurrentX = Printer.Width * 0.02 * (n + 0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
Printer.Print razstr1
Printer.CurrentX = Printer.Width * 0.02 * (6 + 0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
Printer.Print p
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 46, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 1
Printer.Line (Printer.Width * 0.02 * 8, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 8, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 30, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 30, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 41, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 41, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 35, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 35, Printer.Height * 0.02 * (s + 1))
s = s + 1
razstr2 = Mid(str, raz)
rab = Len(razstr2)
If rab > 43 Then
str0 = Left(razstr2, 43)
raz = InStr(40, str0, " ")
If raz = 0 Then
raz = InStr(37, str0, " ")
End If
If raz = 0 Then
raz = InStr(34, str0, " ")
End If
If raz = 0 Then
raz = InStr(31, str0, " ")
End If
razstr3 = Mid(razstr2, raz)
str0 = Left(razstr2, (raz - 1))
razstr2 = str0
l = 1
Else
Printer.Line (Printer.Width * 0.02 * 6,
Printer.Height * 0.02 * (s + 1))-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s +
1))
End If
Printer.CurrentX = Printer.Width * 0.02 * (n + 0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
Printer.Print razstr2
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 46, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 1
Printer.Line (Printer.Width * 0.02 * 8, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 8, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 30, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 30, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 41, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 41, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 35, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 35, Printer.Height * 0.02 * (s + 1))
If l = 1 Then
l = 0
s = s + 1
Printer.CurrentX = Printer.Width * 0.02 * (n +
0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s +
0.2)
Printer.Print razstr3
Printer.Line (Printer.Width * 0.02 * 6,
Printer.Height * 0.02 * (s + 1))-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s +
1))
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 6,
Printer.Height * 0.02 * s)-(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 46,
Printer.Height * 0.02 * s)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 1
Printer.Line (Printer.Width * 0.02 * 8,
Printer.Height * 0.02 * s)-(Printer.Width * 0.02 * 8, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 30,
Printer.Height * 0.02 * s)-(Printer.Width * 0.02 * 30, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 41,
Printer.Height * 0.02 * s)-(Printer.Width * 0.02 * 41, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 35,
Printer.Height * 0.02 * s)-(Printer.Width * 0.02 * 35, Printer.Height * 0.02 * (s + 1))
End If
c = c + 1
GoTo 30
52 Printer.CurrentX = Printer.Width * 0.02 * (n + 0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
Printer.Print str
c = c + 1
GoTo 30
35 r = r + 1
c = 0
s = s + 1
p = p + 1
GoTo 30
70 Printer.EndDoc
ColsError:
Printer.CurrentX = Printer.Width * 0.02 * (8 + 0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
Printer.Print "Итого:"
Printer.CurrentX = Printer.Width * 0.02 * (41 + 0.2)
Printer.CurrentY = Printer.Height * 0.02 * (s + 0.2)
sum = Int(sum)
Printer.Print sum;
Printer.Print "р."
Printer.DrawWidth = 2
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s +
1))-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 6, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 6, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 46, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 46, Printer.Height * 0.02 * (s + 1))
Printer.DrawWidth = 1
Printer.Line (Printer.Width * 0.02 * 8, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 8, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 30, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 30, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 41, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 41, Printer.Height * 0.02 * (s + 1))
Printer.Line (Printer.Width * 0.02 * 35, Printer.Height * 0.02 *
s)-(Printer.Width * 0.02 * 35, Printer.Height * 0.02 * (s + 1))
s = s + 2
If s > 43 Then
s = 1
Printer.NewPage
End If
Printer.CurrentX = Printer.Width * 0.02 * 6
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "Примечание:"
s = s + 1
Printer.CurrentX = Printer.Width * 0.02 * 6
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "1. Сметная стоимость
выполняемых ремонтно-отделочных работ не
включает"
s = s + 1
Printer.CurrentX = Printer.Width * 0.02 * 6
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "стоимость материалов."
s = s + 2
If s > 42 Then
s = 1
Printer.NewPage
End If
Printer.CurrentX = Printer.Width * 0.02 * 6
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "Заказчик"
Printer.CurrentX = Printer.Width * 0.02 * 30
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "Исполнитель"
s = s + 1
Printer.CurrentX = Printer.Width * 0.02 * 6
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "(_____)__________19 г."
Printer.CurrentX = Printer.Width * 0.02 * 30
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "(_____)__________19 г."
s = s + 1
Printer.CurrentX = Printer.Width * 0.02 * 6
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "_______________"
Printer.CurrentX = Printer.Width * 0.02 * 30
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print "_______________"
s = s + 1
Printer.CurrentX = Printer.Width * 0.02 * 6
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print " (подпись)"
Printer.CurrentX = Printer.Width * 0.02 * 30
Printer.CurrentY = Printer.Height * 0.02 * s
Printer.Print " (подпись)"
Printer.EndDoc
DBGrid1.Visible = True
Exit Sub
End Sub