100% found this document useful (1 vote)
95 views

Changing Properties at Design Time

The document discusses setting properties at design time and run-time in VB.NET, provides examples of changing a text box property, and describes useful functions like STR, VAL, RND, INT and ABS for manipulating values. It also explains methods are actions objects can perform.

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
95 views

Changing Properties at Design Time

The document discusses setting properties at design time and run-time in VB.NET, provides examples of changing a text box property, and describes useful functions like STR, VAL, RND, INT and ABS for manipulating values. It also explains methods are actions objects can perform.

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

SEB’s VB.

NET Guide

Coding in .Net
The appearance of objects on the form can be changed either at design time or at run-
time.

Changing Properties at design time


1. Click on the object
2. Click on the property you want to change in the properties window
3. Type the new value or select the value from the drop-down menu

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.

Changing Properties at run-time


The structure of a basic statement is:

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.

If txtGreeting.text = “Hello” then


txtGreeting.text = “Hi”
Else
txtGreeting.text = “Bye”
End if

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

Returns a String representation of a number

VAL

Returns the numbers contained in a string as a numeric value of appropriate type

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:

lintrand = Int (Rnd * 100)

This will generate a whole number between 0 and 100.

ABS

Abs takes a number but ignores the sign (+ or -).

Page 2 of 3
SEB’s VB.NET Guide

Example:

Intdist = ImgA.left – ImgB.left

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.

Intdist = Abs (ImgA.left – ImgB.left)

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

You might also like