-
Aug 11th, 2020, 10:51 PM
#1
Thread Starter
Addicted Member
[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
-
Aug 11th, 2020, 11:09 PM
#2
Re: disable further textbox changes
Originally Posted by geekmaro
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.
-
Aug 11th, 2020, 11:13 PM
#3
Re: disable further textbox changes
Originally Posted by geekmaro
... 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.
-
Aug 11th, 2020, 11:22 PM
#4
Thread Starter
Addicted Member
Re: disable further textbox changes
Originally Posted by Elroy
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
-
Aug 11th, 2020, 11:26 PM
#5
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
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
|