Tuesday, April 19, 2011
Mustfa Gold Price Online
Topic: Overview of Language
Sub topic: Concepts of Programming
Material theoretical. Theoretical Material
. Convert Data
Conversion Functions
Activating the Option Strict option in the project properties, this requires us we have to use conversion functions for each type of data, the most commonly used are green, conversion functions are:
| Name | Data Type | argument Values \u200b\u200b | |
| function | returned | "expression" | |
| CBool \u200b\u200b(expression) | Boolean | Any string value or expression
| |
| numbers.
| |||
| CByte (expression) | Byte | 0 to 255, the fractions
| |
| rounded.
| |||
| CChar (expression) | Char | Any string expression, the
| |
| values \u200b\u200bmust be from 0 to 65535 .
| |||
| CDate (expression) | Date | Any valid representation of
| |
| a date or time.
| |||
| CDbl (expression) | Double
| Any value Double, see table
| |
| above for possible values.
| |||
| CDec (expression) | Decimal Any | Decimal value, see table
| |
| above for possible values.
| |||
| CInt (expression) | Integer | Any Integer value, see table
| |
| above for possible values
| the |||
| fractions are rounded.
| |||
| CLng (expression) | Long | Long Any value, see table
| |
| above for possible values, the
| |||
| fractions are rounded.
| |||
| CObj (expression) | Object
| Any valid expression.
| |
| CShort (expression) | Short
| Short Any value, see table
| |
| previous | possible values, the
| ||
| fractions are rounded.
| |||
| CSng (expression) | Single | Single Any value, see table
| |
| above for possible values.
| |||
| CStr (expression) | String | depends on the type of data
| |
| expression.
| |||
| Note: | |||
| All items vb.NET have some methods of
| |||
| for conversion to other types, at least
| |||
| number to string, and which have the property
| |||
| . ToString that returns a representation formats
| |||
| number string in question (Like CStr).
| |||
| CType (expression, | Same as | Any data
| |
| Type) | the second | ||
| parameter | |||
| Val (expression) | Double
| A string of characters.
| |
| Fix (expression) | depends on the type of data | Any data type of the expression
|
OPERATORS
ARITHMETIC
Empowerment: ^
| OPERATOR | FUNCTION | USE | USE SHORT |
| ^ | Raises the number from left to right exponent
| 2 ^ 8 | 2 ^ = 8 |
| * Multiplication |
| 3 * 6
| *=
|
| + | Sum
| 5 +7 = +
|
|
| - | Rest
| 7-4
| -=
|
| / | Real
| Division 21 / 5
| / =
|
| \\ | Whole Division
| 18 \\ 7
| \\ =
|
| &, +
| Concatenation of character
| "hello" & "again
| & =
|
| Mod
| Other division | 3 Mod 2
|
string comparison
We can use comparison operators also described above to compare strings. The Option Compare statement
, together with its modifiers Binary / Text, allows us to define the way in which comparisons are made between expressions containing strings.
- Option Compare Binary. Comparisons were made based on internal binary values \u200b\u200bof the characters. This is the default.
- Option Compare Text. Comparisons were made based on values text characters.
set at the project level, we open the project properties, and in paragraph
Building, set the corresponding value in the dropdown list
If
set file-level instruction must be written or Binary Option Compare Text at the beginning of the fileOption Compare Binary
Module Module1 Sub Main () Dim
Result As Boolean Result = "A" = "A" 'Returns: False
Result = "M" \u0026lt;"Z"' Returns: True
Result = "M"> "m" 'returns: False
Result = " , F "\u0026lt;>" f "'Returns: True
End Sub End Module
Option Compare Text
Module Module1 Sub Main () Dim
Result As Boolean Result =" A "=" a "' returns: True
Result = "M" \u0026lt;"Z" 'Returns: True
Result = "M"> "m"' returns: False
Result = "F" \u0026lt;> , "f" 'returns: False
End Sub End Module
Asc function ()
When performing string comparisons based on the binary values \u200b\u200bof the characters, is useful in Sometimes knowing the code for those characters. To find out what the code for a particular character, the language provides Asc function ().
This function takes a string as a parameter and returns a numeric value of type Integer, with the code for the first character in the string.
Chr function ()
If we are in the opposite situation to that described in the previous section, ie is the code of a character and we want to know which one applies, the function Chr ( ) receives a number as parameter and returns the character it belongs to a Char data type, but we can also assign the result to a String variable.
string comparison based on a pattern. Like operator
The Like operator allows a comparison between two strings, based on a pattern established in one of them.
Result = string Like pattern
- Results . Logical value with the result of the comparison. True indicates that a string with pattern matching. False indicates that there has been no pattern matching Chain. Chain
- . String that is compared with the pattern matching. Pattern
- . Character string which specifies special characters that serve as pattern matching on the value chain. Table 7 shows the characters and conventions of language use provided by the use of benchmarks.
| character pattern
| Match the search string |
| ?
| Any single character |
| *
| Several characters or any
|
| #
| Any single number
|
| [ListaCaracteres]
| Any single character that is within the list .
|
| [! ListaCaracteres]
| Any single character that is not within the list
|
'operator examples
Like Dim Result As Boolean
' ---------------------
-----------
'pattern?'returns True - The pattern matches the string
' to make the substitution of a character
Result = "HELLO" Like "HO? A"
'returns True - The pattern matches the string
'by making the replacement of two characters
Result = "MONITOR" Like "MO? ITO?
'returns False - The pattern does not match the string
' to make the substitution of a character
Result = "RODENT" Like "R? OED"
'--------- -----------------------
'pattern *
' returns True - The pattern matches the string
'to make the replacement of several characters with
'white space on both sides
Result = "The great plain" Like "The * plain"
' returns True - The pattern matches the string
'To make the replacement of two groups of characters
Result = "The great plain" Like "The llanu * *"
' returns False - The pattern does not match the string
'to make the substitution a group of characters,
'since the pattern itself requires a
word' is located in the
string Result = "The great plain" Like "The llanu *"
---
-----------------------------
'pattern #' returns True - The pattern matches the string
'To make the replacement of two numbers
Result = "It won 128 million" Like "has won # # 8 million"
' returns False - The pattern does not match the string,
'because in the more digits are specified pattern of
'in the supply chain
Result = "It won 128 million" Like "has won # # # 8 million"
' returns False - The pattern does not match the string,
'as used in the pattern
replacement character' of digits incorrectly
Result = "It won 128 million" Like "has won 128 # # million"
'-------------------------- ------
'pattern [List]
' returns True - The character of the chain is
'within the range in the list of results
pattern = "H" Like "[AM ] "
'returns False - The character of the chain is not
' within the range in the list of results
pattern =" h "Like" [AM] "
'Returns True - The character of the chain is
' within the range in the list of results
pattern = "h" Like "[am]"
'returns True - The nature of the chain
is' within the range in the list of results
pattern = "D" Like "[! PW]"
'returns False - The nature of the chain is
' within the range
pattern list
Result = "R" Like "[! PW]"'--------------------------------
' combination of standard characters
'returns True - All substitutions pattern are correct
Result = "missing 48 hours to reach the destination" Like
_ "Fal * # # * to ll [g] gar? des * "
'returns False - The numeric character substitutions are incorrect
Result =" missing 48 hours to reach the destination "Like
_" Fal # # * to ll [g] gar? des * "
'--------------------------------
' pattern matching using characters
'within the expression
' returns True - The close character
question 'is replaced correctly enclosed in brackets
Result = "Ana has come?, welcome" Like " Has * Ana [?] welcome "
'--------------------------------
' comparison two empty strings
'returns True
Result = "" Like ""
OPERATORS AND LEVEL BIT SOFTWARE
And
Operator And we only use when we want to meet a series of expressions, egIf a> b And a> c
Then Console.WriteLine ("a is greater than b and c") End If
| When the expression returns A | And Expression B returns | The result is |
|
| True True True
|
|
|
| True False False
|
|
|
| False
| True False
|
|
| False False False
|
|
| When bit A is Expression | And the bit of Expression B is | The resulting bit value is |
| 0
| 0
| 0
|
| 0
| 1
| 0
|
| 1
| 0
| 0
|
| 1
| 1
| 1
|
AndAlso
AndAlso operator also checks a series of expressions, but in comparison And, this check provided that the above expression turns out to be true, for example: Ifa> b AndAlso a> c
Then Console.WriteLine ("a is greater than b and c") End If
| When the expression returns | And ExpresiónB returns | The result is |
|
| True True True
|
|
|
| True False False
|
|
|
| not evaluated False |
|
Or
Or operator only use when we want to serve a term of a series of expressions, for example: IfAverage \u0026lt;0 Or Average> 20
Then Console.WriteLine ("Enter the Right Note (1. 20)") End If
| When the expression returns | And ExpresiónB returns | The result is |
|
| True True True
|
|
|
| True False True
|
|
| False True
|
| True
|
| False
| False
| False
|
| Cuando el bit de ExpresiónA es | Y el bit de ExpresiónB es | El valor del bit resultante es |
| 0
| 0
| 0
|
| 0
| 1
| 1
|
| 1
| 0
| 1
|
| 1
| 1
| 1
|
Xor
Xor operator will use it for special cases and that performs a logical exclusion on two Boolean expressions or a bitwise exclusion two numeric expressions, eg
Result = expression1 Xor expression2
are Type
IfBoolean
| If expression1 | And Expression2
| Result |
| is ... | is ... | be. |
|
| True True False
|
|
| True
|
| False True
|
|
| False True True
|
|
|
| False False False
|
|
If they are Bit rate
(Numerical)
| If the bit in | And the bit in | Result |
| expression1 is. | Expression2 is. | be. |
| 0
| 0
| 0
|
| 0
| 1
| 1
|
| 1
| 0
| 1
|
| 1
|
| 1 0
|
Example: Encode
following in console application and display results on screen.
1.
Dim A As Integer = 10
Dim B As Integer = 8
Dim C As Integer = 6 Dim
Result As Boolean Result = A> B Xor B> C
Result = B> A Xor B> C
Result = B> A Xor C> B
2.
Dim A As Integer = 10
Dim B As Integer = 8
Dim C As Integer = 6 Dim Result As
Integer Result = (A Xor B)
Result = (A Xor C)
result = (B Xor C) OrElse
OrElse operator also checks a series of expressions, only enough that an expression is true for other assessments do not. For example: If
Average \u0026lt;0 OrElse Average> 20
Then Console.WriteLine ("Enter Right Note (1. 20) ") End If
In this example if the first expression is true, and not perform the following expression, however if it turns out false, perform the following expression.
| When the expression returns | And ExpresiónB returns | The result is |
| True
| not evaluated | True
|
|
| False True True
|
|
|
| False False False
|
|
This operator is used to make denials, in most cases of type Boolean for example: Dim Variable
As Boolean = True Dim
Result As Boolean Result = Not
Variable 'Returns False.
First declare a Boolean variable and assign a value, but then refused instruction stored value and change it to False (Not Variable), so the result variable has the value False.
| When the expression returns | The result is |
|
| True False
|
|
| False True
|
| When bit of expression returns | The result is |
| 0
| 1
|
Is
This operator allows us to make comparisons either Boolean or String, this will return a Boolean value of the expression given, eg :
Dim Variable As String =. Joel.
As Boolean Dim Result Result =
IsNumeric (Variable) 'Returns False.
This example is similar to the previous one we asked if the value is Variable Number (IsNumeric (Variable)), but as string type (String) will return a value of False,
To
This operator will use it more in the repetitive processes or multiple conditions, is used to determine a range of numbers, eg
For K = 1 To 10
A = A + 1 Next
This loop will run or rather, perform 10 times the statement A = A +1 Since you indicated that the variable K will be worth 1 to 10. PRIORITY
operating businesses
| Priority arithmetic |
| Empowerment (^)
|
| Negation (-)
|
| real multiplication and division (*, /)
|
| entire Division (\\)
|
| division (Mod)
|
| Addition and Subtraction (+, -)
|
| logical operators Priority |
| Negation (Not)
|
| Conjunction (And, AndAlso)
|
| Disjunction (Or, OrElse, Xor )
|
| Priority between operators groups |
| Arithmetic
|
| Concatenation
|
| Comparison
|
| Logic
|
DATE TYPE FUNCTIONS
function Now ()
This function returns the current date and time of the system in a long format.
function Date ()
This function returns the current system date.
function Year (Date)
This function returns the year from a specified date.
function Month (Date)
Gets the number of months from a specified date.
function Day (Date)
Gets the number of day sent or a date specified.
Weekday function
(Date)
Gets the number of days a week, taking Sunday as a value number 1.
DateAdd Function (TipoIntervalo, ValorIntervalo, Date)
Add or subtract to a date, a certain range, to determine whether addition or subtraction performed, the TipoIntervalo can be days, weeks, hours, months, years, etc. ValorIntervalo must be positive or negative respectively.
DateDiff Function (TipoIntervalo, FechaPrimera, FechaSegunda)
Calculate the difference between two dates.
DatePart Function (TipoIntervalo, date)
Extract part of a date. CONDITIONAL INSTRUCTION
As we saw in the first installment, these instructions allow us to make decisions, giving us a true or false result, this statement is often the most used by all developers, so you'll that aprendértela memory, and do not worry it's very easy to use.
Syntax:
First Form:
If \u0026lt;expression to evaluate> Then the expression returns \u0026lt;Instrucción (si Verdadero)>Example:
If a = b Then MessageBox (. are numerically equal.)
If the expression evaluated in a = b returns or better is true, this will show a message with the text. are numerically equal.
Second Form: If
\u0026lt;boolean to evaluar> Then\u0026lt;Instrucción (si returns the evaluated expression Verdadero)>
End If Example:
If b \u0026lt;> 0 Then Res
= A / b
Console.WriteLine ("The Result of the division is: {0}", res) End If
The second way we use when we have to do more than one statement if the expression to evaluate is true, in this case if a is greater than b, if true this will make the following statement to divide the result by saving it in a variable called res, that after the show on the screen.
Third Form: If
\u0026lt;boolean to evaluar> Then\u0026lt;instruction (if the evaluated expression returns True)> Else
\u0026lt;instruction (if the evaluated expression returns False)> End If
Example:
If b \u0026lt;> 0 Then
Res = a / b
Console.WriteLine (" and the result of the division is: {0} ", Res)
Else Console.WriteLine (" Error: division by zero ") End If
This form allows us to use both types of results of the evaluated expression, for example, if b is different from zero is divided aa, but if false, show us a message Error.
Fourth Form: If
\u0026lt;boolean to evaluar> Then \u0026lt;Instrucción (si returns the evaluated expressionVerdadero)> \u0026lt;Instrucción (si Else returns the evaluated expression Falso)>
(all on one line)
Example: If
a = b Then MessageBox (. are numerically equal.) Else MessageBox (.
Not equal numbers.)
(all on one line)
This is not is used only in cases when we have to make a single instruction in each type of response from the expression evaluated, for example, if a equals b will show a message of equal numbers, but if false will show us another message saying that numbers are not equal, and remember it is on one line.
Fifth Form:
\u0026lt;boolean to evaluar> Then If
\u0026lt;instruction (if the evaluated expression returns True)> ElseIf
\u0026lt;boolean to evaluar> Then
\u0026lt; statement (if the evaluated expression returns True)> Else
\u0026lt;Instruction (If the evaluated expression returns False)> End If
Example:
If b = 0 Then
Console.WriteLine ("Error: division by zero")
ElseIf a \u0026lt;> b Then
Res = a / b
Console.WriteLine ("The Result of the division is: {0}", Res)
Else Console.WriteLine ("The Division's results: 1" ) End If
MULTIPLE CONDITIONS
Such conditions as we used to have several types of comparisons (to evaluate expressions).
Syntax: Select Case
\u0026lt;boolean to evaluar>expresiones>
Case list>Case Instructions
expresiones> \u0026lt;other
list
Instructions
Case Else
'if not met any of the lists of expressionsEnd Select
Example:
Select Case i Case 3:' Instruction to make
Case 6 To 11
'Instruction to make
Case 14, 17
'instruction to make
Case Is> 25
' instruction to make
Case Else 'instruction to make
End Select
In the example, we make several checks if i is 3 will make the statement that follows after the colon (can run only one statement after the colon, if in case there are more instructions to execute these instructions would put them at the bottom of the Case), however has a value of 6 to 11 will execute the instruction found in the lower, or if you have value of 14 or 17, run the statement is in its lower, or if i is greater than 25, made the statement that is at its bottom, and finally does not meet any comparison, there is a Case Else that execute their instruction, if not met any expression in other Case.
0 comments:
Post a Comment