|
-
Apr 30th, 2008, 11:23 AM
#1
Thread Starter
Hyperactive Member
Locking down textboxes.
hello all,
I use the following code to lock my textboxes:
vb Code:
Public Sub Lockdown()
For Each tb In Me.Controls
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
End Sub
My problem is this: I have 3 frames in an array and only want 2 of the 3 frames textboxes to be locked.
I try different variations of the above code, but nothing works as of yet.
Thanks ahead of time.
-
Apr 30th, 2008, 11:51 AM
#2
Re: Locking down textboxes.
I have 3 frames in an array and only want 2 of the 3 frames textboxes to be locked.
What is the name of the frame and the name of the textboxes which you want to lock?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Apr 30th, 2008, 12:22 PM
#3
Thread Starter
Hyperactive Member
Re: Locking down textboxes.
the name of the frame is frame, but I have an array of the frame:
frame(0), frame(1), and frame(2)
I want to lock the textboxes in one shot and not have to list them individually.
-
Apr 30th, 2008, 01:00 PM
#4
Re: Locking down textboxes.
I haven't tried this as I don't have access to vb6 here in the office, so I am doing this from memory. please amend if there are any syntax errors
Code:
Sub Lockdown()
For i = 1 To 2 '2 because you want textboxes in 2 frames to be disabled
For Each tb In Frame(i).Controls 'add or subtract from i as required
If TypeOf tb Is TextBox Then
tb.Locked = True
End If
Next
Next
End Sub
Hope this helps..
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Apr 30th, 2008, 01:12 PM
#5
Thread Starter
Hyperactive Member
Re: Locking down textboxes.
koolsid,
Thanks for your reply, but unfortunately it is not working.
There is no .Controls for the frame(i)
-
Apr 30th, 2008, 01:15 PM
#6
Thread Starter
Hyperactive Member
Re: Locking down textboxes.
OK, this is what I have and it is working, kindof:
vb Code:
Public Sub Lockdown()
For i = 1 To 2
For Each tb In frame(i).Container
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
Next i
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
End Sub
But the problem is that all of the textboxes backcolor is colored instead of just the 2 frames.
Anyone have any ideas?
-
Apr 30th, 2008, 01:18 PM
#7
Re: Locking down textboxes.
But the problem is that all of the textboxes backcolor is colored instead of just the 2 frames.
Is this true for the .locked property as well? what I mean is that all textboxes are getting locked? As per your code only the textboxes in frame(1) and frame(2) should get locked
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Apr 30th, 2008, 01:19 PM
#8
Re: Locking down textboxes.
I would suggest one further step, and that is the ability to toggle the lock
Code:
Private Sub Lockdown(blnLocked As Boolean)
Dim i As Long
Dim tb As Control
For i = 1 To 2 '2 because you want textboxes in 2 frames to be disabled
For Each tb In Frame(i).Controls 'add or subtract from i as required
If TypeOf tb Is TextBox Then
tb.Locked = blnLocked
End If
Next
Next
End Sub
Private Sub cmdLock_Click()
Lockdown True
End Sub
Private Sub cmdUnLock_Click()
LockDown False
End If
-
Apr 30th, 2008, 01:28 PM
#9
Thread Starter
Hyperactive Member
Re: Locking down textboxes.
Hack,
Yes I have both Lockdown and UnLock in my program, but I like your way much better using the boolean.
koolsid,
Is this true for the .locked property as well? what I mean is that all textboxes are getting locked? As per your code only the textboxes in frame(1) and frame(2) should get locked
Ok, I have a total of 4 frames. 3 of the frames are in an array; they are named frame.
the 4th frame is named frame1.
The code above locks the textboxes in the 2 frames that I want, but the backcolor of all textboxes is colored and only the 2 frames textboxes should be colored.
-
Apr 30th, 2008, 01:37 PM
#10
Thread Starter
Hyperactive Member
Re: Locking down textboxes.
Ok, I just used a quick fix and I cant figure out how to do it otherwise.
I just added "txtLookUp.BackColor = vbWhite" at the end of the sub.
Thanks anyways.
The code looks like this now:
vb Code:
Public Sub Lockdown(blnLocked As Boolean)
For Each tb In frame(0).Container
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
txtLookUp.BackColor = vbWhite
End Sub
-
Apr 30th, 2008, 01:41 PM
#11
Re: Locking down textboxes.
You aren't using the boolean variable that you are passing.
-
Apr 30th, 2008, 01:54 PM
#12
Thread Starter
Hyperactive Member
Re: Locking down textboxes.
Hack wrote:
You aren't using the boolean variable that you are passing.
Not sure what you mean Hack.
This is what I have with your code:
vb Code:
Public Sub Lockdown(blnLocked As Boolean)
For Each tb In frame(0).Container
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
txtLookUp.BackColor = vbWhite
End Sub
and this in the other subs:
vb Code:
Public Sub Locked()
Lockdown True
End Sub
Public Sub UnlockTB()
Lockdown False
End Sub
OK, now I have this and it seems to work fine:
vb Code:
Public Sub Lockdown(blnLocked As Boolean)
If blnLocked = True Then
For Each tb In frame(0).Container
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
txtLookUp.BackColor = vbWhite
Else
For Each tb In frame(0).Container
If TypeOf tb Is TextBox Then
tb.Locked = False
tb.BackColor = vbWhite
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = True
End If
Next
End If
End Sub
Last edited by cfd33; Apr 30th, 2008 at 02:00 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|