DefType.w height DefType.f distance, speed, time width.w counter.b DefType$ addressThe first line in that small section of code was DefType.w height. This shows one way of using the DefType keyword to create a variable. In this case it creates a single variable called "height" and it is a word type.
The second line, DefType.f distance, speed, time, shows another way to use DefType. This time multiple variables are created by separating them with commas. All three variables ("distance", "speed" and "time") are floating point variables.
The next two lines
width.w counter.bdemonstrate another way to initialize a variable, this time by simply using it. In this case the variables are not used for much (well, not anything...). In these cases the variables "width" and "counter" are initialised as a word and a byte respectively. Something to note about this type of declaration (where the variable is not used for anything) is that you cannot use the dollar notation to create a string variable and you must always specify a type if you do not do anything with the variable (as in the above example).
The final line shows how to initialize a string variable (called "address") using the dollar notation and the DefType keyword. Remember that once you create a variable using the dollar notation, you must always follow the variable name with the dollar sign when you use the variable.
Another point worth mentioning is that if you create a variable by using it (and actually doing something with it, as will be shown in the next chapter) you do not need to set the type. PureBasic will by default assume the type is a long. You can change the default type by using the DefType keyword without a variable name. Any variable created after that point without a type will use the type specified with the DefType.
; Variables created here without specifying a type will be longs DefType.f ; Variables created here without specifying a type will be floats DefType.b ; Variables created here without specifying a type will be bytes DefType.s ; Variables created here without specifying a type will be strings
| Previous topic | Chapter contents | Next topic |
|---|---|---|
| Variable types | User Guide contents | Summary |