This document contains code for a class called Formgrid that performs operations on grid controls. It includes two button click event handlers. Button1_Click copies values from one grid to another and calculates a sum. Button2_Click copies grid values, finds minimum and maximum values, and performs additional calculations to determine a final sum value. Both methods copy grid cell values, calculate intermediate sums, and display the final sum in a textbox.
This document contains code for a class called Formgrid that performs operations on grid controls. It includes two button click event handlers. Button1_Click copies values from one grid to another and calculates a sum. Button2_Click copies grid values, finds minimum and maximum values, and performs additional calculations to determine a final sum value. Both methods copy grid cell values, calculate intermediate sums, and display the final sum in a textbox.
This document contains code for a class called Formgrid that performs operations on grid controls. It includes two button click event handlers. Button1_Click copies values from one grid to another and calculates a sum. Button2_Click copies grid values, finds minimum and maximum values, and performs additional calculations to determine a final sum value. Both methods copy grid cell values, calculate intermediate sums, and display the final sum in a textbox.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
a = Grid1.ColumnCount b = Grid1.RowCount 'Grid3.Visible = True Grid4.Visible = True Grid4.Location = Grid3.Location Grid3.ColumnCount = a 'Determina el nmero de columnas matriz aux Grid3.RowCount = b 'Determina el nmero de filas matriz aux Grid4.ColumnCount = a 'Determina el nmero de columnas matriz aux Grid4.RowCount = b 'Determina el nmero de filas matriz aux For i = 0 To a - 1 'Copia los valores de una matriz a otra For j = 0 To b - 1 Grid3(i, j).Value = "" Grid3(i, j).Value = Grid1(i, j).Value Grid4(i, j).Value = "" If i = a - 1 Or j = b - 2 Then Grid4(i, j).Value = Grid1(i, j).Value End If Next Next alto = 0 t=0 s=0 Do While t < a + b - 4 If t = 0 Then min = Grid1(0, 0).Value 'inicializa el mnimo Else min = alto End If max = 0 'inicializa el mximo For i = 0 To a - 2 'Determina el mnimo y mximo matriz original For j = 0 To b - 3 If Grid3(i, j).Value >= max Then max = Grid3(i, j).Value End If If Grid3(i, j).Value <= min Then min = Grid3(i, j).Value i1 = i j1 = j End If Next Next If t = 0 Then alto = max + 10 End If k3 = Grid3(i1, b - 2).Value k4 = Grid3(a - 1, j1).Value 'Finaliza el mnimo y mximo matriz original If k3 > k4 Then Grid3(i1, b - 2).Value = k3 - k4 Grid3(a - 1, j1).Value = 0 Grid4(i1, j1).Value = k4 For m = 0 To a - 2 Grid3(m, j1).Value = alto Next Else Grid3(i1, b - 2).Value = 0 Grid3(a - 1, j1).Value = k4 - k3 Grid4(i1, j1).Value = k3 For n = 0 To b - 3 Grid3(i1, n).Value = alto Next End If s = s + Grid1(i1, j1).Value * Grid4(i1, j1).Value t=t+1 Loop TextBox2.Text = s Grid3.Width = 300 Grid4.Width = 300 For i = 0 To Grid1.ColumnCount - 1 'Determina el tamao de grid auxiliar If Int(257 / a) < 50 Then Grid3.Columns(i).Width = 50 Grid4.Columns(i).Width = 50 Else Grid3.Columns(i).Width = Int(257 / a) 'Grid1.Columns(i).Width Grid4.Columns(i).Width = Int(257 / a) 'Grid1.Columns(i).Width End If Next End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
a = Grid1.ColumnCount b = Grid1.RowCount Grid2.Visible = True Grid2.ColumnCount = a Grid2.RowCount = b For i = 0 To a - 1 For j = 0 To b - 1 Grid2(i, j).Value = "" If i = a - 1 Or j = b - 2 Then Grid2(i, j).Value = Grid1(i, j).Value End If Next Next Grid2.Width = 300 For i = 0 To Grid1.ColumnCount - 1 If Int(257 / a) < 50 Then Grid2.Columns(i).Width = 50 Else Grid2.Columns(i).Width = Int(257 / a) 'Grid1.Columns(i).Width End If Next z=0 x=0 s=0 Do While z < a - 1 k1 = Grid2(z, b - 2).Value k2 = Grid2(a - 1, x).Value If k2 < k1 Then Grid2(z, x).Value = k2 s = s + Grid1(z, x).Value * Grid2(z, x).Value Grid2(z, b - 2).Value = Grid2(z, b - 2).Value - Grid2(z, x).Value Grid2(a - 1, x).Value = Grid2(a - 1, x).Value - Grid2(z, x).Value x=x+1 Else Grid2(z, x).Value = k1 s = s + Grid1(z, x).Value * Grid2(z, x).Value Grid2(z, b - 2).Value = Grid2(z, b - 2).Value - Grid2(z, x).Value Grid2(a - 1, x).Value = Grid2(a - 1, x).Value - Grid2(z, x).Value z=z+1 End If Loop TextBox1.Text = s End Sub End Class