Questo sito utilizza cookies, anche di terze parti, per mostrare pubblicità e servizi in linea con il tuo account. Leggi l'informativa sui cookies.
Username: Password: oppure
Matrici - Form1.vb

Form1.vb

Caricato da:
Scarica il programma completo

  1. Public Class Form1
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Public Sub New()
  7.         MyBase.New()
  8.  
  9.         'This call is required by the Windows Form Designer.
  10.         InitializeComponent()
  11.  
  12.         'Add any initialization after the InitializeComponent() call
  13.  
  14.     End Sub
  15.  
  16.     'Form overrides dispose to clean up the component list.
  17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  18.         If disposing Then
  19.             If Not (components Is Nothing) Then
  20.                 components.Dispose()
  21.             End If
  22.         End If
  23.         MyBase.Dispose(disposing)
  24.     End Sub
  25.  
  26.     'Required by the Windows Form Designer
  27.     Private components As System.ComponentModel.IContainer
  28.  
  29.     'NOTE: The following procedure is required by the Windows Form Designer
  30.     'It can be modified using the Windows Form Designer.  
  31.     'Do not modify it using the code editor.
  32.     Friend WithEvents Button1 As System.Windows.Forms.Button
  33.     Friend WithEvents Button2 As System.Windows.Forms.Button
  34.     Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  35.     Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
  36.     Friend WithEvents Label1 As System.Windows.Forms.Label
  37.     Friend WithEvents Button3 As System.Windows.Forms.Button
  38.     Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
  39.     Friend WithEvents Label2 As System.Windows.Forms.Label
  40.     Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
  41.     Friend WithEvents Label3 As System.Windows.Forms.Label
  42.     Friend WithEvents Button5 As System.Windows.Forms.Button
  43.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  44.         Me.Button1 = New System.Windows.Forms.Button
  45.         Me.Button2 = New System.Windows.Forms.Button
  46.         Me.TextBox1 = New System.Windows.Forms.TextBox
  47.         Me.TextBox2 = New System.Windows.Forms.TextBox
  48.         Me.Label1 = New System.Windows.Forms.Label
  49.         Me.Button3 = New System.Windows.Forms.Button
  50.         Me.TextBox3 = New System.Windows.Forms.TextBox
  51.         Me.Label2 = New System.Windows.Forms.Label
  52.         Me.TextBox4 = New System.Windows.Forms.TextBox
  53.         Me.Label3 = New System.Windows.Forms.Label
  54.         Me.Button5 = New System.Windows.Forms.Button
  55.         Me.SuspendLayout()
  56.         '
  57.         'Button1
  58.         '
  59.         Me.Button1.Location = New System.Drawing.Point(0, 0)
  60.         Me.Button1.Name = "Button1"
  61.         Me.Button1.Size = New System.Drawing.Size(128, 40)
  62.         Me.Button1.TabIndex = 0
  63.         Me.Button1.Text = "Carica Matrice"
  64.         '
  65.         'Button2
  66.         '
  67.         Me.Button2.Location = New System.Drawing.Point(0, 40)
  68.         Me.Button2.Name = "Button2"
  69.         Me.Button2.Size = New System.Drawing.Size(128, 40)
  70.         Me.Button2.TabIndex = 1
  71.         Me.Button2.Text = "Visualizza Matrice"
  72.         '
  73.         'TextBox1
  74.         '
  75.         Me.TextBox1.Location = New System.Drawing.Point(128, 0)
  76.         Me.TextBox1.Multiline = True
  77.         Me.TextBox1.Name = "TextBox1"
  78.         Me.TextBox1.Size = New System.Drawing.Size(208, 200)
  79.         Me.TextBox1.TabIndex = 2
  80.         Me.TextBox1.Text = ""
  81.         '
  82.         'TextBox2
  83.         '
  84.         Me.TextBox2.Location = New System.Drawing.Point(336, 24)
  85.         Me.TextBox2.Name = "TextBox2"
  86.         Me.TextBox2.Size = New System.Drawing.Size(224, 20)
  87.         Me.TextBox2.TabIndex = 3
  88.         Me.TextBox2.Text = ""
  89.         '
  90.         'Label1
  91.         '
  92.         Me.Label1.BackColor = System.Drawing.SystemColors.Control
  93.         Me.Label1.Location = New System.Drawing.Point(336, 8)
  94.         Me.Label1.Name = "Label1"
  95.         Me.Label1.Size = New System.Drawing.Size(224, 24)
  96.         Me.Label1.TabIndex = 4
  97.         Me.Label1.Text = "Totale:"
  98.         '
  99.         'Button3
  100.         '
  101.         Me.Button3.Location = New System.Drawing.Point(336, 48)
  102.         Me.Button3.Name = "Button3"
  103.         Me.Button3.Size = New System.Drawing.Size(224, 32)
  104.         Me.Button3.TabIndex = 5
  105.         Me.Button3.Text = "Totale"
  106.         '
  107.         'TextBox3
  108.         '
  109.         Me.TextBox3.Location = New System.Drawing.Point(336, 104)
  110.         Me.TextBox3.Name = "TextBox3"
  111.         Me.TextBox3.Size = New System.Drawing.Size(224, 20)
  112.         Me.TextBox3.TabIndex = 7
  113.         Me.TextBox3.Text = ""
  114.         '
  115.         'Label2
  116.         '
  117.         Me.Label2.BackColor = System.Drawing.SystemColors.Control
  118.         Me.Label2.Location = New System.Drawing.Point(336, 88)
  119.         Me.Label2.Name = "Label2"
  120.         Me.Label2.Size = New System.Drawing.Size(224, 24)
  121.         Me.Label2.TabIndex = 8
  122.         Me.Label2.Text = "Massimo:"
  123.         '
  124.         'TextBox4
  125.         '
  126.         Me.TextBox4.Location = New System.Drawing.Point(336, 144)
  127.         Me.TextBox4.Name = "TextBox4"
  128.         Me.TextBox4.Size = New System.Drawing.Size(224, 20)
  129.         Me.TextBox4.TabIndex = 9
  130.         Me.TextBox4.Text = ""
  131.         '
  132.         'Label3
  133.         '
  134.         Me.Label3.BackColor = System.Drawing.SystemColors.Control
  135.         Me.Label3.Location = New System.Drawing.Point(336, 128)
  136.         Me.Label3.Name = "Label3"
  137.         Me.Label3.Size = New System.Drawing.Size(224, 24)
  138.         Me.Label3.TabIndex = 10
  139.         Me.Label3.Text = "Minimo:"
  140.         '
  141.         'Button5
  142.         '
  143.         Me.Button5.Location = New System.Drawing.Point(336, 168)
  144.         Me.Button5.Name = "Button5"
  145.         Me.Button5.Size = New System.Drawing.Size(224, 32)
  146.         Me.Button5.TabIndex = 11
  147.         Me.Button5.Text = "Max e Min "
  148.         '
  149.         'Form1
  150.         '
  151.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  152.         Me.ClientSize = New System.Drawing.Size(568, 207)
  153.         Me.Controls.Add(Me.Button5)
  154.         Me.Controls.Add(Me.TextBox4)
  155.         Me.Controls.Add(Me.Label3)
  156.         Me.Controls.Add(Me.TextBox3)
  157.         Me.Controls.Add(Me.Button3)
  158.         Me.Controls.Add(Me.TextBox2)
  159.         Me.Controls.Add(Me.Label1)
  160.         Me.Controls.Add(Me.TextBox1)
  161.         Me.Controls.Add(Me.Button2)
  162.         Me.Controls.Add(Me.Button1)
  163.         Me.Controls.Add(Me.Label2)
  164.         Me.Name = "Form1"
  165.         Me.Text = "Matrici"
  166.         Me.ResumeLayout(False)
  167.  
  168.     End Sub
  169.  
  170. #End Region
  171.     Dim matrice(50, 50) As Double
  172.     Dim vet(250)
  173.     Dim k
  174.     Dim i As Integer
  175.     Dim j As Integer
  176.     Dim c As Integer
  177.     Dim r As Integer
  178.     Dim s As Double
  179.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  180.         r = Val(InputBox("Inserire Il Numero Di Righe", "Inserisci"))
  181.         c = Val(InputBox("Inserire Il Numero Di Colonne", "Inserisci"))
  182.         For i = 1 To r
  183.             For j = 1 To c
  184.                 matrice(i, j) = Val(InputBox("Inserisci il valore di riga" & CStr(i) & " e di Colonna " & CStr(j)))
  185.                 s = s + matrice(i, j)
  186.                 vet(i) = vet(i) + matrice(i, j)
  187.             Next j
  188.         Next i
  189.     End Sub
  190.  
  191.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  192.         For i = 1 To r
  193.             For j = 1 To c
  194.                 TextBox1.Text = TextBox1.Text + CStr(matrice(i, j)) & "   "
  195.             Next j
  196.             TextBox1.Text = TextBox1.Text + vbNewLine
  197.         Next i
  198.     End Sub
  199.  
  200.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  201.         TextBox2.Text = Val(s)
  202.     End Sub
  203.  
  204.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  205.         For i = 1 To r
  206.             For j = 1 To c
  207.                 vet(k) = matrice(i, j)
  208.                 k = k + 1
  209.             Next j
  210.         Next i
  211.  
  212.         For i = 1 To r
  213.             For j = 1 To c
  214.                 matrice(i, j) = vet(k)
  215.                 k = k + 1
  216.                 TextBox1.Text = TextBox1.Text + CStr(matrice(i, j)) & "   "
  217.             Next j
  218.             TextBox1.Text = TextBox1.Text + vbNewLine
  219.         Next i
  220.     End Sub
  221.  
  222.  
  223.  
  224.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  225.         Dim max, min
  226.         For i = 1 To r
  227.             For j = 1 To c
  228.                 If i = 1 And j = 1 Then
  229.                     max = matrice(i, j)
  230.                     min = matrice(i, j)
  231.                 End If
  232.                 If matrice(i, j) > max Then
  233.                     max = matrice(i, j)
  234.                 End If
  235.                 If matrice(i, j) < min Then
  236.                     min = matrice(i, j)
  237.                 End If
  238.             Next
  239.         Next
  240.         TextBox3.Text = CStr(max)
  241.         TextBox4.Text = CStr(min)
  242.     End Sub
  243. End Class