Pdf vb.net tutorial




















After you add the reference files to your VB. Net project , solution explorer look like the following picture. Center will place the your content to the center of the PDF page. After save the file , you can double click and open the pdf file.

Then you can see the following content in your pdf file. Home C VB. How to create PDF files in vb. You can freely download the Assemblies version from the following link: Download PDFsharp Assemblies The following steps will guide you how to create a pdf file programmatically 1. Download the Assemblies from the above mentioned url. Create a New VB. Net Project 4. Add pdfsharp Assemblies in VB. Net Project 5. When using If Else statements, there are few points to keep in mind.

Syntax The syntax of an if WriteLine "Value of a is 30" Else 'if none of the conditions is true Console. Else in the similar way as you have nested If statement. NET When the above code is compiled and executed, it produces the following result: Value of a is and b is Exact value of a is : Exact value of b is : Select Case Statement A Select Case statement allows a variable to be tested for equality against a list of values.

Each value is called a case, and the variable being switched on is checked for each select case. Net, i. Multiple expression clauses are separated by commas. WriteLine "Excellent! ReadLine End Sub End Module When the above code is compiled and executed, it produces the following result: Well done Your grade is B Nested Select Case Statement It is possible to have a select statement as part of the statement sequence of an outer select statement.

Even if the case constants of the inner and outer select contain common values, no conflicts will arise. Loops There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. Programming languages provide various control structures that allow for more complicated execution paths.

A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages: VB. Net provides following types of loops to handle looping requirements. It could be terminated at any time with the Exit Do statement.

NET For Next It repeats a group of statements a specified number of times and a loop index counts the number of loop iterations as the loop executes. For Each Next It repeats a group of statements for each element in a collection. This loop is used for accessing and manipulating all elements in an array or a VB. Net collection. End While It executes a series of statements as long as a given condition is True.

End With It is not exactly a looping construct. It executes a series of statements that repeatedly refer to a single object or structure. Nested loops You can use one or more loops inside any another While, For or Do loop. Do Loop It repeats the enclosed block of statements while a Boolean condition is True or until the condition becomes True.

NET value of a: 17 value of a: 18 value of a: 19 For Next Loop It repeats a group of statements a specified number of times and a loop index counts the number of loop iterations as the loop executes. ReadLine End Sub End Module When the above code is compiled and executed, it produces the following result: value of a: 10 value of a: 12 value of a: 14 value of a: 16 value of a: 18 value of a: 20 Each Next Loop It repeats a group of statements for each element in a collection.

WriteLine arrayItem Next Console. End While Loop It executes a series of statements as long as a given condition is True. The condition may be any expression, and true is logical true. The loop iterates while the condition is true. When the condition becomes false, program control passes to the line immediately following the loop.

NET Here, key point of the While loop is that the loop might not ever run. When the condition is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed. NET value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 With End With Statement It is not exactly a looping construct.

It executes a series of statements that repeatedly refers to a single object or structure. Net Programming". Name Console. Author Console. Subject End With Console. Net allows using one loop inside another loop. Following section shows few examples to illustrate the concept. Syntax The syntax for a nested For loop statement in VB. Net is as follows: While condition1 While condition While loop statement in VB.

Loop Loop A final note on loop nesting is that you can put any type of loop inside of any other type of loop. For example, a for loop can be inside a while loop or vice versa. NET 7 is prime 11 is prime 13 is prime 17 is prime 19 is prime 23 is prime 29 is prime 31 is prime 37 is prime 41 is prime 43 is prime 47 is prime 53 is prime 59 is prime 61 is prime 67 is prime 71 is prime 73 is prime 79 is prime 83 is prime 89 is prime 97 is prime Loop Control Statements Loop control statements change execution from its normal sequence.

When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Net provides the following control statements. NET Exit statement Terminates the loop or select case statement and transfers execution to the statement immediately following the loop or select case. Continue statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. GoTo statement Transfers control to the labeled statement.

Though it is not advised to use GoTo statement in your program. Exit Statement The Exit statement transfers the control from a procedure or block immediately to the statement following the procedure call or the block definition. It terminates the loop, procedure, try block or the select block from where it is called. If you are using nested loops i.

NET value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 Continue Statement The Continue statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. It works somewhat like the Exit statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between.

For the For Next loop, Continue statement causes the conditional test and increment portions of the loop to execute. For the While and Do While loops, continue statement causes the program control to pass to the conditional tests. ReadLine End Sub End Module When the above code is compiled and executed, it produces the following result: value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19 GoTo Statement The GoTo statement transfers control unconditionally to a specified line in a procedure.

Strings In VB. Net, you can use strings as array of characters, however, more common practice is to use the String keyword to declare a string variable.

The string keyword is an alias for the System. String class. Methods of the String Class The String class has numerous methods that help you in working with the string objects. NET S. However, it ignores case if the Boolean parameter is true. NET Copies a specified number of characters from a specified position of the string object to a specified position in an array of Unicode characters. The int parameter specifies the maximum number of substrings to return. The above list of methods is not exhaustive, please visit MSDN library for the complete list of methods and String class constructors.

ReadLine End Sub End Module When the above code is compiled and executed, it produces the following result: This is test and This is text are not equal. Contains "test" Then Console. WriteLine "The sequence 'test' was found. NET End Module When the above code is compiled and executed, it produces the following result: The sequence 'test' was found.

Substring 23 Console. WriteLine substr Console. Join vbCrLf, strarray Console. WriteLine str Console. Dates are so much part of everyday life that it becomes easy to work with them without thinking. Net also provides powerful tools for date arithmetic that makes manipulating dates easy. The Date data type contains date values, time values, or date and time values. The default value of Date is midnight on January 1, The equivalent. NET data type is System.

The DateAndTime module contains the procedures and properties used in date and time operations. The DateAndTime class belongs to the Microsoft. VisualBasic namespace and the DateTime structure belongs to the System namespace. Therefore, using the later would help you in porting your code to another. Net language like C. N Property Description 1 Date Gets the date component of this instance.

Gets the day of the month represented by this 2 Day instance. Gets the day of the week represented by this 3 DayOfWeek instance. Gets the hour component of the date represented by 5 Hour this instance. Gets a value that indicates whether the time 6 Kind represented by this instance is based on local time, Coordinated Universal Time UTC , or neither.

Gets the milliseconds component of the date 7 Millisecond represented by this instance. Gets the minute component of the date represented 8 Minute by this instance. Gets the month component of the date represented 9 Month by this instance. Gets a DateTime object that is set to the current 10 Now date and time on this computer, expressed as the local time. NET Gets the seconds component of the date represented 11 Second by this instance.

Gets the number of ticks that represent the date and 12 Ticks time of this instance. Gets the year component of the date represented by 16 Year this instance. The following table lists some of the commonly used methods of the DateTime structure: S. The above list of methods is not exhaustive, please visit Microsoft documentation for the complete list of methods and properties of the DateTime structure.

Today Console. WriteLine date1 Console. WriteLine date2 Console. WriteLine date4 Console. WriteLine date5 Console. Write "Current Time: " Console. WriteLine Now. ToLongTimeString Console. Otherwise, your code may change depending on the locale in which your application is running.

To convert a Date literal to the format of your locale or to a custom format, use the Format function of String class, specifying either a predefined or user-defined date format. The following example demonstrates this.

Module dateNtime Sub Main Console. ToString "d" Console. ToString "D" Console. ToString "t" Console. ToString "T" Console. ToString "f" Console. ToString "F" Console. ToString "g" Console. ToString "G" Console. ToString "M" Console. ToString "y" Console. For example, Sunday, December 16, Displays a date using your current culture's Short Date, or d short date format. For example, AM. Displays a time using your current culture's Short Time or t short time format. Displays the long date and short time according to your current culture's format.

Displays the long date and long time according to your current culture's format. Displays the short date and short time G according to your current culture's format. Displays the month and the day of a date. M, m For example, December Formats the date and time as a sortable S index. For example, T Formats the date and time as a GMT U sortable index. For example, Z. For example, Sunday, December 16, PM.

Formats the date as the year and month. Y, y For example, December, For other formats like user-defined formats, please consult Microsoft Documentation. N Property Description 1 Date Returns or sets a String value representing the current date according to your system.

The following table lists some of the commonly used methods of the DateAndTime class: S. The above list is not exhaustive. For complete list of properties and methods of the DateAndTime class, please consult Microsoft Documentation. MonthName month Console. WriteLine birthday Console. WriteLine bday Console. WriteLine month Console. WriteLine monthname Console. Arrays An array stores a fixed-size sequential collection of elements of the same type.

An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. All arrays consist of contiguous memory locations.

The lowest address corresponds to the first element and the highest address to the last element. Creating Arrays in VB. Net To declare an array in VB. Net, you use the Dim statement. For example, Dim intData 30 ' an array of 31 elements Dim strData 20 As String ' an array of 21 strings Dim twoDarray 10, 20 As Integer 'a two dimensional array of integers Dim ranges 10, 'a two dimensional array You can also initialize the array elements while declaring the array.

You can declare a dynamic array using the ReDim statement. Net allows multidimensional arrays. Multidimensional arrays are also called rectangular arrays. It is defined in the System namespace.

The Array class provides various properties and methods to work with arrays. Properties of the Array Class The following table provides some of the most commonly used properties of the Array class: S.

The length is specified as a bit integer. The index is specified as a bit integer. For a complete list of Array class properties and methods, please refer the Microsoft documentation.

WriteLine ' reverse the array Array. Reverse temp Console. WriteLine 'sort the array Array. Sort list Console. Collections Collection classes are specialized classes for data storage and retrieval. These classes provide support for stacks, queues, lists, and hash tables. Most collection classes implement the same interfaces. Collection classes serve various purposes, such as allocating memory dynamically to elements and accessing a list of items on the basis of an index, etc.

These classes create collections of objects of the Object class, which is the base class for all data types in VB. Collection namespace. Class Description and Usage It represents ordered collection of an object that can be indexed individually.

It is basically an alternative to an array. However, unlike ArrayList array, you can add and remove items from a list at a specified position using an index and the array resizes itself automatically. It also allows dynamic memory allocation, add, search and sort items in the list. It uses a key to access the elements in the collection. A hash table is used when you need to access elements by Hashtable using key, and you can identify a useful key value. The key is used to access the items in the collection.

It uses a key as well as an index to access the items in a SortedList list. NET A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index. If you access items using an index, it is an ArrayList, and if you access items using a key, it is a Hashtable. The collection of items is always sorted by the key value. It represents a last-in, first out collection of object. Stack It is used when you need a last-in, first-out access of items.

When you add an item in the list, it is called pushing the item, and when you remove it, it is called popping the item. It represents a first-in, first out collection of object. It is used when you need a first-in, first-out access of items. Queue When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque. It represents an array of the binary representation using the values 1 and 0.

BitArray It is used when you need to store the bits but do not know the number of bits in advance. You can access items from the BitArray collection by using an integer index, which starts from zero.

ArrayList It represents an ordered collection of an object that can be indexed individually. However, unlike array, you can add and remove items from a list at a specified position using an index and the array resizes itself automatically.

It also allows dynamic memory allocation, adding, searching and sorting items in the list. Count Gets the number of elements actually contained in the ArrayList. Item Gets or sets the element at the specified index.

The following table lists some of the commonly used methods of the ArrayList class: S. WriteLine "Adding some numbers:" al. Add 45 al. Add 78 al. Add 33 al. Add 56 al. Add 12 al. Add 23 al. Add 9 Console. Capacity Console. Count Console. Write "Sorted Content: " al. Sort For Each i In al Console.

NET End Sub End Module When the above code is compiled and executed, it produces the following result: Adding some numbers: Capacity: 8 Count: 7 Content: 45 78 33 56 12 23 9 Content: 9 12 23 33 45 56 78 Hashtable The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. It uses the key to access the elements in the collection. A hashtable is used when you need to access elements by using key, and you can identify a useful key value.

Properties and Methods of the Hashtable Class The following table lists some of the commonly used properties of the Hashtable class: Property Description Count Gets the number of key-and-value pairs contained in the Hashtable.

IsFixedSize Gets a value indicating whether the Hashtable has a fixed size. IsReadOnly Gets a value indicating whether the Hashtable is read-only. Item Gets or sets the value associated with the specified key. Keys Gets an ICollection containing the keys in the Hashtable. Values Gets an ICollection containing the values in the Hashtable.

Add "", "Zara Ali" ht. Add "", "Abida Rehman" ht. Add "", "Joe Holzner" ht. Add "", "Mausam Benazir Nur" ht. Add "", "M. Amlan" ht. Arif" ht. Add "", "Ritesh Saikia" If ht.

NET Else ht. Keys For Each k In key Console. Amlan SortedList The SortedList class represents a collection of key-and-value pairs that are sorted by the keys and are accessible by key and by index.

A sorted list is a combination of an array and a hashtable. Count Gets the number of elements contained in the SortedList. Item Gets and sets the value associated with a specific key in the SortedList. Keys Gets the keys in the SortedList. Values Gets the values in the SortedList. The following table lists some of the commonly used methods of the SortedList class: S. Add "", "Zara Ali" sl. Add "", "Abida Rehman" sl. Add "", "Joe Holzner" sl. Add "", "Mausam Benazir Nur" sl.

Amlan" sl. Arif" sl. Add "", "Ritesh Saikia" If sl. WriteLine "This student name is already in the list" Else sl. Amlan M. It is used when you need a last-in, first-out access of items. Properties and Methods of the Stack Class The following table lists some of the commonly used properties of the Stack class: Property Description Count Gets the number of elements contained in the Stack.

The following table lists some of the commonly used methods of the Stack class: S. Push "A" st. Push "M" st. Push "G" st. Push "W" Console. WriteLine st. Push "V" st. Push "H" Console. Peek Console. WriteLine "Removing values " st. Pop st. NET st. Pop Console. When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque Properties and Methods of the Queue Class The following table lists some of the commonly used properties of the Queue class: Property Description Count Gets the number of elements contained in the Queue.

The following table lists some of the commonly used methods of the Queue class: S. Enqueue "A" q. Enqueue "M" q. Enqueue "G" q. Enqueue "W" Console. NET q. Enqueue "V" q. Enqueue "H" Console. Dequeue Console. It is used when you need to store the bits but do not know the number of bits in advance. Item Gets or sets the value of the bit at a specific position in the BitArray. Length Gets or sets the number of elements in the BitArray.

The following table lists some of the commonly used methods of the BitArray class: S. NET 'content of ba2 Console. And ba2 'content of ba3 Console. Or ba2 'content of ba3 Console. Functions A procedure is a group of statements that together perform a task when called. After the procedure is executed, the control returns to the statement calling the procedure. Defining a Function The Function statement is used to declare the name, parameter and the body of a function. NET When the above code is compiled and executed, it produces the following result: Max value is : Recursive Function A function can call itself.

This is known as recursion. NET Param Arrays At times, while declaring a function or sub procedure, you are not sure of the number of arguments passed as a parameter. Net param arrays or parameter arrays come into help at these times. Sub Procedures As we mentioned in the previous chapter, Sub procedures are procedures that do not return any value.

We have been using the Sub procedure Main in all our examples. We have been writing console applications so far in these tutorials. When these applications start, the control goes to the Main Sub procedure, and it in turn, runs any other statements constituting the body of the program.

Defining Sub Procedures The Sub statement is used to declare the name, parameter and the body of a sub procedure. In this mechanism, when a method is called, a new storage location is created for each value parameter. The values of the actual parameters are copied into them. So, the changes made to the parameter inside the method have no effect on the argument.

Net, you declare the reference parameters using the ByVal keyword. NET ' calling a function to swap the values ' swap a, b Console. ReadLine End Sub End Module When the above code is compiled and executed, it produces the following result: Before swap, value of a Before swap, value of b After swap, value of a After swap, value of b It shows that there is no change in the values though they had been changed inside the function.

Passing Parameters by Reference A reference parameter is a reference to a memory location of a variable. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters. The reference parameters represent the same memory location as the actual parameters that are supplied to the method.

Net, you declare the reference parameters using the ByRef keyword. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.

Objects are instances of a class. The methods and variables that constitute a class are called members of the class. Class Definition A class definition starts with the keyword Class followed by the class name; and the class body, ended by the End Class statement. NET Volume of Box2 : Member Functions and Encapsulation A member function of a class is a function that has its definition or its prototype within the class definition like any other variable.

It operates on any object of the class of which it is a member and has access to all the members of a class for that object. Member variables are attributes of an object from design perspective and they are kept private to implement encapsulation. These variables can only be accessed using the public member functions. NET ' box 1 specification Box1. ReadKey End Sub End Module When the above code is compiled and executed, it produces the following result: Volume of Box1 : Volume of Box2 : Constructors and Destructors A class constructor is a special member Sub of a class that is executed whenever we create new objects of that class.

A constructor has the name New and it does not have any return type. ReadKey End Sub End Class When the above code is compiled and executed, it produces the following result: Object is being created Length of line : 6 A default constructor does not have any parameter, but if you need, a constructor can have parameters. Such constructors are called parameterized constructors. A destructor has the name Finalize and it can neither return a value nor can it take any parameters.

Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories, etc. Skip to content. Visual Basic. Net that will allow users to view pdf. Description This tutorial will allow the user to open and view a pdf file within the form of visual basic. Automating is the name of the command button for Automating. RadioButtonWord is the name of the radio button for MS word.

This is how we design the form. Design of the Dialog1 Paste the following code to import the statement. Code here Imports Microsoft. Paste the following codes for all the functions in each button at the first form. Object, ByVal e As System. EventArgs Handles btnNew. Click If Dialog1. ShowDialog Then If Dialog1. CreateNew "Word.



0コメント

  • 1000 / 1000