Salve; quando provo ad eseguire il mio programma , mi da quest' errore: "Too many constants alla linea 7146 in ModSet.module"
Questo è la parte del codice incriminata
7125 sql = "SELECT * FROM tconfbtn WHERE id = 213"
7126 MyRes = modConn.$Conn.Exec(sql)
7127 IF MyRes.Available THEN
7128 IF FMain.RadioButton1.Value THEN
7129 TRY fList = MyRes!list1
7130 ELSE IF FMain.RadioButton2.Value THEN
7131 TRY fList = MyRes!list2
7132 ELSE IF FMain.RadioButton3.Value THEN
7133 TRY fList = MyRes!list3
7134 ELSE IF FMain.RadioButton4.Value THEN
7135 TRY fList = MyRes!list4
7136 ENDIF
7137
7138 IF MyRes!text2 = NULL THEN
7139 FMain.Button213.Text = MyRes!text & gb.NewLine & " € " & modZero.PiuZero(fList)
7140 ELSE
7141 FMain.Button213.Text = MyRes!text & gb.NewLine & MyRes!text2 & gb.NewLine & " € " & modZero.PiuZero(fList)
7142 ENDIF
7143
7144 WITH FMain.Button213
7145 .Background = MyRes!bkgnd
7146 .Foreground = MyRes!fognd
7147 .Font.Name = MyRes!fntno
7148 .Font.Bold = MyRes!fntbo
7149 .Font.Italic = MyRes!fntit
7150 .Font.Size = MyRes!fntsi
7151 .Font.StrikeOut = MyRes!fntso
7152 .Font.Underline = MyRes!fntul
7153 END WITH
7154 ENDIF
Questa è la configurazione del 213° pulsante, prima con soli 200 andava bene ora che ne ho aggiunti altri 100 da questo problema.
Queste configurazioni sono divise in 6 "PUBLIC PROCEDURE Set_Tab'numero tavola'()" da 50 pulsanti l'una.
Grazie.
In effetti, come dice fsurfing, è impegnativo scrivere 300 volte del codice per lo più ridondante. Nel mio programma, per poche ComboBx similari (solamente sei) ho utilizzato la poprietà Group che mi ha permesso di avere una sola ComboBox.GotFocus, ComboBox.Change, ..., ComboBox.LostFocus. Naturalmente ho dovuto capire quale dato avrei dovuto trattare al momento e per fare questo ho creato un array a cui punto durante l'esecuzione del programma per indivuiduare il Last.text o il Last.tag. Riporto un esempio tratto dalla mia applicazione:
Private o_ElCmbVoCo As New Object[] 'permette il puntamento agli elementi del gruppo di oggetti ComboVociCont presenti nel Form
Private o_CmbVociCont As Object
'...........................................
Public Sub CarPuntVociCo() 'Procedura di caricamento della Tabella dei puntamenti ad alcune ComboBox della Form
o_ElCmbVoCo.Add(Me.VoContCas)
o_ElCmbVoCo.Add(Me.VoSotCtoCas)
o_ElCmbVoCo.Add(Me.VoSezColleg)
o_ElCmbVoCo.Add(Me.VoCoPriColleg)
o_ElCmbVoCo.Add(Me.VoCoSecColleg)
o_ElCmbVoCo.Add(Me.VoSotCtoColleg)
End
'...........................................
For Each o_CmbVociCont In o_ElCmbVoCo 'Esempio di utilizzo
If o_CmbVociCont.text = "" Then
'.......bla.......bla.......bla
next
Spero che ti possa tornare utile.
:ciao:
Volendo modificare le caratteristiche o il testo di un solo pulsante una volta creati , come faccio?
Riprendiamo il codice inviato da fsurfing, e facciamo finta che durante la divina creazione dei Button, vuoi modificare le dimensioni di un solo tasto rispetto agli altri, ad esempio il num. 50:
Public Sub Form_Open()
Dim pippo As Button
Dim i As Integer
Dim a, b As Integer
For i = 0 To 100
a = 100
b = 10
pippo = New Button(ScrollView1) As "MyButton"
If i = 50 Then a = 200
With pippo
.W = a
.H = b
.name = i
.Text = "pulsante " & i
End With
Next
End
Ora, più coerentemente con la tua domanda, mettiamo che, dopo aver creato quei tasti, vogliamo modificare una o più caratteristiche di uno, ad esempio ancora del Button num. 50:
Public Sub MyButton_click()
Dim objB As Object
Message.Info("hai premuto il pulsante " & Last.Name)
' Prendiamo in considerazione tutti i Button
' presenti nella ScrollView:
For Each objB In ScrollView1.Children
' Quando il codice passa a considerare il Button (Children) num. 50, allora...
If objB.name = 50 Then
'...gli cambiamo qualche connotato...:
With objB
.W = 300
.Background = Color.Red
End With
Endif
Next
End
....come faccio ad eliminarli... ?
Ancora più semplice:
' Poiché fsurfing ha stabilito che quei Button
' sono posti nella ScrollView, e quindi ne sono "figli",
' determiniamo lo sterminio totale di tutti
' i "children" appartenenti alla ScrollView:
ScrollView1.Children.Clear
Print "Button, tutti kaput ! Ja !"
Questi sono i miei modesti suggerimenti :-X , ma certamente amici qui nel forum ben più esperti e capaci di me ti sapranno suggerire :coder: metodi più brevi ed efficaci.
Ciao; ho dovuto rivoluzionare un pò tutto, ma così è fichissimo!
Questa è la creazione:
PUBLIC SUB Set_Buttons()
DIM sql AS String
DIM fList AS Float
DIM btn AS Button
DIM i AS Integer
FOR i = 1 TO 300
IF i < 51 THEN btn = NEW Button(Panel4) AS "myBtn"
IF i > 50 AND i < 101 THEN btn = NEW Button(Panel5) AS "myBtn"
IF i > 100 AND i < 151 THEN btn = NEW Button(Panel6) AS "myBtn"
IF i > 150 AND i < 201 THEN btn = NEW Button(Panel7) AS "myBtn"
IF i > 200 AND i < 251 THEN btn = NEW Button(Panel8) AS "myBtn"
IF i > 250 THEN btn = NEW Button(Panel9) AS "myBtn"
btn.Height = 59
btn.Width = 98
btn.Name = i
sql = "SELECT * FROM tconfbtn WHERE id = " & i
MyRes = modConn.$Conn.Exec(sql)
IF MyRes.Available THEN
IF RadioButton1.Value THEN
TRY fList = MyRes!list1
ELSE IF RadioButton2.Value THEN
TRY fList = MyRes!list2
ELSE IF RadioButton3.Value THEN
TRY fList = MyRes!list3
ELSE IF RadioButton4.Value THEN
TRY fList = MyRes!list4
ENDIF
IF MyRes!text2 = NULL THEN
btn.Text = MyRes!text & gb.NewLine & " € " & modZero.PiuZero(fList)
ELSE
btn.Text = MyRes!text & gb.NewLine & MyRes!text2 & gb.NewLine & " € " & modZero.PiuZero(fList)
ENDIF
WITH btn
.Background = MyRes!bkgnd
.Foreground = MyRes!fognd
.Font.Name = MyRes!fntno
.Font.Bold = MyRes!fntbo
.Font.Italic = MyRes!fntit
.Font.Size = MyRes!fntsi
.Font.StrikeOut = MyRes!fntso
.Font.Underline = MyRes!fntul
END WITH
ELSE
btn.Text = NULL
ENDIF
NEXT
END
E questa è la modifica in corsa:
' Scorriamo tutte e 6 le tabelle
FOR EACH objA IN FMain.TabStrip1.Children
' Prendiamo in considerazione tutti i Button
' presenti nell PanelX:
FOR EACH objB IN objA.Children
' Quando il codice passa a considerare il Button (Children) num. X, allora...
IF objB.name = FMain.inBtn THEN
'...gli cambiamo qualche connotato...:
WITH objB
.Background = btnExe.Background
.Foreground = btnExe.Foreground
.Font.Name = btnExe.Font.Name
.Font.Bold = fntbo
.Font.Italic = fntit
.Font.Size = btnExe.Font.Size + 1
.Font.StrikeOut = fntso
.Font.Underline = fntul
END WITH
IF TextBox2.Text = NULL THEN
objB.Text = TextBox1.Text & gb.NewLine & " € " & TxtPrezzo1.Text
ELSE
objB.Text = TextBox1.Text & gb.NewLine & TextBox2.Text & gb.NewLine & " € " & TxtPrezzo1.Text
ENDIF
ENDIF
NEXT
NEXT
Per quanto riguarda la distruzione, usando
ScrollView1.Children.Clear
oppure, come mel mio caso
non và, perchè, in entrambi i casi, dopo Children. accetta solo Count.
GRAZIE!
per eliminare i pulsantoi dovrebbe andare:
DIM i AS Integer
FOR i = 0 TO ScrollView1.Children.Count - 1
ScrollView1.Children[i].Delete
NEXT
oppure così che in alcuni casi funziona meglio
PUBLIC SUB Button1_Click()
DIM i AS Integer
FOR i = ScrollView1.Children.Count - 1 TO 0 STEP -1
ScrollView1.Children[i].Delete
NEXT
END
ERRORE ERRORE!!
il codice che ho scritto per la modifica in corsa non và.
' Scorriamo tutte e 6 le tabelle
FOR EACH objA IN FMain.TabStrip1.Children
' Prendiamo in considerazione tutti i Button
' presenti nell PanelX:
FOR EACH objB IN objA.Children
' Quando il codice passa a considerare il Button (Children) num. X, allora...
IF objB.name = FMain.inBtn THEN
La riga 2 non considera le 6 tabelle, ma i 50 pulsanti contenuti nella tabella attiva in quel momento.
per modificare tutti i 300 pulsanti, divisi in 6 tabelle, ho dovuto ripetere il codice seguente 6 volte.
FOR EACH objB IN FMain.ScrollView1.Children
' Quando il codice passa a considerare il Button (Children) num. X, allora...
INC x
'...gli cambiamo qualche connotato...:
sql = "SELECT * FROM tconfbtn WHERE id = " & x
MyRes = modConn.$Conn.Exec(sql)
IF MyRes.Available THEN
IF FMain.RadioButton1.Value THEN
TRY fList = MyRes!list1
ELSE IF FMain.RadioButton2.Value THEN
TRY fList = MyRes!list2
ELSE IF FMain.RadioButton3.Value THEN
TRY fList = MyRes!list3
ELSE IF FMain.RadioButton4.Value THEN
TRY fList = MyRes!list4
ENDIF
IF MyRes!text2 = NULL THEN
objB.Text = MyRes!text & gb.NewLine & " € " & modZero.PiuZero(fList)
ELSE
objB.Text = MyRes!text & gb.NewLine & MyRes!text2 & gb.NewLine & " € " & modZero.PiuZero(fList)
ENDIF
WITH objB
.Background = MyRes!bkgnd
.Foreground = MyRes!fognd
.Font.Name = MyRes!fntno
.Font.Bold = MyRes!fntbo
.Font.Italic = MyRes!fntit
.Font.Size = MyRes!fntsi
.Font.StrikeOut = MyRes!fntso
.Font.Underline = MyRes!fntul
END WITH
ELSE
objB.Text = NULL
ENDIF
NEXT
uno per ogn'una delle 6 ScrollView (riga 1) che contengono i 50 pulsanti.