'Следующий код должен быть в модуле книги 'Константы единичных значений битов
Const BIT_0 As Byte = 1 Const BIT_1 As Byte = 2 Const BIT_2 As Byte = 4 Const BIT_3 As Byte = 8 Const BIT_4 As Byte = 16 Const BIT_5 As Byte = 32 Const BIT_6 As Byte = 64 Const BIT_7 As Byte = 128 Const Pi = 3.141592653589 'число Пи Const period = 60.9756 'период выборок в мкС Private Sub PrintFile(ByVal Filename As String) Dim viborka As Integer Dim sin_byte As Byte Dim cos_byte As Byte
Dim ws As Worksheet
'Находим в книге рабочий лист For Each ws In Me.Worksheets If ws.Type = xlWorksheet Then GoTo PF Next ws MsgBox "Не найдено ни одного рабочего листа." Exit Sub PF:
On Error GoTo err_PrintFile 'Пишем в файл Open Filename For Binary As #1 For viborka = 1 To 164 bit0 = IIf((Sin(2 * Pi * 700 * period * viborka)) > 0, BIT_0, 0) bit1 = IIf((Sin(2 * Pi * 900 * period * viborka)) > 0, BIT_1, 0) bit2 = IIf((Sin(2 * Pi * 1100 * period * viborka)) > 0, BIT_2, 0) bit3 = IIf((Sin(2 * Pi * 1300 * period * viborka)) > 0, BIT_3, 0) bit4 = IIf((Sin(2 * Pi * 1500 * period * viborka)) > 0, BIT_4, 0) bit5 = IIf((Sin(2 * Pi * 1700 * period * viborka)) > 0, BIT_5, 0) bit6 = 0 bit7 = 0 sin_byte = bit0 Or bit1 Or bit2 Or bit3 Or bit4 Or bit5 Or bit6 Or bit7
Put #1, viborka, sin_byte ws.Cells(viborka, 1).Value = sin_byte Next viborka For viborka = 1 To 164 bit0 = IIf((Cos(2 * Pi * 700 * period * viborka)) > 0, BIT_0, 0) bit1 = IIf((Cos(2 * Pi * 900 * period * viborka)) > 0, BIT_1, 0) bit2 = IIf((Cos(2 * Pi * 1100 * period * viborka)) > 0, BIT_2, 0) bit3 = IIf((Cos(2 * Pi * 1300 * period * viborka)) > 0, BIT_3, 0) bit4 = IIf((Cos(2 * Pi * 1500 * period * viborka)) > 0, BIT_4, 0) bit5 = IIf((Cos(2 * Pi * 1700 * period * viborka)) > 0, BIT_5, 0) bit6 = 0 bit7 = 0 cos_byte = bit0 Or bit1 Or bit2 Or bit3 Or bit4 Or bit5 Or bit6 Or bit7
Put #1, viborka + 164, cos_byte ws.Cells(viborka, 2).Value = cos_byte Next viborka
Close Exit Sub err_PrintFile:
MsgBox "Ошибка записи в файл." Close End Sub Public Sub Run()
'Запуск макроса PrintFile "sin_cos.bin" End Sub'Следующий код должен быть в модуле книги 'Константы единичных значений битов
Const BIT_0 As Byte = 1 Const BIT_1 As Byte = 2 Const BIT_2 As Byte = 4 Const BIT_3 As Byte = 8 Const BIT_4 As Byte = 16 Const BIT_5 As Byte = 32 Const BIT_6 As Byte = 64 Const BIT_7 As Byte = 128 Const Pi = 3.141592653589 'число Пи Const period = 60.9756 'период выборок в мкС Private Sub PrintFile(ByVal Filename As String) Dim viborka As Integer Dim sin_byte As Byte Dim cos_byte As Byte
Dim ws As Worksheet
'Находим в книге рабочий лист For Each ws In Me.Worksheets If ws.Type = xlWorksheet Then GoTo PF Next ws MsgBox "Не найдено ни одного рабочего листа." Exit Sub PF:
On Error GoTo err_PrintFile 'Пишем в файл Open Filename For Binary As #1 For viborka = 1 To 164 bit0 = IIf((Sin(2 * Pi * 700 * period * viborka)) > 0, BIT_0, 0) bit1 = IIf((Sin(2 * Pi * 900 * period * viborka)) > 0, BIT_1, 0) bit2 = IIf((Sin(2 * Pi * 1100 * period * viborka)) > 0, BIT_2, 0) bit3 = IIf((Sin(2 * Pi * 1300 * period * viborka)) > 0, BIT_3, 0) bit4 = IIf((Sin(2 * Pi * 1500 * period * viborka)) > 0, BIT_4, 0) bit5 = IIf((Sin(2 * Pi * 1700 * period * viborka)) > 0, BIT_5, 0) bit6 = 0 bit7 = 0 sin_byte = bit0 Or bit1 Or bit2 Or bit3 Or bit4 Or bit5 Or bit6 Or bit7
Put #1, viborka, sin_byte ws.Cells(viborka, 1).Value = sin_byte Next viborka For viborka = 1 To 164 bit0 = IIf((Cos(2 * Pi * 700 * period * viborka)) > 0, BIT_0, 0) bit1 = IIf((Cos(2 * Pi * 900 * period * viborka)) > 0, BIT_1, 0) bit2 = IIf((Cos(2 * Pi * 1100 * period * viborka)) > 0, BIT_2, 0) bit3 = IIf((Cos(2 * Pi * 1300 * period * viborka)) > 0, BIT_3, 0) bit4 = IIf((Cos(2 * Pi * 1500 * period * viborka)) > 0, BIT_4, 0) bit5 = IIf((Cos(2 * Pi * 1700 * period * viborka)) > 0, BIT_5, 0) bit6 = 0 bit7 = 0 cos_byte = bit0 Or bit1 Or bit2 Or bit3 Or bit4 Or bit5 Or bit6 Or bit7
Put #1, viborka + 164, cos_byte ws.Cells(viborka, 2).Value = cos_byte Next viborka
Close Exit Sub err_PrintFile:
MsgBox "Ошибка записи в файл." Close End Sub Public Sub Run()
'Запуск макроса PrintFile "sin_cos.bin" End Sub
Ответить
|