Changing Properties at Design Time
Changing Properties at Design Time
NET Guide
Coding in .Net
The appearance of objects on the form can be changed either at design time or at run-
time.
NB: Setting properties at design time is useful for establishing initial values quickly; but setting
properties within code gives the programmer more control over when properties are changed.
object.property = value
This changes the property of the specified object to the desired value.
eg:
txtGreeting.text = “Hello”
This sets the text box’s text property to “Hello” – ie: displays “Hello” in the text box.
To test the value of a property in a condition, the same structure should be used.
This changes the contents of the text box depending on the current contents.
Page 1 of 3
SEB’s VB.NET Guide
Functions:
Most languages include a library of functions available to reduce duplication of frequently used
code. These functions usually perform tasks such as searching, sorting or manipulation of strings
(extract, delete & insert).
Useful functions:
STR
VAL
RND
The function RND can be used to generate a random number. The number generated will
be between 0 and 1 so you need to multiply the number by the maximum number you
want to be generated. You need to use the command Randomize to get a different series
of random numbers each time the code is run.
Example:
ldblrand = Rnd*100
This will generate a random number between 0 and 100 (with decimal places).
INT
The function INT takes the integer part of a number. NOTE: It is not the same as
rounding! The fractional part of the number is truncated and lost.
Example:
ABS
Page 2 of 3
SEB’s VB.NET Guide
Example:
The statement above will calculate the distance between the left of image A and the left of
image B. If image A is nearer to the left than image B, the distance will be negative.
If imgA.left = 100 and imgB.left = 200, Intdist would be -100. If the images were
reversed, Intdist would be 100. Therefore, simply calculating the distance the sign needs
to be omitted. The Abs function does this: it takes the result, but ignores the sign.
Methods:
In Object Oriented languages objects have associated functionality, methods. Properties are what
objects have; methods are what they do. What would have previously involved the use of
functions may now be performed through using an object’s method.
eg:
strMyString.ToLower
The ToLower method associated with strings which appears to convert the string into lower case
characters. It actually converts a copy of the string to lower case characters.
Page 3 of 3