Documente Academic
Documente Profesional
Documente Cultură
Programarea procedurală
Chişinău 2022
Introducere
Sarcina acestei lucrări de laborator este crearea unei aplicații ce va rula în Excel și
va folosi un șir de funcții definite de programator destinate prelucrării vectorilor în
Excel.
Sarcina individuală:
1. Elaboraţi forma propusă în lucrare.
2. Comentaţi detaliat codurile associate obiectelor formei propuse
3. Modificaţi forma şi codul respectiv pentru adăugarea cel puţin a doua
obiecte/evenimente.
4. Faceţi concluzii
5. Prezentaţi lucrarea profesorului.
1
Descrierea aplicaţiei create:
2
Pagina Scale vector conține 2 cîmpuri de text unde utilizatorul trebuie să introducă constanta la care
va fi înmulțit vectorul și numărul coloanei unde va fi inserat vectorul scalarizat. Apăsînd pe butonul
”Scale” în coloana indicată va fi inserat vectorul scalarizat.
3
coloanei unde va fi inserat vectorul. Apăsînd pe butonul ”Produs” în coloana indicată va fi inserat
vectorul inmultit.
Rezultatele obținute:
4
Figura 2: Screenshot pentru functia Scale
5
Figura 5: Screenshot pentru functia MinMax
6
Figura 7: Screenshot pentru functia Produs
Concluzie
Anexa Codului
8
Public Function Suma2Vec(rng As Range, rng2 As Range) As Variant
Dim i As Integer
Dim n As Integer
n = rng.Rows.Count
ReDim vect(1 To n) As Double
ReDim vect2(1 To n) As Double
ReDim Suma(1 To n) As Double
For i = 1 To n
vect(i) = rng(i)
vect2(i) = rng2(i)
Suma(i) = vect(i) + vect2(i)
Next i
Suma2Vec = Suma
End Function
Public Function ScaleVector(rng As Range, sc As Double) As Variant
Dim i As Integer
Dim n As Integer
n = rng.Rows.Count
ReDim vect(1 To n) As Double
For i = 1 To n: vect(i) = rng(i): Next i
ReDim scaled(1 To n) As Variant
For i = 1 To n
scaled(i) = sc * vect(i)
Next i
ScaleVector = scaled
End Function
Public Function Bubble(rng As Range) As Variant
Dim n As Integer
Dim i As Integer, j As Integer
Dim Temp As Double
n = rng.Rows.Count
ReDim vect(1 To n) As Double
For i = 1 To n: vect(i) = rng(i): Next i
For i = 1 To n - 1
For j = i + 1 To n
If vect(i) > vect(j) Then
Temp = vect(j)
vect(j) = vect(i)
vect(i) = Temp
End If
Next j
Next i
Bubble = vect
End Function
Public Function ScadConst(rng As Range, sc As Double)
Dim i As Integer
Dim n As Integer
n = rng.Rows.Count
9
For i = 1 To n
scazut(i) = vect(i) - sc
Next i
ScadConst = scazut
End Function
End Function
Private Sub CommandButton1_Click()
Dim c As Double
Dim n As Double
Dim col As Integer
Dim vect As Range
Set vect = Selection
n = vect.Rows.Count
c = TextBox8.Value
ReDim prod(1 To n) As Double
scad = ScadConst(vect, c)
col = TextBox7.Value
Cells(1, col).Value = "scaderea "
For i = 1 To n
Cells(i + 1, col).Value = scad(i)
Next i
End Sub
Private Sub CommandButton2_Click()
Dim c As Double
Dim n As Double
Dim col As Integer
Dim vect As Range
Set vect = Selection
n = vect.Rows.Count
c = TextBox9.Value
ReDim prod(1 To n) As Double
prod = ProdConst(vect, c)
col = TextBox10.Value
Cells(1, col).Value = "produsul "
For i = 1 To n
Cells(i + 1, col).Value = prod(i)
Next i
10
End Sub
11
Dim col As Integer
Set vect1 = Range(TextBox3.Value)
Set vect2 = Range(TextBox4.Value)
rez = Suma2Vec(vect1, vect2)
If (VarType(rez) = vbString) Then
MsgBox rez
Else
col = TextBox5.Value
Cells(i + 1, col).Value = "Suma a 2 vectori"
For i = 1 To vect1.Rows.Count
Cells(i + 1, col).Value = rez(i)
Next i
End If
End Sub
Private Sub UserForm1_Activate()
Set vect = Worksheets("sheet1").Range(ActiveWindow.RangeSelection.Address)
End Sub
End Sub
End Sub
End Sub
12