<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBA: Операции реляционной алгебры]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=18304</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=18304&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBA: Операции реляционной алгебры».]]></description>
		<lastBuildDate>Tue, 24 Sep 2024 13:13:31 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[VBA: Операции реляционной алгебры]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=161639#p161639</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (gamesszedlak)]]></author>
			<pubDate>Tue, 24 Sep 2024 13:13:31 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=161639#p161639</guid>
		</item>
	</channel>
</rss>
