Results 1 to 12 of 12

Thread: Locking down textboxes.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    449

    Locking down textboxes.

    hello all,

    I use the following code to lock my textboxes:

    vb Code:
    1. Public Sub Lockdown()
    2.     For Each tb In Me.Controls
    3.         If TypeOf tb Is TextBox Then
    4.             tb.Locked = True
    5.             tb.BackColor = &H80FF80
    6.         End If
    7.     Next
    8.    
    9.     For Each dt In Me.Controls
    10.         If TypeOf dt Is DTPicker Then
    11.             dt.Enabled = False
    12.         End If
    13.     Next
    14. 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.

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    449

    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.

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    449

    Re: Locking down textboxes.

    koolsid,

    Thanks for your reply, but unfortunately it is not working.

    There is no .Controls for the frame(i)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    449

    Re: Locking down textboxes.

    OK, this is what I have and it is working, kindof:
    vb Code:
    1. Public Sub Lockdown()
    2.     For i = 1 To 2
    3.     For Each tb In frame(i).Container
    4.         If TypeOf tb Is TextBox Then
    5.             tb.Locked = True
    6.             tb.BackColor = &H80FF80
    7.         End If
    8.     Next
    9.     Next i
    10.     For Each dt In Me.Controls
    11.         If TypeOf dt Is DTPicker Then
    12.             dt.Enabled = False
    13.         End If
    14.     Next
    15. End Sub

    But the problem is that all of the textboxes backcolor is colored instead of just the 2 frames.

    Anyone have any ideas?

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    449

    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.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    449

    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:
    1. Public Sub Lockdown(blnLocked As Boolean)
    2.  
    3.     For Each tb In frame(0).Container
    4.         If TypeOf tb Is TextBox Then
    5.             tb.Locked = True
    6.             tb.BackColor = &H80FF80
    7.         End If
    8.     Next
    9.    
    10.    
    11.     For Each dt In Me.Controls
    12.         If TypeOf dt Is DTPicker Then
    13.             dt.Enabled = False
    14.         End If
    15.     Next
    16.    
    17.     txtLookUp.BackColor = vbWhite
    18. End Sub

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Locking down textboxes.

    You aren't using the boolean variable that you are passing.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    449

    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:
    1. Public Sub Lockdown(blnLocked As Boolean)
    2.  
    3.     For Each tb In frame(0).Container
    4.         If TypeOf tb Is TextBox Then
    5.             tb.Locked = True
    6.             tb.BackColor = &H80FF80
    7.         End If
    8.     Next
    9.    
    10.    
    11.     For Each dt In Me.Controls
    12.         If TypeOf dt Is DTPicker Then
    13.             dt.Enabled = False
    14.         End If
    15.     Next
    16.    
    17.     txtLookUp.BackColor = vbWhite
    18. End Sub

    and this in the other subs:
    vb Code:
    1. Public Sub Locked()
    2.     Lockdown True
    3. End Sub
    4.  
    5. Public Sub UnlockTB()
    6.     Lockdown False
    7. End Sub


    OK, now I have this and it seems to work fine:

    vb Code:
    1. Public Sub Lockdown(blnLocked As Boolean)
    2.     If blnLocked = True Then
    3.    
    4.         For Each tb In frame(0).Container
    5.             If TypeOf tb Is TextBox Then
    6.                 tb.Locked = True
    7.                 tb.BackColor = &H80FF80
    8.             End If
    9.         Next
    10.    
    11.         For Each dt In Me.Controls
    12.             If TypeOf dt Is DTPicker Then
    13.                 dt.Enabled = False
    14.             End If
    15.         Next
    16.         txtLookUp.BackColor = vbWhite
    17.     Else
    18.         For Each tb In frame(0).Container
    19.             If TypeOf tb Is TextBox Then
    20.                 tb.Locked = False
    21.                 tb.BackColor = vbWhite
    22.             End If
    23.         Next
    24.        
    25.         For Each dt In Me.Controls
    26.             If TypeOf dt Is DTPicker Then
    27.                 dt.Enabled = True
    28.             End If
    29.         Next
    30.     End If
    31.    
    32. 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
  •  



Click Here to Expand Forum to Full Width