Results 1 to 5 of 5

Thread: [RESOLVED] disable further textbox changes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Resolved [RESOLVED] disable further textbox changes

    i want to change textbox value only one time and disable it , so even if i click command2 it should not change, value must remain same
    how can i do this ?

    Private Sub Command1_Click()
    Text1.Text = "1"
    End Sub

    Private Sub Command2_Click()
    Text1.Text = "2"
    End Sub

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: disable further textbox changes

    Quote Originally Posted by geekmaro View Post
    i want to change textbox value only one time and disable it , so even if i click command2 it should not change, value must remain same
    how can i do this ?
    To prevent the user from making changes, consider setting the .Locked property to true.
    As for your code from changing the text, your command button click events can check if .Locked is True and if so, exit sub immediately.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: disable further textbox changes

    Quote Originally Posted by geekmaro View Post
    ... so even if i click command2 it should not change ...
    The Locked nor Enabled property will stop code from changing the Text property. This is sort of why we call ourselves "programmers". If you want to stop code from doing it, then set a Boolean flag somewhere:

    Code:
    
    Option Explicit
    
    Dim mbDoneWithChanges As Boolean
    
    Private Sub Command1_Click()
        If Not mbDoneWithChanges Then
            Text1.Text = "1"
        End If
        mbDoneWithChanges = True
    End Sub
    
    Private Sub Command2_Click()
        If Not mbDoneWithChanges Then
            Text1.Text = "2"
        End If
        mbDoneWithChanges = True
    End Sub
    
    
    Take Care,
    Elroy

    EDIT: Or, I suppose you could use the Locked property of the textbox as your boolean flag, as LaVolpe suggested.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: disable further textbox changes

    Quote Originally Posted by Elroy View Post
    The Locked nor Enabled property will stop code from changing the Text property. This is sort of why we call ourselves "programmers". If you want to stop code from doing it, then set a Boolean flag somewhere:

    Code:
    
    Option Explicit
    
    Dim mbDoneWithChanges As Boolean
    
    Private Sub Command1_Click()
        If Not mbDoneWithChanges Then
            Text1.Text = "1"
        End If
        mbDoneWithChanges = True
    End Sub
    
    Private Sub Command2_Click()
        If Not mbDoneWithChanges Then
            Text1.Text = "2"
        End If
        mbDoneWithChanges = True
    End Sub
    
    
    Take Care,
    Elroy

    EDIT: Or, I suppose you could use the Locked property of the textbox as your boolean flag, as LaVolpe suggested.
    amazing code it solved the problem simple and clean
    thank u very much

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] disable further textbox changes

    You should really examine your alternatives. If you are going to learn, you need to try vs. giving what's just handed to you without question.

    You could've used 99% of your original code:
    Code:
    Private Sub Command1_Click()
    If Text1.Locked = False Then 
        Text1.Text = "1"
        Text1.Locked = True
    End If
    End Sub
    
    Private Sub Command2_Click()
    If Text1.Locked = False Then 
        Text1.Text = "2" 
        Text1.Locked = True
    End If
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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