Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Conta Quadrati - Conta Quadrati.frm

Conta Quadrati.frm

Caricato da: Antometal
Scarica il programma completo

  1. Option Explicit
  2.  
  3. Private Function ContaQuadrati(Lato As Long) As Long
  4. Dim I As Integer
  5. Dim J As Integer
  6. Dim Unità As Integer
  7. Dim Somma As Long
  8. lstCalcolo.Clear
  9. pic.Cls
  10. txtLato = Val(txtLato)
  11. Unità = pic.Height / Lato
  12.     For I = 1 To Lato
  13.         Somma = Somma + I ^ 2
  14.         lstCalcolo.AddItem I & "*" & I & " (" & Lato - I + 1 & "X" & Lato - I + 1 & ") = " & I ^ 2
  15.             For J = 1 To Lato
  16.                 If (I Mod 2 = 0 And J Mod 2 = 0) Or (I Mod 2 = 1 And J Mod 2 = 1) Then pic.Line ((I - 1) * Unità, (J - 1) * Unità)-(I * Unità, (J * Unità)), vbWhite, B
  17.             Next J
  18.     Next I
  19. ContaQuadrati = Somma
  20. End Function
  21.  
  22. Private Sub cmdConta_Click()
  23.     If Val(txtLato) < 1 Or Val(txtLato) > 1000 Then
  24.         MsgBox "Errore, inserire un numero compreso tra 1 e 1000", vbExclamation
  25.         txtLato_GotFocus
  26.     End If
  27.     If Val(txtLato) > 0 And Val(txtLato) < 1001 Then lblRisultato.Caption = "La scacchiera contiene complessivamente: " & ContaQuadrati(txtLato) & " quadrati"
  28. End Sub
  29.  
  30. Private Sub cmdSalva_Click()
  31. CDialog.ShowSave
  32.     If CDialog.FileName = "" Then Exit Sub
  33. SavePicture pic.Image, CDialog.FileName
  34. End Sub
  35.  
  36. Private Sub txtLato_GotFocus()
  37. txtLato.SelStart = 0
  38. txtLato.SelLength = Len(txtLato)
  39. End Sub