01.09.2014 Views

WM Basic™ User's Manual - Classes

WM Basic™ User's Manual - Classes

WM Basic™ User's Manual - Classes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1 Putting it All Together: A Simple <strong>WM</strong> Basic Program 37<br />

Specifying Objects to be Controlled<br />

To link <strong>WM</strong>Input to other objects in Working Model, you simply need to assign the input ID<br />

to the desired property to be controlled.<br />

For example, the following code segment shows how to create a new control to specify the<br />

initial x-velocity of a body called Circle (assume Circle has been declared and defined as a<br />

valid <strong>WM</strong>Body object):<br />

Dim Slider as <strong>WM</strong>Input<br />

Set Slider = <strong>WM</strong>.ActiveDocument.NewInput()<br />

Circle.VX.Formula = "input["+str$(Slider.ID)+"]"<br />

The third line above warrants an explanation. Typically, you would specify an expression<br />

such as "input[5]", but the ID number of the Input just created may not be necessarily 5.<br />

The ID property of the <strong>WM</strong>Input object retains the number, and the number is converted to a<br />

string by the str$ function. Finally, the number is concatenated with "input[" followed<br />

by "]" to create a valid Working Model formula expression.<br />

Changing the Input Value<br />

An input control in Working Model is a flexible tool which allows you to change its value<br />

while the simulation is running. In interactive operation, the user moves the slider bar to<br />

change the input values. In scripting operation, you can simply modify the Value property of<br />

the <strong>WM</strong>Input object to change the value. The Value property holds values of type Double.<br />

For example, the following line sets the slider value of a <strong>WM</strong>Input object called Slider to be<br />

5.5.<br />

Slider.Value = 5.5<br />

Putting it All Together: A Simple <strong>WM</strong> Basic<br />

Program<br />

Now that you know the fundamental elements of Working Model Basic, we will walk you<br />

through a simple <strong>WM</strong> Basic program.<br />

Spring-Mass Simulation<br />

The following code performs the following tasks:<br />

1. Creates a new Working Model document.<br />

2. Creates a disk.<br />

3. Attaches a spring to the disk.<br />

4. Creates an input slider to specify the downward initial velocity of the<br />

disk.<br />

4. Creates a meter to measure the y position and velocity of the disk.<br />

5. Runs the simulation for 50 frames and exports the meter data to a file.<br />

6. Closes and saves the document.<br />

Most of the functions are derived from examples provided in the preceding sections in the<br />

current chapter.<br />

Sub Main()<br />

' Declare objects<br />

Dim Doc as <strong>WM</strong>Document<br />

Dim Disk as <strong>WM</strong>Body<br />

Dim Spring1 as <strong>WM</strong>Constraint

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!