saboh12617
Board Regular
- Joined
- May 31, 2024
- Messages
- 80
- Office Version
- 365
- Platform
- Windows
Hi,
In a class module, I define a private attribute as a Userform, and then a public withEvent attribute as a SpinButton. And then the private subs mySpinButton_SpinUp() and spinDown.
Why when i show the userform and click the coresponding buttons, my events are not called correctly ? is it because of the scope of the private "mother" userform that kind of blocs the calls to the child public button, even if it is declared as public ?
Otherwise i really dont understand. I can post the code but it could be a little bit confusing as i have the code for the userform, for the "frame bloc" ie the class im talking about, and then a test sub in a module to implement all of this.
The idea is that i define a small frame with a textbox, a label and a spinbutton. When clicked on the spinbutton, the textbox updates. I can have an undefined quantity of those frames, that's why, i read, it is convenient using a class for this frame object.
The code of the Frame bloc :
EDIT : PickAttributes is the name of the userform on which i implement this element.
In a class module, I define a private attribute as a Userform, and then a public withEvent attribute as a SpinButton. And then the private subs mySpinButton_SpinUp() and spinDown.
Why when i show the userform and click the coresponding buttons, my events are not called correctly ? is it because of the scope of the private "mother" userform that kind of blocs the calls to the child public button, even if it is declared as public ?
Otherwise i really dont understand. I can post the code but it could be a little bit confusing as i have the code for the userform, for the "frame bloc" ie the class im talking about, and then a test sub in a module to implement all of this.
The idea is that i define a small frame with a textbox, a label and a spinbutton. When clicked on the spinbutton, the textbox updates. I can have an undefined quantity of those frames, that's why, i read, it is convenient using a class for this frame object.
The code of the Frame bloc :
EDIT : PickAttributes is the name of the userform on which i implement this element.
VBA Code:
Private Const BLOCK_W As Long = 66
Private Const BLOCK_H As Long = 72
Private Type tAttributeFrame
tFrame As MSForms.Frame
tTextBox As MSForms.TextBox
name As String
value As Long ' faire un total
minVal As Long
maxVal As Long
End Type
Private this As tAttributeFrame
Private daddyForm As PickAttributes
Public WithEvents spinButt As MSForms.SpinButton
Public Sub DefineFrame(dadF As PickAttributes, fieldName As String, minVal As Long, maxVal As Long)
Set daddyForm = dadF
this.name = fieldName
this.value = minVal
this.minVal = minVal
this.maxVal = maxVal
Set this.tFrame = daddyForm.Controls.Add("Forms.Frame.1", "FRAME." & fieldName, True)
With this.tFrame
.Height = BLOCK_H
.Width = BLOCK_W
.Caption = fieldName
End With
Set this.tTextBox = this.tFrame.Controls.Add("Forms.TextBox.1", "TEXTBOX." & fieldName, True)
With this.tTextBox
.Height = 25
.Width = 25
.value = this.value
.Top = 12
.Left = 6
.TextAlign = fmTextAlignCenter
.Locked = True
End With
Set spinButt = this.tFrame.Controls.Add("Forms.SpinButton.1", "SPINBUTT." & fieldName, True)
With spinButt
.Height = 25
.Width = 14
.Top = 12
.Left = 42
.min = minVal
.max = maxVal
End With
End Sub
Public Sub DefinePos(dVertical, dHoriz)
With this.tFrame
.Top = dVertical
.Left = dHoriz
End With
End Sub
Private Sub class_initialize()
' todo default title etc
End Sub
Private Sub spinButt_SpinDown()
this.value = WorksheetFunction.max(minVal, this.value - 1)
this.tTextBox.Text = this.value
Debug.Print "hi", this.value ' not called
End Sub
Private Sub spinButt_SpinUp()
this.value = WorksheetFunction.min(maxVal, this.value + 1)
this.tTextBox.Text = this.value
End Sub
Public Property Get value() As Long
value = this.value
End Property