Alpha Video Training
Results 1 to 11 of 11

Thread: [ or ( - What's the difference?

  1. #1
    Member
    Real Name
    Charles Kistler
    Join Date
    Dec 2000
    Posts
    94

    Default [ or ( - What's the difference?

    In reading the help files and documentation, I've noticed that almost always arrays are typed like this:

    ArrayName[n]

    Is there a difference between

    ArrayName[n] and ArrayName(n)? If so, what is it?

    Just curious.

    Charles

  2. #2
    Member
    Real Name
    Doug Chanley
    Join Date
    Apr 2000
    Posts
    563

    Default RE: [ or ( - What's the difference?

    Charles

    Normaly when Alpha5 uses [] in describing the syntax
    of a function the brackets mean it is an optional argument.
    In which the actual [] is not included with the argument.

    In the case of an array it would seem that it is the proper
    syntax for defining the number of elements in an array.

    The [] accepts a numeric value only in the same way the {}
    brackets are used for dates. I am thinking that () accepts
    a character string thus to represent a numeric value
    enclosed in () would be trace.writeln(str(recno))to convert
    the numeric value to a character string.

    I havent tried to define an array using DIM arraynames(4) as C
    I believe that you would get an error using that syntax....
    but havent tried it to know for sure.

  3. #3
    Member
    Real Name
    Charles Kistler
    Join Date
    Dec 2000
    Posts
    94

    Default RE: [ or ( - What's the difference?

    I just put these four statements into my autoexec script and it ran without errors:

    DIM GLOBAL number(2) AS N
    DIM GLOBAL numbers[2] AS N
    DIM GLOBAL character(2) AS C
    DIM GLOBAL characters[2] AS C

    Then, in the Interactive window, I assigned variables to

    character(1), character[1], characters(1), characters[1], number(1), number[1], numbers(1), numbers[1], etc.

    then displayed them using ? and all of the variables were assigned.

    I know that [] in syntax statements ususally means optional. I just was curious why they were used for array indexes. It appears that it makes no difference at all which one is used.

    Thanks.

    Charles

  4. #4
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default RE: [ or ( - What's the difference?

    Charles,

    It may make no difference, but you should always try to use syntax as documented unless there is no other way. The reason for this is that, the program, in general, will try to match the documentation. In a new version or maintenance release, the alternatives may no longer work.

    Regards,

    Ira J. Perlow
    Computer Systems Design & Associates
    csda@mediaone.net

  5. #5
    Member
    Real Name
    Charles Kistler
    Join Date
    Dec 2000
    Posts
    94

    Default RE: [ or ( - What's the difference?

    I agree. I was just curious, though, because of these two pages from the xBasic help:

    Here, the documentation uses ().
    *************************
    DIM
    Syntax:

    DIM [SHARED] [GLOBAL] VariableName [(Array Size)] AS Value Type

    Description:

    Used to declare and allocate a variable. When declaring a variable as an array, you must supply the maximum subscript value in parenthesis. The variable type is indicated through the Value Type, a single character (N - numeric, D - date, C - character, L - logical, P - pointer, B - BLOB) at the end of the statement.

    You can ... (text omitted) ... sessions.

    Examples:

    DIM flds(256) AS C 'a 256 element array
    DIM SHARED flag AS L 'a shared variable called flag
    DIM field_value AS D 'a local value, explicitly declared

    *************************

    Now, over here, it uses []:
    ********************
    Defining An Array

    To store a series of data values of the same data type together under the same variable name, declare the variable as an array. Arrays are useful for collecting and processing lists of information. They must be explicitly defined with the DIM statement before they are used. The declaration must include the Array Size which is the maximum number of data elements the array will contain.

    For example, the following statement declares an array of character strings holding five elements:

    DIM names[5] AS C

    This array can be used to collect and store a list of five names. The contents of the array elements are assigned like any other variable using the assignment operator (=). The number of the element in which you want to put the data must also be supplied. For example:

    names[1] = "Henry"
    names[2] = "Burt"
    names[3] = "Ernie"
    names[4] = "Linda"
    names[5] = "Cheryl"
    ********************

    Sigh.

    Charles

  6. #6
    Member
    Real Name
    Charles Kistler
    Join Date
    Dec 2000
    Posts
    94

    Default RE: [ or ( - What's the difference?

    I've found a situation where it does make a difference. This piece of code reads an array glbMailName() of glbMailMax(2) elements and inserts glbMailName() as the choice and str(i) as the value of a radio button object:

    '*** START
    FOR i=1 to glbMailMax(2)
    IF i>1 THEN
    optDShip.CHOICE.LIST.INSERT()
    END IF

    ' CHOICE.LIST must be []
    optDShip.CHOICE.LIST[i].TEXT=glbMailName[i+10]

    ' CHOICE.LIST must be []
    optDShip.CHOICE.LIST[i].VALUE=STR(i,1,0)

    NEXT

    OptDShip.OBJECT.HEIGHT=glbMailMax(2)*.17

    '*** END

    What's strange is glbMailMax can use () or [] except for the very last line. It must be () here.

    Short of an answer from Those Who Know, I suppose [] should be used whenever an object is involved, and () used whenever a variable is involved.

    Charles

  7. #7
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default RE: [ or ( - What's the difference?

    Charles,

    I'm not buying what you said (without more proof). I would believe that [] would always work. What's the dimensioning or definition of glbMailMax(2). This looks more like a function call.

    All uses should be with brackets including the 1st line. The last line may be confused by the faulty definition in the 1st line.

    Regards,

    Ira J. Perlow
    Computer Systems Design & Associates
    csda@mediaone.net

  8. #8
    Member
    Real Name
    Charles Kistler
    Join Date
    Dec 2000
    Posts
    94

    Default RE: [ or ( - What's the difference?

    Ira:

    glbMailMax is numeric, dimensioned as global in my autoexec script:

    DIM GLOBAL glbMailMax[2] AS N

    It contains the total number of MailNames (currently 4) read in from a parameter table.

    glbMailName is character, dimensioned as global in my autoexec script:

    DIM GLOBAL glbMailName[20] AS C

    Merely changing the () to [] in the statement that sets the height of the radio buttons (optDShip) causes the height NOT to be set:

    OptDShip.OBJECT.HEIGHT=glbMailMax(2)*.17 'Works
    OptDShip.OBJECT.HEIGHT=glbMailMax[2]*.17 'Does not work

    I don't know the height of the radio buttons resulting from line 2 (it looks like 3 or 4 inches).

    Charles

  9. #9
    Member
    Real Name
    Charles Kistler
    Join Date
    Dec 2000
    Posts
    94

    Default RE: [ or ( - What's the difference?

    Here is a small database that mimics the one I'm designing.

    Charles

  10. #10
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default RE: [ or ( - What's the difference?

    Charles,

    Alpha 5 may have a slight bug in syntax ininterpretation of the formula. The following do work. As far as I can tell, it's the combination of "]*" causing the problem. Other operators like "+" and "-" do not seem to cause a problem.

    OptDShip.OBJECT.HEIGHT=(glbMailMax[2])*.17 'Does work OptDShip.OBJECT.HEIGHT=.17*glbMailMax[2] 'Does work

    In general, when ever you have a syntax problem, it is wise to put extra parenthesis around each part to force Alpha to properly evaluate this.

    I'm surprised that Alpha interpreted the line properly the other way, but I'll still stick by my original statement to use brackets for array references. By sticking with the brackets, any future corrections to the syntax will not fail your code.

    Regards,

    Ira J. Perlow
    Computer Systems Design & Associates
    csda@mediaone.net

  11. #11
    Member
    Real Name
    Charles Kistler
    Join Date
    Dec 2000
    Posts
    94

    Default RE: [ or ( - What's the difference?

    Ira:

    Good advice. After posting the test.zip last night, I shut down and went to bed. This morning, before checking the forum, I tried

    OptDShip.OBJECT.HEIGHT=glbMailMax[2]*.17

    and it worked fine. I tried

    OptDShip.OBJECT.HEIGHT=.17*glbMailMax[2]

    like you did and it worked, too.

    I wonder if A5 got a little unstable during my development work. I tend to make a lot of typing errors.

    As a final question to this, is the variable assigned to an option button/check box/list box/etc. object restricted to being a character type, or can it be a numeric type? You might want to read msg. 45564 to see the background on this. I ask this because my option buttons always work when the variable is character, but they don't always work when it is numeric.

    Thanks

    Charles

Similar Threads

  1. no difference
    By Tony Agnone in forum Alpha Five Version 5
    Replies: 1
    Last Post: 08-12-2005, 11:13 AM
  2. What is the difference?
    By Tommy in forum Alpha Five Version 5
    Replies: 4
    Last Post: 02-14-2005, 07:37 AM
  3. Why The Difference
    By Phil Rolf in forum Web Application Server v6
    Replies: 7
    Last Post: 11-23-2004, 02:45 AM
  4. Why The Difference
    By Phil Rolf in forum Alpha Five Version 6
    Replies: 5
    Last Post: 11-21-2004, 08:33 AM
  5. What's the difference?
    By Jerry Gray in forum Alpha Five Version 6
    Replies: 0
    Last Post: 10-27-2004, 08:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •