mohammad shaterian Member May 13, 2025 #1 I wrote the following code in B4J to create a loop to set the values of the buttons I created in the form, but unfortunately it does not work and returns an error. Please help. Sub Process_Globals Private MainForm As Form Private Button1 As Button Private Button2 As Button Private Button3 As Button Private Button4 As Button Private Button5 As Button Private Button6 As Button Dim ls As List End Sub Sub AppStart (Form1 As Form, Args() As String) MainForm = Form1 MainForm.RootPane.LoadLayout("Layout1") MainForm.Show ls.Initialize ls.AddAll(Array As Button(Button1,Button2,Button3,Button4,Button5,Button6)) End Sub Sub Button1_Click For t=0 To 5 Dim bt As Button=ls.Get(0) bt.Text="" Next End Sub
I wrote the following code in B4J to create a loop to set the values of the buttons I created in the form, but unfortunately it does not work and returns an error. Please help. Sub Process_Globals Private MainForm As Form Private Button1 As Button Private Button2 As Button Private Button3 As Button Private Button4 As Button Private Button5 As Button Private Button6 As Button Dim ls As List End Sub Sub AppStart (Form1 As Form, Args() As String) MainForm = Form1 MainForm.RootPane.LoadLayout("Layout1") MainForm.Show ls.Initialize ls.AddAll(Array As Button(Button1,Button2,Button3,Button4,Button5,Button6)) End Sub Sub Button1_Click For t=0 To 5 Dim bt As Button=ls.Get(0) bt.Text="" Next End Sub
Erel B4X founder Staff member Licensed User Longtime User May 13, 2025 #2 Please use [code]code here...[/code] tags when posting code. Which error? Upvote 0
aeric Expert Licensed User Longtime User May 13, 2025 #3 mohammad shaterian said: For t=0 To 5 Dim bt As Button=ls.Get(0) bt.Text="" Next Click to expand... I don't think there is an error but only the first button clear the Text. Should have written ls.Get(t) if you want to clear all 6 buttons. B4X: Copy For i = 0 To 5 Dim bt As Button = ls.Get(i) bt.Text = "" Next Upvote 0
mohammad shaterian said: For t=0 To 5 Dim bt As Button=ls.Get(0) bt.Text="" Next Click to expand... I don't think there is an error but only the first button clear the Text. Should have written ls.Get(t) if you want to clear all 6 buttons. B4X: Copy For i = 0 To 5 Dim bt As Button = ls.Get(i) bt.Text = "" Next
mohammad shaterian Member May 13, 2025 #4 aeric said: I don't think there is an error but only the first button clear the Text. Should have written ls.Get(t) if you want to clear all 6 buttons. B4X: Copy For i = 0 To 5 Dim bt As Button = ls.Get(i) bt.Text = "" Next Click to expand... I'm sorry, but even with your method I get the following error: Code: Copy java.lang.ClassCastException: class anywheresoftware.b4j.objects.ButtonWrapper cannot be cast to class javafx.scene.control.Labeled (anywheresoftware.b4j.objects.ButtonWrapper is in unnamed module of loader 'app'; javafx.scene.control.Labeled is in module javafx.controls of loader 'app') Upvote 0
aeric said: I don't think there is an error but only the first button clear the Text. Should have written ls.Get(t) if you want to clear all 6 buttons. B4X: Copy For i = 0 To 5 Dim bt As Button = ls.Get(i) bt.Text = "" Next Click to expand... I'm sorry, but even with your method I get the following error: Code: Copy java.lang.ClassCastException: class anywheresoftware.b4j.objects.ButtonWrapper cannot be cast to class javafx.scene.control.Labeled (anywheresoftware.b4j.objects.ButtonWrapper is in unnamed module of loader 'app'; javafx.scene.control.Labeled is in module javafx.controls of loader 'app')
Erel B4X founder Staff member Licensed User Longtime User May 13, 2025 #5 Change: Code: Copy ls.AddAll(Array As Button(Button1,Button2,Button3,Button4,Button5,Button6)) To: Code: Copy ls.AddAll(Array(Button1,Button2,Button3,Button4,Button5,Button6)) List.AddAll expects an array of generic objects. Upvote 0
Change: Code: Copy ls.AddAll(Array As Button(Button1,Button2,Button3,Button4,Button5,Button6)) To: Code: Copy ls.AddAll(Array(Button1,Button2,Button3,Button4,Button5,Button6)) List.AddAll expects an array of generic objects.
aeric Expert Licensed User Longtime User May 13, 2025 #6 Erel said: Change: Code: Copy ls.AddAll(Array As Button(Button1,Button2,Button3,Button4,Button5,Button6)) To: Code: Copy ls.AddAll(Array(Button1,Button2,Button3,Button4,Button5,Button6)) List.AddAll expects an array of generic objects. Click to expand... I never noticed this as I only use AddAll for Array As String(), it worked. Upvote 0
Erel said: Change: Code: Copy ls.AddAll(Array As Button(Button1,Button2,Button3,Button4,Button5,Button6)) To: Code: Copy ls.AddAll(Array(Button1,Button2,Button3,Button4,Button5,Button6)) List.AddAll expects an array of generic objects. Click to expand... I never noticed this as I only use AddAll for Array As String(), it worked.
aeric Expert Licensed User Longtime User May 13, 2025 #7 B4X: Copy ls.AddAll(Array As B4XView(Button1,Button2,Button3,Button4,Button5,Button6)) B4X: Copy Private Sub Button1_Click Dim bt As B4XView = ls.Get(0) bt.Text = "" End Sub This work. Upvote 0
B4X: Copy ls.AddAll(Array As B4XView(Button1,Button2,Button3,Button4,Button5,Button6)) B4X: Copy Private Sub Button1_Click Dim bt As B4XView = ls.Get(0) bt.Text = "" End Sub This work.
mohammad shaterian Member May 13, 2025 #8 Erel said: Change: Code: Copy ls.AddAll(Array As Button(Button1,Button2,Button3,Button4,Button5,Button6)) To: Code: Copy ls.AddAll(Array(Button1,Button2,Button3,Button4,Button5,Button6)) List.AddAll expects an array of generic objects. Click to expand... thank you erel it's OK Upvote 0
Erel said: Change: Code: Copy ls.AddAll(Array As Button(Button1,Button2,Button3,Button4,Button5,Button6)) To: Code: Copy ls.AddAll(Array(Button1,Button2,Button3,Button4,Button5,Button6)) List.AddAll expects an array of generic objects. Click to expand... thank you erel it's OK