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
Crea_Matrici_Numeriche - ottimizzazioni

Crea_Matrici_Numeriche

Sommario | Admin | Forum | Bugs | Todo | Files

Avatar
Carlo (Member)
Guru


Messaggi: 1316
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 20:35
Giovedė, 14/06/2018
Ciao, ho visto che ti sei scontrato con la formattazione degli zeri, ci sono varie alternative per eliminare i Case.
VB NET:
Testo = Testo & " " & String.Format("{0:00}", matrice2(i3, j3))

Basic:
Testo = Testo & " " & Mid(CStr(matrice2(i3, j3) + 100), 2, 2)

VB6:
Testo = Testo & " " & Format(matrice2(i3, j3), "00")


https://docs.microsoft.com/en-us/dotnet/standard/base-types ...

Ultima modifica effettuata da Carlo il 14/06/2018 alle 21:07


in programmazione tutto č permesso
PM Quote
Avatar
Ultimo (Member)
Guru


Messaggi: 877
Iscritto: 22/05/2010

Segnala al moderatore
Postato alle 0:30
Venerdė, 15/06/2018
Testo quotato

Postato originariamente da Carlo:

Ciao, ho visto che ti sei scontrato con la formattazione degli zeri, ci sono varie alternative per eliminare i Case.
VB NET:
Testo = Testo & " " & String.Format("{0:00}", matrice2(i3, j3))

Basic:
Testo = Testo & " " & Mid(CStr(matrice2(i3, j3) + 100), 2, 2)

VB6:
Testo = Testo & " " & Format(matrice2(i3, j3), "00")


https://docs.microsoft.com/en-us/dotnet/standard/base-types ...



Grazie, lo modifico, :k:


If ok Then GOTO Avanza else GOTO Inizia

PM Quote
Avatar
Ultimo (Member)
Guru


Messaggi: 877
Iscritto: 22/05/2010

Segnala al moderatore
Postato alle 11:16
Domenica, 17/06/2018
Inserita funzione:

Codice sorgente - presumibilmente VB.NET

  1. Public Function Ritorna_Formato_Numerico(ByRef ln As Int32) As String
  2.         Dim len As String = CStr(ln)
  3.         Dim lenStr As Short = len.Length
  4.         Dim FormatoStringa As String = "{0:00}"
  5.  
  6.         Select Case lenStr
  7.             Case 1
  8.                 FormatoStringa = "{0:0}"
  9.             Case 2
  10.                 FormatoStringa = "{0:00}"
  11.             Case 3
  12.                 FormatoStringa = "{0:000}"
  13.             Case 4
  14.                 FormatoStringa = "{0:0000}"
  15.             Case 5
  16.                 FormatoStringa = "{0:00000}"
  17.             Case 6
  18.                 FormatoStringa = "{0:000000}"
  19.         End Select
  20.  
  21.         Return FormatoStringa
  22.  
  23.     End Function
  24.  
  25.  Private Sub ButtonVisual2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVisual2.Click
  26.  
  27.         Dim i4 As Integer
  28.         Dim j4 As Integer
  29.  
  30.         Dim Testo As String
  31.         Testo = CStr("")
  32.          'utilizzo della funzione per il formato numerico
  33.         Dim Formato As String = Ritorna_Formato_Numerico(Tnum)
  34.  
  35.         For i4 = 1 To r
  36.             Testo = CStr("")
  37.             For j4 = 1 To c
  38.  
  39.                 Testo = Testo & "  " & String.Format(Formato, matrice2(i4, j4))
  40.             Next j4
  41.             Me.ListBox1.Items.Add(Testo)
  42.         Next i4
  43.  
  44.         Me.ButtonGenera.BackColor = Color.GreenYellow
  45.         Me.ButtonGenera2.BackColor = Color.Olive
  46.         Me.ButtonGenera2.Enabled = True
  47.         Me.ButtonGenera.Enabled = True
  48.         Me.Btn_Ripeti.Visible = True
  49.  
  50.     End Sub
  51.  
  52.  Private Sub ButtonVisual1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVisual1.Click
  53.  
  54.         Dim i3 As Integer
  55.         Dim j3 As Integer
  56.         Dim Testo As String
  57.         Testo = CStr("")
  58.        'utilizzo della funzione per il formato numerico
  59.         Dim Formato As String = Ritorna_Formato_Numerico(Tnum)
  60.  
  61.         If Metodo = 2 Then
  62.             Me.TextBox1.Text = TextBox1.Text + "By Ultimo------MATRICE--- " & r & " X " & c & " -------------------------------. . . . . . . . ."
  63.             Me.TextBox1.Text = TextBox1.Text + vbNewLine
  64.             For i3 = 1 To r
  65.                 Testo = CStr("")
  66.                 For j3 = 1 To c
  67.  
  68.                     Testo = Testo & "  " & String.Format(Formato, matrice2(i3, j3))
  69.                 Next j3
  70.                 TextBox1.Text = TextBox1.Text + Testo
  71.                 TextBox1.Text = TextBox1.Text + vbNewLine
  72.             Next i3
  73.             Me.TextBox1.Text = TextBox1.Text + "By Ultimo------------------------------------------------. . . . . . . . . . ."
  74.             Me.TextBox1.Text = TextBox1.Text + vbNewLine + vbNewLine
  75.             Me.ButtonGenera.BackColor = Color.GreenYellow
  76.             Me.ButtonGenera2.BackColor = Color.Olive
  77.             Me.ButtonGenera2.Enabled = True
  78.             Me.ButtonGenera.Enabled = True
  79.             Me.Btn_Ripeti.Visible = True
  80.         Else
  81.             Me.TextBox1.Text = TextBox1.Text + "By Ultimo------MATRICE--- " & r & " X " & c & " -------------------------------------. . . . . . . . . . ."
  82.             Me.TextBox1.Text = TextBox1.Text + vbNewLine
  83.             For i3 = 1 To r
  84.                 For j3 = 1 To c
  85.                     TextBox1.Text = TextBox1.Text + "  " & CStr(matrice2(i3, j3))
  86.                 Next j3
  87.                 TextBox1.Text = TextBox1.Text + vbNewLine
  88.             Next i3
  89.             Me.TextBox1.Text = TextBox1.Text + "By Ultimo------------------------------------------------. . . . . . . . . . ."
  90.             Me.TextBox1.Text = TextBox1.Text + vbNewLine + vbNewLine
  91.             Me.ButtonGenera.BackColor = Color.GreenYellow
  92.             Me.ButtonGenera2.BackColor = Color.Olive
  93.             Me.ButtonGenera2.Enabled = True
  94.             Me.ButtonGenera.Enabled = True
  95.             Me.Btn_Ripeti.Visible = True
  96.         End If
  97.  
  98.  
  99.     End Sub



:k:



If ok Then GOTO Avanza else GOTO Inizia

PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1316
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 13:28
Domenica, 17/06/2018
Testo quotato

Postato originariamente da Ultimo:
Inserita funzione:



Bella, cosė con Tnum, gli zeri si aggiungono in accordo con il numero random scelto!!!

Inseriscila anche dopo l'else, cosė funziona anche con [Genera matrici] quadrate e non:

Codice sorgente - presumibilmente VB.NET

  1. Private Sub ButtonVisual1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVisual1.Click
  2.  
  3.         Dim i3 As Integer
  4.         Dim j3 As Integer
  5.         Dim Testo As String
  6.         Testo = CStr("")
  7.         'utilizzo della funzione per il formato numerico
  8.         Dim Formato As String = Ritorna_Formato_Numerico(Tnum)
  9.  
  10.         If Metodo = 2 Then
  11.             Me.TextBox1.Text = TextBox1.Text + "By Ultimo------MATRICE--- " & r & " X " & c & " -------------------------------. . . . . . . . ."
  12.             Me.TextBox1.Text = TextBox1.Text + vbNewLine
  13.             For i3 = 1 To r
  14.                 Testo = CStr("")
  15.                 For j3 = 1 To c
  16.  
  17.                     Testo = Testo & "  " & String.Format(Formato, matrice2(i3, j3))
  18.                 Next j3
  19.                 TextBox1.Text = TextBox1.Text + Testo
  20.                 TextBox1.Text = TextBox1.Text + vbNewLine
  21.             Next i3
  22.             Me.TextBox1.Text = TextBox1.Text + "By Ultimo------------------------------------------------. . . . . . . . . . ."
  23.             Me.TextBox1.Text = TextBox1.Text + vbNewLine + vbNewLine
  24.             Me.ButtonGenera.BackColor = Color.GreenYellow
  25.             Me.ButtonGenera2.BackColor = Color.Olive
  26.             Me.ButtonGenera2.Enabled = True
  27.             Me.ButtonGenera.Enabled = True
  28.             Me.Btn_Ripeti.Visible = True
  29.         Else
  30.             Me.TextBox1.Text = TextBox1.Text + "By Ultimo------MATRICE--- " & r & " X " & c & " -------------------------------------. . . . . . . . . . ."
  31.             Me.TextBox1.Text = TextBox1.Text + vbNewLine
  32.             For i3 = 1 To r
  33.                 For j3 = 1 To c
  34.                     TextBox1.Text = TextBox1.Text + "  " & String.Format(Formato, matrice2(i3, j3))
  35.                 Next j3
  36.                 TextBox1.Text = TextBox1.Text + vbNewLine
  37.             Next i3
  38.             Me.TextBox1.Text = TextBox1.Text + "By Ultimo------------------------------------------------. . . . . . . . . . ."
  39.             Me.TextBox1.Text = TextBox1.Text + vbNewLine + vbNewLine
  40.             Me.ButtonGenera.BackColor = Color.GreenYellow
  41.             Me.ButtonGenera2.BackColor = Color.Olive
  42.             Me.ButtonGenera2.Enabled = True
  43.             Me.ButtonGenera.Enabled = True
  44.             Me.Btn_Ripeti.Visible = True
  45.         End If
  46.  
  47. End Sub



:k::k:

La funzione Ritorna_Formato_Numerico:
Codice sorgente - presumibilmente VB.NET

  1. Public Function Ritorna_Formato_Numerico(ByRef ln As Int32) As String
  2.  
  3.         Dim lenStr As Short = CStr(ln).Length
  4.         Dim FormatoStringa As String = "{0:"
  5.  
  6.         For i = 1 To lenStr
  7.             FormatoStringa = FormatoStringa & "0"
  8.         Next
  9.         FormatoStringa = FormatoStringa & "}"
  10.  
  11.         Return FormatoStringa
  12.  
  13. End Function


funziona anche con numeri >6 cifre
:asd::asd::asd:

Ultima modifica effettuata da Carlo il 17/06/2018 alle 14:45


in programmazione tutto č permesso
PM Quote
Avatar
Ultimo (Member)
Guru


Messaggi: 877
Iscritto: 22/05/2010

Segnala al moderatore
Postato alle 14:48
Domenica, 17/06/2018
@Carlo
___________________________________________________________________
Solo a livello accademico (la tua va benissimo), come avrei scritto la funzione Ritorna_Formato_Numerico:
Codice sorgente - presumibilmente VB.NET

Public Function Ritorna_Formato_Numerico(ByRef ln As Int32) As String

        Dim lenStr As Short = CStr(ln).Length
        Dim FormatoStringa As String = "{0:"

        For i = 1 To lenStr
            FormatoStringa = FormatoStringa & "0"
        Next
        FormatoStringa = FormatoStringa & "}"

        Return FormatoStringa

End Function


cosė va bene anche con numeri >6 cifre
_________________________________________________

:k:

La tua soluzione č migliore

:rofl:





If ok Then GOTO Avanza else GOTO Inizia

PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1316
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 22:08
Domenica, 17/06/2018
Poca cosa in confronto al programma che hai postato...;)


in programmazione tutto č permesso
PM Quote