Вы находитесь на странице: 1из 43

Front-End And Back-End

Roll Number Name Address Phone

4 Himanshu WZ-45, Hari Nagar 9213222920

Save

Delete

Search

Form / Interface / Front-End

Student
Roll Number 1 2 3 Name Raj Amit Rahul Address c-65, hari nagar a-45, Ramesh ngr. c-96, Janak puri Phone 25126633 25165263 25545298

Table / Relation / Back-End

1. 2. 3. 4.

DataTypes in VB Storage size


1 byte 2 bytes 2 bytes 4 bytes 4 bytes

Datatype
Byte Boolean Integer Long

Range
0-255 True or False -32768 to +32767 -2147483648 to +2147483647

5. Single

6. 7. 8. 9.

Double Currency Decimal Date

8 bytes 8 bytes 14 bytes 8 bytes 4 bytes 10 bytes length of string 16 bytes 22 bytes + string length

10. Object 11. String (variable length) 12. String (fixed length) 13. Variant (numeric) 14. Variant (text)

Jan 1, 100 to Dec 31, 9999 Any object reference + string length 0 to approx. 2 billion 1 to approx. 65,400

Declaring & initializing Variables


Dim Num as integer Num = 2557 Num = -235 Num = 32 + 7 - 3 Dim Age as byte Age = 73 Age = 12 Dim Name as string Name = raj Dim Name as string * 15 Name = raj Dim Address as string Address = A-45, janak puri Dim price as single Price = 75.80 Price = 75.25 - 1.85 Dim x as Boolean x = true x = false x= 5<2 dim doj as date doj = #8-15-2005# dim x as date x = #12:45 PM# dim p as variant dim p p = raj p = 45 p = #8-15-2005# p = true p=45.7

Or Or Or

. .

variable length string fixed length string

Or Or Or

false

Or Or Or Or Or

(by default variant)

Dim a, b, c as integer Variant variables

Literals
String literals: raj, a-45, hari nagar, 845.73, 8-15-2005 Boolean literals: True, false Date / Time literals: #8-12-2005#, #1:45 AM # Single / Double literals: 12.5#, -13.80 , +0.73, 85.2! byte / integer / long literals: +45, -33, 0, 48, 128, 85%

Type declaration characters


% $ @ & # ! Dim x% Dim p$ Dim n# Integer string currency long double single declares x as integer variable declares p as string variable declares n as double variable

Comments
The word REM or symbol () tells the visual basic that everything on that line following REM or () is not the code, it is a comment and should be ignored by the compiler. REM can appear only in the beginning of the line but apostrophe () can appear after a statement also. Example: Dim x% declares x as integer variable REM example of a comment.

Variable Default Values


Datatype Integer Long Single Default Values 0 0 0

Double String Boolean Variant Date Currency

0 blanks/null false empty 0 0

Implicit & Explicit Variables Declaration


Dim x, y P=100 Dim m as integer Option explicit variant variables implicit variable (variant) explicit variable only explicit variables can be used

Defining Named Constants


Syntax: [public / private] const <constantname> [as type] = expression Examples: const pi = 3.14 public const a as integer = 9 const jdate = #2/1/05# public const nm = raj public const x = 14, nm = raj

Operators
1. 2. 3. 4. Arithmetic Operators String or Concatenation Operators Comparison Operators Logical Operators Arithmetic operators +, -, *, /, \ , mod, ^ 2+5 daljeet + singh 91 + 6 5/2 11/3 5\2 11\ 3 5 mod 2 11 mod 3 2 ^ 3 = 23 3 ^ 3 = 33 Concatenation operators(&) . . . . . . . . . . . 7 daljeetsingh 916 2.5 3.66 2 3 1 2 8 27

Daljeet & singh

. . . . . . .

Daljeetsingh false true true true false false

Comparison operators = 2=3 <> 9< >7 > 8>5 >= 5>=5 < 91<15 <= 9<=8 Logical Operators AND, OR, NOT, XOR (5 > 7 AND 9 <= 81) false true

. Truth Table A OR B A XOR B False False True True True True True False

false

A False False True True

B False True False True

A AND B False False False True

NOT A True True False False

NOT B True False True False

The Print Statement


Syntax: Print Message Text Print constant / variable / expression Example: Print this is visual basic Print 10 A = 30 Print A Print A * 2 / 3 Print using comma: Print 2, 3, 4, 5, 6 Output: 2 3 4 5 6 Print using semicolon: Print 1;2;3;4 Output: 1234 print hello;friends Output: hellofriends

Controls & their Properties

Control Name
Label

Property
Name Appearance Alignment Autosize Backcolor Backstyle Borderstyle Caption Enabled Font Forecolor Height Left Tooltiptext Top Visible Width

Value
0 flat 1 3D 0 left justify 1 right justify 2 center true / false 0 transparent 1 opaque 0 none 1 fixed single true / false

true / false

Control name
Textbox

Property
Name Alignment Backcolor Enabled Font Forecolor Height Left Maxlength Multiline Passwordchar Scrollbars

Value
0 left 1 right 2 center True / false

True / false 0 none 1 horizontal 2 vertical 3 both

Width

Borderstyle Appearance Text Tooltiptext Top Visible

0 none 1 fixed single 0 flat 1 3D

true / false

Control Name
Command button

Property
Name Appearance Backcolor Caption Disabledpicture Downpicture Enabled Font Height Left Picture Style Tooltiptext Top Visible Width

Value
0 flat 1 3D

true / false

0 standard 1 graphical true / false

Control Name
Frame

Property
Name Backcolor Borderstyle Caption Enabled Font Forecolor Height Left Tooltiptext Top Visible Width

Value
0 none 1 fixed single true / false

true / false

Control Name
Checkbox

Property
Name Allignment Backcolor Caption Disabledpicture Downpicture Enabled Font Forecolor Height Left Picture Style Tooltiptext Top Value Visible Width

Value
0 left 1 - right

true / false

0 standard 1 graphical 0 unchecked 1 checked true / false

Control Name
Optionbutton

Property
Name Allignment Backcolor Caption Disabledpicture Downpicture Enabled Font Forecolor Height Left Picture Style Tooltiptext Top Value Visible Width

Value
0 left 1 - right

true / false

0 standard 1 graphical true / false true / false

Control Name
Picturebox

Property
Name Align

Value
0 - None 1 Align top 2 Align bottom 3 Align left 4 Align right True / false 0 none 1 fixed single true / false

Autosize Backcolor Borderstyle Enabled Font Forecolor Height Left Picture Tooltiptext Top Visible Width

true / false

Control Name
Image

Property
Name Borderstyle Enabled Height Left Picture Stretch Tooltiptext Top Visible Width

Value
0 none 1 fixed single true / false

true / false true / false

Control Name
Combo box

Property
Name Backcolor Enabled Font Forecolor Height Left List

Value
True / false

Style Text Tooltiptext Top Visible Width

0 Drop down combo 1 simple combo 2 drop down list

true / false

Control Name
Listbox

Property
Name Backcolor Enabled Font Forecolor Height Left List Multiselect Style Tooltiptext Top Visible Width Text

Value
True / false

0 none 1 simple 2 extended 0 standard 1 checkbox True / False

Control Name
Hscrollbar / vscrollbar

Property
Name Enabled Height Left Max Min Top Value Visible Width

Value
True / false 32767 0 True / false

Control Name
DriveListbox

Property
Name Backcolor Enabled Font Forecolor Height

Value
True / false

Left Tooltiptext Top Visible Width Drive

True / false

Control Name
Directory list box

Property
Name Backcolor Enabled Font Forecolor Height Left Tooltiptext Top Visible Width Path

Value
True / false

True / false

Control Name
File list box

Property
Name Backcolor Enabled Font Forecolor Height Left Multiselect Pattern Tooltiptext Top Visible Width Path

Value
True / False

0 none 1 simple 2 extended

True / false

Control Name
Shape

Property
Name Backcolor Backstyle Bordercolor Fillcolor Height Left

Value
0 transparent 1 opaque

Shape

0 rectangle 1 square 2 oval 3 circle 4 rounded rectangle 5 rounded square True / false 0 solid 1 - transparent

Top Visible Width Fillstyle

Control Name
Timer

Property
Name Enabled Interval Left Top

Value
True /False

Control Name
Form

Property
Name Backcolor Caption Enabled Font Forecolor Height Left Mdichild Maxbutton Minbutton Picture Top Visible Width Windowstate

Value

True / false

True / false True / false True / false True / False 0 normal 1 minimized 2 - maximized

Events

1.

Event refers to the occurrence of an activity. Some useful events Click:- When the user clicks the primary mouse button on an object. Change:- When the user modifies text in combo box or text box. Gotfocus:- When an object receives focus. Lostfocus:-When an object loses focus. Keypress:- The user presses and releases a keyboard key while an object has focus. Keyup:- When the user releases a keyboard key when an object has focus. Dragdrop:- The use drags an object to another location. Dragover:- The user drags an object over another control. Form_load: - When the form loads for execution in memory. Setting the Properties

2. 3.
4. 5. 6. 7.

8. 9.

The controls that you draw on your form, have some properties associated with them. The properties can be set by two different ways. 1. At design time 2. At run time.
1. Properties can be set at design time using properties window.

2. Setting properties at run time. Setting the Alignment property Example: Label1.alignment = 0 Or Text1.alignment = 1 Setting Appearance property Example: Label1.appearance =1 Or Command1.appearance = 1 Or Option1.appearance = 0 Setting Autosize Property Example: Label1.autosize = true

Or Label1.autosize = false Or Picture1.autosize = true Setting the backcolor property Example: Label1.backcolor = RGB(100, 125, 190)

0-255 (red) Or Or text1.backcolor = VbRed Setting Backstyle Property Example: Label1.Backstyle = 0 Or Label1.backstyle = 1

0-255(green)

0-255( blue)

text1.backcolor = RGB(50, 50, 100)

Setting Borderstyle Property Example: Label1.Borderstyle = 0 Or Label1.Borderstyle = 1

Setting the Enabled Property Example Text1.enabled = true Or Label1.enabled = false Setting caption property Example: Label1.caption = this is my name Or Command1.caption = click me Setting forecolor property Example: Label1.forecolor = RGB( 100, 255, 70) Or Label1.forecolor = VbBlue Setting Height Property

Example: Label1.height = 100 Or Command1.height = 200 Setting the tooltiptext property Example: Text1.tooltiptext = This is a text box Setting the text property Example: Text1.text = Amit sharma Setting the visible property Example: Label1.visible = true Or Text1.visible = false Setting the width property Example: Text1.width = 250 Or Command1.width = 100 Setting the style property Example: Command1.style = 0 Or Option1.style = 1 Setting the picture property Example: Check1.picture = loadpicture ( c:\abc.gif) Or Command1.picture = loadpicture ( c:\abc.gif) Or Option1.picture = loadpicture ( c:\abc.gif) Or Picture1.picture = loadpicture ( c:\abc.gif) Setting the disabledpicture and downpicture property Example: Command1.disabledpicture = loadpicture(c:\abc.gif) Or

Command1.downpicture = loadpicture(c:\abc.gif) Setting the value property of checkbox Example: Check1.value = 0 Or Check1.value = 1 Setting the value property of option button Example: Option1.value = true Or Option1.value = false Setting the stretch property of image control Example Image1.stretch = true Or Image1.stretch = false Setting the max/min property of Hscrollbar / Vscrollbar Example Hscroll1.max = 100 Hscroll1.min = 1 Vscroll1.max = 100 Vscroll1.min = 1 Setting the fillstyle and fillcolor property Example: Shape1.fillstyle = 0 Shape1.fillcolor = RGB(100, 150, 200) Setting the Shape Property of Shape control Example: Shape1.shape = 1 Or Shape1.shape = 3 Setting the windowstate property of form Example: Form1.windowstate = 0 Or Form1.windowstate = 1

Some Examples: Example1:- Loading a picture in the picture box at run time. Picture Box

Load

Command Button (cmdload) Private sub cmdload_click() Picture1.picture = loadpicture (c:\abc.gif) End sub Example2: Loading a picture in the image control at run time. Image control(image1)

Load

Command Button( cmdload ) Private sub cmdload_click() Image1.picture = loadpicture (c:\abc.gif) End sub Example3: List Box

ListBox (list1)

Enter Your Name Add Delete Clear Listcount Listindex Display

Private sub cmdadd_click() List1.additem text1.text End sub Private sub cmddel_click() List1.removeitem list1.listindex End sub Private sub cmdclear_click() List1.clear End sub Private sub cmdcount_click() Msgbox List1.listcount End sub Private sub cmdindex_click() Msgbox list1.listindex End sub Private sub cmddisp_click() Msgbox list1.text End sub Adding an item in the list box List1.additem Ravi List1.additem text1.text Removing an item from the list box List1.removeitem 0 List1.removeitem list1.listindex Example 4: Hscrollbar / Vscrollbar application Hscroll1

Sum

Command Button (cmdsum)

vscroll1

Private sub hscroll1_change() Text1.text = hscroll1.value End sub Private sub Vscroll1_change() Text2.text = vscroll1.value End sub Private sub cmdsum_click( ) Dim a as integer, b as integer a = val (text1.text) b = val (text2.text) text3.text = a + b End sub

Example 5 : Shape Control Application Shape Control (shape1)

Rectangle

Square

Oval

Circle

Rounded Rectangle

Rounded square

Private sub cmdrect_click( ) Shape1.shape = 0 End sub Private sub cmdsquare_click( ) Shape1.shape = 1 End sub Private sub cmdoval_click( ) Shape1.shape = 2 End sub Private sub cmdcircle_click( ) Shape1.shape = 3 End sub Private sub cmdroundrect_click( ) Shape1.shape = 4 End sub Private sub cmdroundsquare_click( ) Shape1.shape = 5 End sub

Example 6 : Drive, Directory and file list box Drive1 directory1

file1

C: C:\ Program Files . . . Abc.dll Rmn.dll Pqr.exe

Enter the pattern

Private sub drive1_change( ) Dir1.path = drive1.drive End sub Private sub dir1_change( ) File1.path = dir1.path End sub Private sub text1_change( ) File1.pattern = text1.text End sub Example 7: Timer application. Label1

Reset Timer1 cmdreset

Set the following properties: Timer1.interval = 1000 Label1 - > font = MS sans serif, bold, 18

Dim I as integer Private sub cmdreset_click( ) I=0 End sub Private sub timer1_timer ( ) Label1.caption = i I=I+1 End sub Example 7: Option Button Application.

Percentage

90

80

70

60

Click

lblgrade

cmdgrade

Private sub cmdgrade_click( ) If optone.value = true then Lblgrade.caption = The grade is A Else if opttwo.value = true then Lblgrade.caption = The grade is B Else if optthree.value = true then Lblgrade.caption = The grade is C Else if optfour.value = true then Lblgrade.caption = The grade is D End if End sub Private sub form_load( ) Optone.value = false Opttwo.value = false

Optthree.value = false Optfour.value = false End sub Manipulating forms Setting the startup form To change the startup form 1. Goto project menu - > project peoperties 2. Select General Tab 3. In startup object listbox select the form 4. Click Ok Loading and unloading the forms Load form1 Unload form1 Unload me Showing and Hiding forms Form1.show Form2.show Form1.hide Me.hide Assigning the Access key Command buttons can be used by clicking on them or by pressing the alt + < access key >. To assign a keyboard access key to command button place ampersand( &) in front of the letter that is to be used as access key, while setting the caption property of the command button.

Control Structures in VB

Control Flow:

1. 2. 3.

Sequence Selection Iteration

The if statement: Syntax:


if (condition) then statements end if

Example:
If (a>10) then Print Raj End if

The if. Then else statement Syntax:


If (condition) then statements else statements End if

Example:
Enter the marks

Text1

Result cmdresult Private sub cmdresult_click( ) Dim m as integer m = val (text1.text) if (m >= 40) then print you are passed else print you are failed end if End sub

If then else if statement Syntax:


If (condition) then statements else if (condition) then statements else if (condition) then statements . . . else statements End if

Example:
Text1 Enter a number

Print day cmdprintday Private sub cmdprintday_click( ) Dim x as integer X = val(text1.text) If(x = 1) then Msgbox Sunday else if (x = 2) then Msgbox Monday else if (x = 3) then Msgbox Tuesday else if (x = 4) then Msgbox Wednesday else if( x = 5) then Msgbox Thursday else if (x = 6) then

Msgbox Friday else if (x = 7) then Msgbox Saturday Else Msgbox Invalid choice End if End sub

Nested ifs Example:


If ( x > 7) then If( y <= 8) then Print Ravi Else Print Amit End if Else If (P <> 71) then Print vishvas Else Print Raj End if End if

Compound if: Example:


If ( x > 7 AND y <> 75) then Print Vicky Else Print Raj End if

Example:
If( x >= 91 OR p <> 83) then Print Rishabh Else Print Amrita End if

The iif( ) function: Syntax:


iif(condition, value1, value2)

Example:
Dim num1 as integer, num2 as integer, big as integer

Num1 = 7 Num2 = 81 Big = iif (num1 >= num2, num1, num2)

Select case statement: If Select case


case1 case is > 7 case is < 7 case 7 to 20 if x = 1 if x > 7 if x < 7 if x >= 7 AND x <= 20

1. 2. 3. 4.

Example 1:
Text1 Enter a number

Print day cmdprintday Private sub cmdprintday_click( ) dim m as integer m = val( text1.text ) select case m case 1: Msgbox Sunday case 2 Msgbox Monday case 3 Msgbox Tuesday case 4: Msgbox Wednesday case 5: Msgbox Thursday case 6: MsgboxFriday case 7: MsgboxSaturday case else Msgbox Invalid choice End select End sub

Example 2:

Text1 Enter the marks

Result cmdresult Private sub cmdresult_click( ) Dim m as integer M = val( text1.text ) Select case m Case is < 50 Msgbox Fail Case is < 60: Msgbox Grade B Case is < 75: Msgbox Grade A Case else: Msgbox Grade A+ End select End sub

Example 3:
txtmonth Enter the month no.

No. of days cmdnod Private sub cmdnod_click( ) Dim n as integer n = val ( txtmonth.text ) select case n

case 1,3,5,7,8,10,12 Msgbox 31 days in the month case 2 Msgbox 28 days in the month Case 4,6,9,11 Msgbox 30 days in the month End select End sub

Looping Structures:
1. 2. ForNext Do loop (a) Do whileloop (b) Doloop while (c ) Do untilloop (d) Doloop until whilewend

3.

1.

Fornext Example:
For i = 1 to 10 step 1 Print Raj Next i

Example:
For i = 7 to 22 step 2 Print abc Next i

Example:
For x = 17 to 1 step -3 Print raj Next x

2.(a)

Do whileloop Example:
x=1 Do while (x < = 10) Print xyz x=x+1 loop

Example:
x = 10 Do while (x > = 1)

Print xyz x=x-1 loop

Example:
x=1 Do while (x < = 20) Print raj x=x+2 loop

2.(b) Doloop while Example:


x=1 do print ABC x=x+1 loop while (x <= 10)

Example:
x = 10 do print raj x=x-1 loop while (x >= 1)

2.(c) Do untilloop While


x < 10 x <= 10 x>1 x >= 1 x < >1 x=1

Until
x >= 10 x > 10 x <= 1 x<1 x=1 x <> 1 x=1 do until x > 10 print Raj x=x+1 loop

Example:

Example:
x = 10 do until x < 1 print Raj x=x-1

loop

2.(d) Doloop until Example:


x=1 do print Raj x=x+1 loop until > 10

Example:
x = 10 do print Raj x=x-1 loop until x < 1

3. While wend Example:


x=1 while x <= 10 print raj x=x+1 wend

Example:
x = 10 while x >= 1 print raj x=x-1 wend

Nested loops

Example: for I = 1 to 3 step 1 for j = 1 to 5 step 1 print "raj"

next j next i Example: i=1 do while i<=3 j=1 do while j<=5 print "raj" j=j+1 loop i=i+1 loop

Exiting from loops


Exit For Exit Do Example: (Exit For) for i=1 to 10 step 1 if (I = 7) then Exit for End if print i next i Example: (Exit do) x=1 do while x<=10 if(x=7) then Exit do End if print x x=x+1 loop

Arrays
Array is a collection of variables of same type that are referenced by a common name. Example: Private sub Command1_Click() dim a(4) as integer dim i as integer for i=0 to 4 step 1 a(i) = inputbox "enter a number " next i for i=0 to 4 step 1 print a(i) next i End Sub

dim x(1 to 5) as integer dim x(5 to 9) as integer

Redim statement

Example: Private sub Cmdprint_Click( ) dim a( ) as integer dim i as integer redim a(4) for i=0 to 4 step 1 a(i) = inputbox "Enter a number" next i for i=0 to 4 step 1 print a(i) next i redim a(9) print "array after re-dimensioning " for i=0 to 9 step 1 print a(i) next i End sub Redim preserve a(9)

Preserve statement

Procedures & Functions Types of Procedures


1. Sub Procedures 2. Function Procedures 3. Property Procedures 1. Sub Procedures: A sub procedure or subroutine or sub is a procedure that performs a specific task but does not return a value.

Example: Procedure without arguments

Print message

cmdprintmessage Private sub cmdprintmessage_click( ) print "Raj" print "Daljeet" disp or call disp print ravi print "kailash" call disp print "vishal" End sub Private sub disp( ) print "Harish" print "Manish" print "Vicky" End sub Example: Procedures with arguments Enter a number Enter second number Result is sum text 3 text 1 text 2

cmdsum Private sub cmdsum_click( ) dim x as integer, y as integer x = val (text1.text) y = val(text2.text) call findsum (x, y) or findsum x, y findsum x . Error findsum x, 5, y . Error End sub Private sub findsum (n as integer, m as integer) text3.text = n + m End sub 2. Function Procedures: A function is a procedure that performs a specific task and returns a value. Types of Functions 1. User Defined Functions 2. Built in Functions or Library Functions

Example: Enter a number Enter a second number Result is Sum Text1 Text2 Text3

cmdsum Private sub cmdsum_click( ) dim x as integer, y as integer, z as integer x = val(text1.text) y = val(text 2.text) z = findsum(x, y) text3.text = z End sub Private function findsum (n as integer, m as integer) as integer findsum = n + m End function

Passing Parameters to Procedures

1. Call by Value (pass by value) .Byval 2. Call by Reference (pass by reference) ..Byref Example:

cmdprint

Print Private sub cmdprint_click( ) dim x as integer x=5 print x call change(x) or change x print x End sub Private sub change (Byref n as integer) n=100 print n End sub

. . .

5 100 100

Using Optional Arguments


Enter first number Enter second number Result is cmdsum sum Text1 Text2 Text3

Private sub cmdsum_click( ) dim x as integer, y as integer x = val(text 1.text) y = val(text 2.text) findsum x, y findsum x findsum findsum 2, y, 5 . error End sub Private sub findsum (optional n as integer = 70, optional m as integer = 80) text3.text = n + m End sub

Exiting from Procedures


1. Exit Sub 2. Exit Function

Enter a no. check cmdcheck Private sub cmdcheck_click( ) dim x as integer x = val(text1.text) call samplepro(x) End sub Private sub samplepro (n as integer ) if (n > 50) then msgbox "you have got a car" else Exit sub

text1

End if End sub

Library Functions String Functions:

1. Lcase and Ucase Functions Print Ucase(hello) Print Lcase (HELLO) Text1.text = Ucase(text1.text) Text1.text = Lcase(text1.text) 2. Len Function dim x as integer x = len(raj) print x x = len(text1.text) print x print len(Rajeev)

HELLO hello

3 6

3. Trim, Ltrim, and Rtrim functions Text1.text = Ltrim( daljeet) Text1.text = Rtrim(sandeep ) Text1.text = trim( amit arora Text1.text = trim(text1.text) Text1.text = rtrim(text1.text) 4. Left and Right functions dim n as string, m as string m = daljeet n = right(m, 4) print n m = raj arora print left (m,3) 5. Mid function dim x as string, y as string x = raj kumar arora y = mid (x, 5, 5) print y print (x,11, 5) 6. Instr function

jeet raj

kumar arora

dim searchstring as string, searchchar as string, mypos searchstring = XXpXXpXXPXXP searchchar = P mypos = instr (4, searchstring, searchchar, 1) 6

mypos = instr(1, searchstring, searchchar, 0) mypos = instr(searchstring, searchchar) mypos = instr(searchstring, w) 7. Space Function dim p as string p = raj & space(10) & puri print p 8. String Function dim x as string x = string(10, a) print x x = string (5, ABC) print x 9. Str Function dim x as string, y as string x = str(1205) y = str(1305) print 12 + 15 print str(12) + str(15) print 12 + 15

9 9 (0) not found

raj

puri

aaaaaaaaaa AAAAA

1205 1305 27 1215 1215

10.Asc Function dim x as integer x = asc(A) print x 65 print asc(Abc) 65 x = asc(a) print x 97 ASCII Values American Standard Codes For Information Interchange. A to Z 65 to 90 a to z 97 to 122 0 to 9 48 to 57 11.Chr Function dim x as string x = chr(65) print x A print chr(66) B x = chr(98) print x b 12.Strreverse Function Dim x as string x = Neeraj

Print strreverse(x) Print strreverse (neeraj) Text1.text = strreverse(text1.text)

jareeN jareen

Numeric Functions

1. Int & Fix Functions print int(14.1) . print int(14.6) . print int(-14.1) . print int(-14.6) . print cint(14.1) print cint(14.6) print cint(-14.1) print cint(-14.6) print fix(14.1) print fix(14.6) print fix(-14.1) print fix(-14.6) 2. Sgn Function if number is greater than 0 equal to 0 less than 0 print sgn(-5) print sgn(0) print sgn(10) x = sgn (-5) print x . . . . . . . .

14 14 15 15 14 15 14 15 14 14 14 14

Sgn function returns 1 0 -1 . . . . -1 0 1 -1 . . . . 7 25 7 18

3. Val( ) Function print 2+5 print 2 + 5 print val(2) + val(5) print val(18th Road)

4. Rnd Function Text1.text = rnd(1) Or print rnd(3) To produce a random number within the given range. int ((upperbound lowerbound + 1) * rnd + lowerbound) Example: (To produce a random number between 1 and 6) dim x as integer

Or

x = int ((6 1 + 1) * rnd + 1) x = int (( 6 * rnd) + 1)

Date and Time Functions


1. Now( ) Function print now( ) Or print now . 1/17/06 11:25:50 AM

2. Date and Date$ Functions Print date . Print date$ . Date Variant Uses / Do not places 0 Do not appends 19 or 20 before year 3. Time and Time$ Functions Print time . Print time$ .

1/17/04 01-17-2004 Date$ String Uses - Places 0 Appends 19 or 20 before year 9:11:50 PM 21:11:50

Time Time$ Variant String 12 hour 24 hour 4. Datepart Function Syntax: Datepart (interval, validdate) Interval yyyy year q quarter m month y day of the year d day w weekday ww week h hour n minute s second Example: dim x as date x = #1/17/2006# Print datepart (m, x) Print datepart(yyyy, now) 5. Day, Month and Year Functions

1 2006

Print day(date) Print month (date) Print year(date) dim x as date x = #1/19/2006# print year(x) print day(x) 6. dim x as date x = #12:10:41 AM# Print hour(x) Print minute(x) Print second(x) Print minute(now) 7. Print timer Text1.text = timer( )

17 1 2006 2006 19 Hour, Minute and Second Functions

12 10 41 Timer( ) Function

Or

8. Dateadd and Datediff Functions Syntax: Dateadd (interval, number, olddate) Example: x = dateadd(y, 25, now) Or x = dateadd(yyyy, 3, now) Datediff Function Syntax: Datediff(interval, date1, date2) Example: x = #1/17/2006# y = #2/25/2004# n = datediff (yyyy, x, y)

print n Miscellaneous Functions

1. Isdate( ) Function dim x as integer, y as string x = 10 y = 12/17/2005 print isdate(x) print isdate(y) 2. Isnumeric( ) Function print isnumeric(x) print isnumeric(y)

. . . .

false true true false

3. Isempty( ) Function 4. Isnull( ) Function 5. Vartype( ) Function Example: dim x as integer, y as string Print vartype (x) Print vartype (y) 6. Inputbox( ) Function Syntax: Inputbox (prompt [,title] [,default] [,xpos] [,ypos]) Example: p = inputbox(Enter the number, My Project, 10, 100, 200) 7. Msgbox( ) Function Syntax: Msgbox (prompt [,buttons] [,title]) Example: Msgbox (A Trial Message) x = Msgbox (Do you wish to continue:, 4 + 32, My Project)

. .

2 8

Вам также может понравиться