Oppure

Loading
06/12/06 15:41
Salve,sto facendo un programma.Vi spiego in breve cosa dovrei fare.
Ho 2 form
Nel primo form c'è un label
Nel secondo 2 text box
Nel secondo un tasto
In questo tasto vorrei ke mi mandi l'addizione della textbox1 + textbox2 nel label nel primo form...se mi sn spiegato male fatemi sapere :D aspetto vostre risposte!!!Siau!!!
06/12/06 18:07
Il Totem
Forse volevi dire la somma :D, cmq puoi usare un codice del genere (puoi usare CInt o qualsiasi altra conversione a seconda del tipo di dato):
Form1.Label.Text = CType(TextBox1.Text, Double) + Ctype(TextBox2.Text, Double)

In questo codice si suppone che Form1 si già aperto.
Ultima modifica effettuata da Il Totem 06/12/06 18:08
aaa
06/12/06 18:13
eh si lol cmq ce siamo capiti... :D grazie ;)
06/12/06 18:31
ehm...non capisco xkè nn mi funziona -.-

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Form1.Label26.Text = CType(TextBox1.Text, Double) + CType(TextBox2.Text, Double) + CType(TextBox3.Text, Double) + CType(TextBox4.Text, Double) + CType(TextBox5.Text, Double) + CType(TextBox6.Text, Double) + CType(TextBox7.Text, Double) + CType(TextBox8.Text, Double) + CType(TextBox9.Text, Double) + CType(TextBox10.Text, Double) + CType(TextBox11.Text, Double) + CType(TextBox12.Text, Double) + CType(TextBox13.Text, Double) + CType(TextBox14.Text, Double) + CType(TextBox15.Text, Double) + CType(TextBox16.Text, Double) + CType(TextBox17.Text, Double) + CType(TextBox18.Text, Double) + CType(TextBox19.Text, Double) + CType(TextBox20.Text, Double) + CType(TextBox21.Text, Double) + CType(TextBox1.Text, Double) + CType(TextBox22.Text, Double) + CType(TextBox23.Text, Double) + CType(TextBox24.Text, Double) + CType(TextBox25.Text, Double) + CType(TextBox26.Text, Double) + CType(TextBox27.Text, Double) + CType(TextBox28.Text, Double) + CType(TextBox29.Text, Double) + CType(TextBox30.Text, Double) + CType(TextBox31.Text, Double)
    End Sub
07/12/06 14:47
Il Totem
Sei sicuro di non poter utilizzare meno codice? Mi hai fatto spaventare con tutta quella roba!

Beh, ritornando al problema, forse non hai specificato le label come public.
E potresti provare ad usare questo codice un po' più semplice, anche se non so se fa al caso tuo (nella fattispecie non so se tutte le textbox del form contengano numeri...):
Private Sub Somma()
  Dim Tot As Double = 0

  For Each T As TextBox In Me.Controls
    Tot += CType(T.Text, Double)
  Next
 
  Form1.Label.Text = Tot
Ultima modifica effettuata da Il Totem 07/12/06 14:47
aaa
09/12/06 17:50
si tutte e 31 TextBox devono avere un numero e devono essere tutti sommati tra di loro...cosa mi konsigli?Aspetto al + presto una tua risposta ;)
09/12/06 18:03
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim Tot As Double = 0

        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox1.Text, Double)
        Next

        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox2.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox3.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox4.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox5.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox6.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox7.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox8.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox9.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox10.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox11.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox12.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox13.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox14.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox15.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox16.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox17.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox18.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox19.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox20.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox21.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox22.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox23.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox24.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox25.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox26.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox27.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox28.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox29.Text, Double)
        Next
        For Each T As TextBox In Me.Controls
            Tot += CType(TextBox30.Text, Double)
        Next
        Tot += CType(TextBox31.Text, Double)

        Form1.Label26.Text = Tot
    End Sub


Non ti spaventare :P ho messo questo codice ma l'errore me lo da qui

For Each T As TextBox In Me.Controls


Se mi puoi dare una mano mi farestri un GRANDISSIMO favore :)
10/12/06 8:07
Il Totem
Per prima cosa quando dici 'mi dà errore' dovresti specificare quale errore, chè altrimenti ti possiamo aiutare poco. In seconda istanza, il codice che hai scritto è... beh, non hai fatto i cicli for? Questo è un tipo particolare di ciclo, ma ciclo rimane, quindi va scritto una sola volta ed esegue le operazioni per tutte le textbox, quindi prova così:
For Each C As Control In Me.Controls
  If TypeOf C Is TextBox Then
    Tot += CType(C.Text, Double)
  End If
Next


EDIT: in effetti ci ho pensato e il codice che ti avevo scritto l'ultima volta è sbagliato perchè il for each cerca di vedere tutti i controlli come textbox: questa volta dovrebbe andare...
Ultima modifica effettuata da Il Totem 10/12/06 8:10
aaa