Results 1 to 8 of 8

Thread: What is an Operand/Operator in VBA?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    30

    What is an Operand/Operator in VBA?

    Hi,

    I'm trying to build code to calculate Halstead metrics.

    For this I need...
    A count of unique operators
    A total count of operators
    A count of unique operands
    A count of total operands

    Can anyone help with this please?

    For example... Is a function call an Operator?
    What about the parameters to a Sub?
    Do built in functions like Split or UCase UBound or whatever count as operators?

    TIA
    Lisa

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,589

    Re: What is an Operand/Operator in VBA?

    Hi Lisa,

    I would think that an operand is like a variable, possibly a constant, or maybe even a literal constant. I suppose, when you see something like the following....


    5 + a - 4 / b

    ... there'd be three operators (all unique): +, -, /
    And there'd be four operands (also all unique): 5, a, 4, b

    Take Care,
    Elroy

    EDIT1: And I'd think functions would be separate from all of that (although, in a certain sense, they might be called an operator).

    EDIT2: I'm not sure what the context of all of this is, but one way to find out is to test. If you're using some equation evaluator (possibly such as the Eval method of VBScript), that would certainly be easy enough. I'm not sure that VBScript counts those things though.
    Last edited by Elroy; Apr 29th, 2018 at 11:32 AM.
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    30

    Re: What is an Operand/Operator in VBA?

    Hi Elroy!!

    So far I've found counting the operators okay.... I think. Though whether a function is an operator is a mystery!! I've been on this for about a week now and have only just... in the last 1/2 hour... come across....

    "Unfortunately, there is a problem in distinguishing
    between operators and operands. This problem occurs
    because Halstead has provided an example2
    with
    specific illustrations of operators and operands, but
    without generic definitions applicable to any program
    context. That is, Halstead has not explicitly described
    the generic measurable concepts of operators and
    operands. He has asserted only that – in the example
    he provides – their description is intuitively obvious
    and requires no further explanation. In practice, for
    measurement purposes, intuition is insufficient to
    obtain accurate, repeatable and reproducible
    measurement results. "

    https://www.researchgate.net/profile...ds-Metrics.pdf

    Which basically means... as far as I can tell ... it's a SOL problem. Excuse the unladylike language.

    <Head Desk>

    If anyone has any insights here I'd be totally more than happy to hear them!

    Again
    TIA
    Lisa

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,589

    Re: What is an Operand/Operator in VBA?

    To me, the issue of whether a function is an operator is only slightly confusing. Personally, I would not count them as operators, and here's why. I have functions, that do enormous tasks in my primary application. Just as an example, Value from Array after Butterworth Filter is Applied, or Value from Array after Cubic Spline has been Applied, or Return Structure with All Kinds of File Info. These just don't feel like operators to me. And, in fact, we could have a function that was something like ...

    Code:
    
    Option Explicit
    
    Public Function SolveAllTheWorldsProblemsInAnHour() As Boolean
        ' Return whether or not it was accomplished, True/False.
    
        ' ...
    
    End Function
    
    
    But then, on the other side of the coin, I have a function like the following I use all the time:

    Code:
    
    
    Public Function dSafeDiv(dnum As Double, dden As Double) As Double
        On Error GoTo AnError
        dSafeDiv = dnum / dden
    AnError:
    End Function
    
    
    That one actually does feel like an operator. So, I don't see a perfect answer.

    Regarding Halstead metrics, maybe you could say a bit more about what you're actually trying to accomplish. Are you attempting to monitor the productiveness of various programmers? Or, is it some other objective?

    Take Care,
    Elroy
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,878

    Re: What is an Operand/Operator in VBA?

    It's exactly the same as in mathematics. Functions are not operators. That's why function parameters are called parameters and not operands.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    30

    Re: What is an Operand/Operator in VBA?

    Hi Elroy!

    I have a sub and a class that do the same thing but I'll just talk about the class coz I'm going to get rid of the Sub. I instantiate it to return as much information as I can about where the cursor is in the VBE. I call it ... creatively... cWhereAreWe. :-)

    Some of this is Project, CodePane, Component, Number of Dims, Number of comment lines, line where the Dims start and stop and lots more including an array of the Dims and an array of the code.

    I'm happy to post the code if anyone is interested. I **really** love feedback and improvements about/to my code.

    In amongst that information I want to give enough numbers for people to have an idea of how complex the procedure is. There seems to be a number of "accepted" measures. One is Lines of code. That's clear really... more code.. more "complex"... though I have some caveats about that. Another is the McCabe cyclomatic complexity derived from the number of paths through a piece of code... and another is the Helstead suite of "numbers".


    Rubber Duck reports a cyclomatic complexity number for a module for example but I've been on this for at least seven years on and off. I have to say though that Rubber Duck has put a thing up my bum!!

    Hence my Question.

    My own thoughts are that it's all relative... It depends on the client, the project, the "purpose", the customer restraints if any... so many things. And that you have to build up knowledge with all of that in mind and more even before you can come to any conclusions about code you come across in your environment.

    Having said that... metrics are ok to have and better than nothing as long as you are careful with the interpretations.

    My aim is to supply as many metrics as I can and let the client/user do what they want with them.

    Lisa

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    30

    Re: What is an Operand/Operator in VBA?

    Heya....

    If we have a line...
    A = B + C
    for me B and C are operands.

    If there is A function...
    Result = function(A,B)
    that returns A + B

    Does that make A and B Operands? And then does that make "function" an operator?

    Lisa

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,878

    Re: What is an Operand/Operator in VBA?

    Quote Originally Posted by lisagreen View Post
    If there is A function...
    Result = function(A,B)
    that returns A + B

    Does that make A and B Operands? And then does that make "function" an operator?
    No and no. The function is a function and A and B are parameters. Inside the function, + is an operator and the A and B parameters are its operands. Context is important.

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