| HTML Tutorials |
|
|
| XML Tutorials |
|
|
| Browser Scripting |
|
|
| Server Scripting |
|
|
| .NET (dotnet) |
|
|
| Multimedia |
|
|
| Web Building |
|
|
| Java Tutorials |
|
|
| Programming Langauges |
|
|
| Soft Skills |
|
|
|
|
Assigning Values to Variables
|
|
We can assign values to those variables,after declaring various variables using the Dim statements. The general format of an assignment is
variable=Expression and the variable can be a declared variable or a control property value. The expression could be a mathematical expression, a number, a string, a Boolean value ( false or true) and etc.
The following are some examples:
|
firstNumber=100
secondNumber=firstNumber-99
userName="John Lyan"
userpass.Text = password
Label1.Visible = True
Command1.Visible = false
Label4.Caption = textbox1.Text
ThirdNumber = Val(usernum1.Text)
total = firstNumber + secondNumber+ThirdNumber
|
|
|
Operators in Visual Basic
|
|
We need to use various mathematical operators in order to compute inputs from users and to generate results.In Visual Basic, except for + and -, the symbols for the operators are different from normal
mathematical operators as shown in following table:
|
|
Operator |
Mathematical function |
Example |
|
^ |
Exponential |
2^4=16 |
|
* |
Multiplication |
4*3=12 |
|
/ |
Division |
12/4=3 |
|
Mod |
Modulus(return the
remainder from an integer division) |
15 Mod 4=3 |
|
\ |
Integer Division(discards
the decimal places) |
19\4=4 |
|
+ or & |
String concatenation |
"Visual"&"Basic"="Visual
Basic" |
|
|
The following example describe the use of operator in VB
|
Dim firstName As String
Dim secondName As String
Dim yourName As String
Private Sub Command1_Click()
firstName = Text1.Text
secondName = Text2.Text
yourName = secondName + " " + firstName
Label1.Caption = yourName
End Sub
|
|
|
In this example, three variables are declared as string and for variables secondName and firstName will receive their data from the user’s input into textbox1 and textbox2, and
the variable yourName will be assigned the data by combining the first two variables.
Finally, yourName is displayed on the Label1.
|
Dim number1, number2, number3 as Integer
Dim total, average as variant
Private sub Form_Click
number1=val(Text1.Text)
number2=val(Text2.Text)
number3= val(Text3.Text)
Total=number1+number2+number3
Average=Total/5
Label1.Caption=Total
Label2.Caption=Average
End Sub
|
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
Working With Variables,
asp net variables,
shell script variables,
php variables,
mysql variables,
working with php,
perl variables,
unix variables,
asp variables,
working with mysql,
bash variables,
javascript variables,
linux variables,
echo variables,
working with unix,
working with perl,
working with asp,
working with excel,
working with iis,
working with xml,
shell variables,
url variables
| HTML Quizes |
|
|
| XML Quizes |
|
|
| Browser Scripting Quizes |
|
|
| Server Scripting Quizes |
|
|
| .NET (dotnet) Quizes |
|
|
| Multimedia Quizes |
|
|
| Web Building Quizes |
|
|
| Java Quizes |
|
|
| Programming Langauges Quizes |
|
|
| Soft Skills Quizes |
|
|
|
|
| Copyright © 2003-2008 All Rights Reserved. |
|
| |