You are not logged in.

Henning

Beginner

  • "Henning" is male
  • "Henning" started this thread

Posts: 9

Date of registration: Jan 15th 2009

Location: In Sweden, 50 km outside Östersund

Occupation: HW, FW & Interface developer

Hobbies: Cars, and ofcause my job ;)

  • Send private message

1

Friday, January 16th 2009, 2:09am

Control Arrays

Hi again,

How to handle control arrays, in my case Buttons, there is no Index property?

/Henning

maXim

Trainee

  • "maXim" is male

Posts: 53

Date of registration: Jan 5th 2009

Location: Sesto Fiorentino, Florence (ITALY)

Occupation: design & development (HW, SW & FW)

Hobbies: chess, fly fishing, good wine and beautiful women!

  • Send private message

2

Friday, January 16th 2009, 4:03pm

Hi Henning,

I hope for a lot that also in Jabaco is possible to manage the arrays of controls as in VB6. I propose a temporary solution, is not very elegant (for nothing!) but...

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..... 
Public Sub Command1_Click() 
    CommandEx 1 
End Sub 
Public Sub Command2_Click() 
    CommandEx 2 
End Sub 
Public Sub Command3_Click() 
    CommandEx 3 
End Sub 
..... 
Sub CommandEx(Index As Integer) 
    MsgBox "the button " & CStr(Index) & " has been pressed!" 
    Select Case Index 
        Case 1 
            ..... 
        Case 2 
            ..... 
        Case 3 
            ..... 
    End Select 
End Sub


... we can try! ;)

Best Regards,

maXim

P.S. I apologize for my bad English. :S

Henning

Beginner

  • "Henning" is male
  • "Henning" started this thread

Posts: 9

Date of registration: Jan 15th 2009

Location: In Sweden, 50 km outside Östersund

Occupation: HW, FW & Interface developer

Hobbies: Cars, and ofcause my job ;)

  • Send private message

3

Friday, January 16th 2009, 6:07pm

Thx but Jeeez, I got about 200 graphical buttons that change backcolor, simulating LED's, depending on data in a UDP pkg. ;(

/Henning

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

4

Saturday, January 17th 2009, 12:04am

Another Jabaco solution that should solve your problem:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Dim WithEvents myStateList As VBControlExtender(Me)
Dim myStateItems() As PictureBox 

Public Sub Form_Load()

   Dim tmpStateItem As PictureBox
   
   Const maxX As Integer = 15
   Const maxY As Integer = 10
   
   Const offsetX As Integer = 10
   Const offsetY As Integer = 10
   
   Const itemWidth As Integer = 23
   Const itemHeight As Integer = 10
   
   Dim x As Integer, y As Integer, v As Integer
   
   ReDim myStateItems((maxX + 1) * (maxY + 1))
   For x = 0 To maxX
  	For y = 0 To maxY
     	v = v + 1
     	tmpStateItem = New PictureBox()
     	myStateItems(v) = tmpStateItem
     	Call myStateList.AddControl("test" + x + "|" + y, tmpStateItem, x * itemWidth + offsetX, y * itemHeight + offsetY, itemWidth, itemHeight, True)
  	Next
   Next
   
   v = 0
   For x = 0 To maxX
  	For y = 0 To maxY
     	v = v + 1
     	myStateItems(v).BackColor = IIF(Rnd > 0.5, vbRed, vbGreen)
   	Next
   Next
   
   
End Sub

Public Sub myStateList_Click(ControlID As String)
   MsgBox ControlID + " pressed!"
End Sub

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

5

Saturday, January 17th 2009, 8:30pm

Dynamic array of controls with class overloading

Hi all,

here is another solution how to create and handle controls dynamically.

I overloaded the CommandButton class. This allowed me do overload the "mouseClicke()" method and route all incoming events to my central handler.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Option Explicit 
' 
' this Class overloads CommandButton to define a special event handler 
' 
Public ownerForm As frmDynControl ' allows call back to common event handler 
Public row As Integer ' we remember row/col to handle events parameterized 
Public col As Integer 

' a parameterized constructor 
Public Sub clsMyDynButton(frm As frmDynControl, c As Integer, r As Integer ) 
  ownerForm = frm 
  col = c 
  row = r 
End Sub 

' Jabaco was not able to find class "MouseEvent" 
' before I explicitly selected this class in the Project/Classpath rt.jar tree 
Public Sub mouseClicked(e As MouseEvent) 
  ownerForm.dynButtonClickHandler(Me, e) 
End Sub



The central event handler in my form:

Source code

1
2
3
4
5
6
7
8
9
10
11
' "MouseEvent" was not visible in my Jabaco IDE before I explicitly 
' selected it in the Project/Classpath rt.jar tree 
Public Sub dynButtonClickHandler(btn As clsMyDynButton, e As MouseEvent) 
  ' common click event handler for all clsMyDynButton controls 
  If Not e.isConsumed Then 
    ' we react just once 
    msgbox "col=" & btn.col & " row=" & btn.row & vbcrlf & e.toString 
    ' here we might do something clever depending on the btn.Caption 
    e.consume 
  End If 
End Sub



I wonder why I had to "convince" the event handler to execute the events just once. Without checking and setting the "consume" flag, the event handler is executed twice.

Regards

A1880
A1880 has attached the following file:
  • jbDynControl.zip (5.75 kB - 658 times downloaded - latest: Apr 3rd 2024, 9:15pm)

This post has been edited 1 times, last edit by "A1880" (Feb 15th 2009, 11:00pm)


Henning

Beginner

  • "Henning" is male
  • "Henning" started this thread

Posts: 9

Date of registration: Jan 15th 2009

Location: In Sweden, 50 km outside Östersund

Occupation: HW, FW & Interface developer

Hobbies: Cars, and ofcause my job ;)

  • Send private message

6

Saturday, January 17th 2009, 9:31pm

Manuels code also works with a CommandButton. Just change PictureBox to CommandButton.
The problem with Cmd BackColor though as in my other post.

/Henning

Rate this thread
WoltLab Burning Board