<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBA: Операции реляционной алгебры]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=18304&amp;type=atom" />
	<updated>2024-09-24T13:13:31Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=18304</id>
		<entry>
			<title type="html"><![CDATA[VBA: Операции реляционной алгебры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=161639#p161639" />
			<content type="html"><![CDATA[<p>Здравствуйте, помогите пожалуйста, необходимо написать код, для VBA на основании таблиц A и B, должны быть сделаны операции, а именно пересечение, объединение, разность и произведение, как видите реализация только пересечение, и объединение(код представлен ниже), но слегка с ошибками, разность и произведение, просто нет возможности сделать?</p><div class="codebox"><pre><code>
Sub Start()
Dim A() As String
Dim B() As String
Dim ASB() As String
Dim AUB() As String
i% = 3

Do
If Cells(i%, 2).Value = &quot;&quot; Then
n% = i% - 3
Exit Do
End If
i% = i% + 1
Loop

If n% = 0 Then
MsgBox &quot;?????? A ????&quot;
Exit Sub
End If

i% = 3
Do
If Cells(i%, 4).Value = &quot;&quot; Then
m% = i% - 3
Exit Do
End If
i% = i% + 1
Loop

If m% = 0 Then
MsgBox &quot;?????? B ????&quot;
Exit Sub
End If

&#039; ??????????????? ??????????? ????????
ReDim A(1 To n%, 1 To 2) As String
ReDim B(1 To m%, 1 To 2) As String
ReDim ASB(1 To n% + m%, 1 To 2) As String
ReDim AUB(1 To n% + m%, 1 To 2) As String

&#039; ?????? ?????? ?? ????? ? ???????
For i% = 1 To n%
A(i%, 1) = Cells(i% + 2, 2)
A(i%, 2) = Cells(i% + 2, 3)
Next i%

For i% = 1 To m%
B(i%, 1) = Cells(i% + 2, 4)
B(i%, 2) = Cells(i% + 2, 5)
Next i%

&#039;???????? ?????? ??????

Range(&quot;F3:I40&quot;).Select
Selection.ClearContents
Range(&quot;A1&quot;).Select

&#039; ????? ???????????

Intersect A(), B(), ASB(), k1%


&#039; ????? ??????????? ?????????
For i% = 1 To k1%
Cells(i% + 2, 6) = ASB(i%, 1)
Cells(i% + 2, 7) = ASB(i%, 2)
Next i%

&#039;For i% = 1 To k2%
&#039;Cells(i% + 2, 8) = AUB(i%, 1)
&#039;Cells(i% + 2, 9) = AUB(i%, 2)
&#039;Next i%


End Sub

&#039;::: ??????????? A ? B -&gt; AB

Sub Intersect(A() As String, B() As String, AB() As String, k As Integer)
k% = 0
For i% = 1 To UBound(A, 1)
aa = A(i%, 1)
a1 = A(i%, 2)
q% = 0
For j% = 1 To UBound(B, 1)
If B(j%, 1) = aa Then
q% = -1
Exit For
End If
Next j%
If (q% &lt;&gt; 0) Then
q% = 0
For j% = 1 To k%
If AB(j%, 1) = aa Then
q% = -1
Exit For
End If
Next j%
If (q% = 0) Then
k% = k% + 1
AB(k%, 1) = aa
AB(k%, 2) = a1
End If
End If
Next i%

Range(&quot;H3&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;H4&quot;).Select
Range(&quot;H3&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;I3&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;H4&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;I4&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;H5&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;I5&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;H6&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;I6&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;H7&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;I7&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=RC[-6]&quot;
Range(&quot;H8&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-5]C[-4]&quot;
Range(&quot;I8&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-5]C[-4]&quot;
Range(&quot;H9&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-5]C[-4]&quot;
Range(&quot;I9&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-5]C[-4]&quot;
Range(&quot;H10&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-5]C[-4]&quot;
Range(&quot;I10&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-5]C[-4]&quot;
Range(&quot;H11&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=&quot;
Range(&quot;H10&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-4]C[-4]&quot;
Range(&quot;I10&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-4]C[-4]&quot;
Range(&quot;H11&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-4]C[-4]&quot;
Range(&quot;I11&quot;).Select
ActiveCell.FormulaR1C1 = &quot;=R[-4]C[-4]&quot;
Range(&quot;I12&quot;).Select

End Sub


</code></pre></div>]]></content>
			<author>
				<name><![CDATA[gamesszedlak]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=44110</uri>
			</author>
			<updated>2024-09-24T13:13:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=161639#p161639</id>
		</entry>
</feed>
