Results 1 to 2 of 2

Thread: Some simple syntax questions ...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Californ-I- A


    This is the very basics ... but I'm curious what of the fallowing is meaningful and what is just old syntax carring over ...

    What is call for?

    Call function()
    or just using

    What is ByVal and when should it be used? That is, do I need to use it in my own functions?

    And I've noticed that ScaleWidth and Width have different results, and I just use scalewidth when available ... but what is the difference between the two?

    Thanks y'all, I'm off to work, hope to read responces when I get back

    Micah Carrick
    Ordinary joe, only not named joe.
    ICQ: 53480225

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    San Jose, CA


    This is from Help.

    You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded.

    Passing Arguments to Procedures

    Usually the code in a procedure needs some information about the state of the program to do its job. This information consists of variables passed to the procedure when it is called. When a variable is passed to a procedure, it is called an argument.

    Argument Data Types
    The arguments for procedures you write have the Variant data type by default. However, you can declare other data types for arguments. For example, the following function accepts a string and an integer:

    Function WhatsForLunch(WeekDay As String, Hour _
    As Integer) As String
    ' Returns a lunch menu based on the day and time.
    If WeekDay = "Friday" then
    WhatsForLunch = "Fish"
    WhatsForLunch = "Chicken"
    End If
    If Hour > 4 Then WhatsForLunch = "Too late"
    End Function

    For More Information Details on Visual Basic data types are presented earlier in this chapter. You can also see the Language Reference for specific data types.

    Passing Arguments By Value
    Only a copy of a variable is passed when an argument is passed by value. If the procedure changes the value, the change affects only the copy and not the variable itself. Use the ByVal keyword to indicate an argument passed by value.

    For example:

    Sub PostAccounts(ByVal intAcctNum as Integer)
    . ' Place statements here.
    End Sub

    Passing Arguments By Reference
    Passing arguments by reference gives the procedure access to the actual variable contents in its memory address location. As a result, the variable's value can be permanently changed by the procedure to which it is passed. Passing by reference is the default in Visual Basic.

    If you specify a data type for an argument passed by reference, you must pass a value of that type for the argument. You can work around this by passing an expression, rather than a data type, for an argument. Visual Basic evaluates an expression and passes it as the required type if it can.

    The simplest way to turn a variable into an expression is to enclose it in parentheses. For example, to pass a variable declared as an integer to a procedure expecting a string as an argument, you would do the following:

    Sub CallingProcedure()
    Dim intX As Integer
    intX = 12 * 3
    End Sub

    Sub Foo(Bar As String)
    MsgBox Bar 'The value of Bar is the string "36".
    End Sub

    ScaleHeight, ScaleWidth Properties

    Return or set the number of units for the horizontal (ScaleWidth) and vertical (ScaleHeight) measurement of the interior of an object when usinggraphics methods or when positioning controls. For MDIForm objects, not available atdesign time and read-only atrun time.


    object.ScaleHeight [= value]

    object.ScaleWidth [= value]

    The ScaleHeight and ScaleWidth property syntaxes have these parts:

    Part Description
    Object Anobject expression that evaluates to an object in the Applies To list.
    Value Anumeric expression specifying the horizontal or vertical measurement.


    You can use these properties to create a custom coordinate scale for drawing or printing. For example, the statement ScaleHeight = 100 changes the units of measure of the actual interior height of the form. Instead of the height being n current units (twips, pixels, ...), the height will be 100 user-defined units. Therefore, a distance of 50 units is half the height/width of the object, and a distance of 101 units will be off the object by 1 unit.

    Use the ScaleMode property to define a scale based on a standard unit of measurement, such astwips,points,pixels, characters, inches, millimeters, or centimeters.

    Setting these properties to positive values makes coordinates increase from top to bottom and left to right. Setting them to negative values makes coordinates increase from bottom to top and right to left.

    Using these properties and the related ScaleLeft and ScaleTop properties, you can set up a full coordinate system with both positive and negative coordinates. All four of these Scale properties interact with the ScaleMode property in the following ways:

    Setting any other Scale property to any value automatically sets ScaleMode to 0. A ScaleMode of 0 is user-defined.

    Setting ScaleMode to a number greater than 0 changes ScaleHeight and ScaleWidth to the new unit of measurement and sets ScaleLeft and ScaleTop to 0. In addition, the CurrentX and CurrentY settings change to reflect the new coordinates of the current point.
    You can also use the Scale method to set the ScaleHeight, ScaleWidth, ScaleLeft, and ScaleTop properties in one statement.

    Note The ScaleHeight and ScaleWidth properties aren't the same as the Height and Width properties.

    For MDIForm objects, ScaleHeight and ScaleWidth refer only to the area not covered by PictureBox controls in the form. Avoid using these properties to size a PictureBox in the Resize event of an MDIForm.


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