Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable / enable controls

Status
Not open for further replies.

RonVaught

Programmer
Oct 22, 2002
62
US
I stumbled across a way to disable / enable controls based on two text strings being the equal. In the sample below, Command1’s click enable the label. Cammand2 disabled the label. Does anyone see anything wrong with this approach? Some of the other programmers I work with don’t trust it. Was wanting some other opinions or if anyone could tell me why this is a bad approach.

Private Sub Command1_Click()
Me.Label1.Enabled = "Blah" = "Blah"
End Sub

Private Sub Command2_Click()
Me.Label1.Enabled = "Blah" = "halB"
End Sub
 
The construction is perfecty valid cos what you are saying is:

"Blah" = "Blah" evaluates to True or false, and this evaluation is then assigned to the var/property (in this case Me.Label1.Enabled).
I do myself use this construction cos it was simple to write and simple to use.

Carlos Paiva
 
As Carlos says, it should be fine. You may need to watch for leading or trailing spaces, if so use Trim()
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
How do the other programers you work with assign to a boolean variable to comparision?

Take these two examples:

Dim a As Boolean
If "A" = "A" Then
a = True
Else
a = False
End If

Or,

Dim a As Boolean
If 1 + 2 = 3 Then
a = True
Else
a = False
End If
========================

Actually a more efficient way to write this is.

a = "A" = "A"

Or

a = 1 + 2 = 3

======================
You should write your example as:

Me.Label1.Enabled = ("Blah" = "Blah")

using the ()

a = ("A" = "A")

may make it faster and easier to see what is being done.

But you do not need to.


[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
As I said before, most of my boolean assigns are made this way. It comes ahead, when i'm porting a C code to VB. C code is from RTOS microcontroller machine, i've designed several years ago, and by mistake i'd placed 2 lines of C code. When in debug, i run the program, a sintax error comes on one line, and not in the other. Then i analise, and found the evaluation that VB does.
Anyway, it's a pitty that some C constructions are'nt avaiable in VB Like: xpto= Var1 = Var2;

Sorry my bad english.
Thanks
Carlos Paiva
 
The reason that VB cannot support the multiple assignment X = A = B; like you can in C is that VB overloads the "=" as both the relation operator and the assignment operator which C does not.

The following VB statement (First = is assignment, second is relational)
Me.Label1.Enabled = "Blah" = "Blah"
is the C equivalent of
Me.Label1.Enabled = ("Blah" == "Blah");

Since the "=" operator is overloaded in VB, and the definition of an assignment statement is
Variable = Expression
It makes more sense for the "=" operator to be treated as a relational operator when inside the expression. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
nicely explained CajunCenturion [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top