Reputation: 485
I'm missing some basic concepts and I don't know what they are. I'm getting a Compile Error "invalid use of property" when I use my user form to update tab strips. I'm trying to trigger an update to the Tab strip that responds to valid integer numbers entered into the Text box. Below is my current code.
I'm also don't know how to check the count in the Tab index and then add to the count help on this would also be appreciated.
Another Error I get is when a number value is checked by the IsValid Function it asks about a Debug when a Character is entered. Am I checking the input incorrectly?
The image below shows the form layers. Where Test1 is a Frame (on Userform page), TabStrip is located within the same frame as the Text Box (referenced in the code as TStrip1).
Function IsValid(numIn As Integer) As Boolean
IsValid = (numIn Like [1-15])
End Function
Private Sub TextBox11_Change()
Dim ValidNum As Integer
ValidNum = TextBox11
Call IsValid(ValidNum)
Dim x As Integer
x = TextBox11
Call TStrip1(x)
End Sub
Private Function TStrip1_(ByRef,ByVal TStrip1) As Integer
Dim x As Integer
Dim TabNum As Integer
TabNum = x
UserForm1.TStrip1.TabIndex.Add = TabNum
End Function
Private Sub TStrip1_Change()
End Sub
Upvotes: 0
Views: 2301
Reputation: 739
The 'Invalid use of property' error is caused by:
Private Function TStrip1_(ByRef,ByVal TStrip1) As Integer
You specified ByRef AND ByVal for the argument. Changing that line to:
Private Function TStrip1_(TStrip1) As Integer
should remove that error.
I would, however, rewrite your code like so:
Option Explicit 'always use option explicit (just do)
Private Function IsValid(numIn As Variant) As Boolean
Dim n As Long
n = Val(numIn) 'cast to long
'check if n is between 1 and 15:
If n > 0 And n < 16 Then
IsValid = True
Else
IsValid = False
End If
End Function
Private Sub TextBox1_Change()
Dim ValidNum As Long
If IsValid(Me.TextBox1.Value) Then
ValidNum = Val(Me.TextBox1.Value)
Else
Exit Sub
End If
Call AdjTabs(ValidNum)
End Sub
Private Sub AdjTabs(n As Long)
Dim i As Long
If Me.TabStrip1.Tabs.Count = n Then
Exit Sub
ElseIf Me.TabStrip1.Tabs.Count < n Then
For i = Me.TabStrip1.Tabs.Count To n - 1
Me.TabStrip1.Tabs.Add
Next i
Else
For i = Me.TabStrip1.Tabs.Count To n + 1 Step -1
Me.TabStrip1.Tabs.Remove (Me.TabStrip1.Tabs.Count - 1)
Next i
End If
End Sub
only thing left is to change the tabs names, but that's up to you now. I'm sure you can figure that out.
Upvotes: 3