Affichage des articles dont le libellé est visual basic. Afficher tous les articles

Learn array in vb.net / PDF

Learn array in vb.net / PDF





Learn array in vb.net / PDF













1       OVERVIEW OF ARRAYS

The ability to work with arrays is important in any programming language. VB.NET offers a simple way of grouping data into the array structures similar to other languages.

1.1            Definition

Arrays are programming constructs that store data and allow us to access them by numeric index or subscript. All arrays in VB as zero based, meaning, the index of the first element is zero and they are numbered sequentially. Arrays have an upper bound and a lower bound, which simply refer to the starting index and the ending index of a given array structure.

1.2            Purpose of the Arrays

§  Arrays are generally used for storing similar types of values or objects. They allow grouping variables together and allow referring to them by using an index.
§  Arrays help us create shorter and simpler code in many situations.
§  Additionally, the data in the array can be sorted.
§  You can loop through an array to determine and to modify the values stored in the array.

1.3            Array Elements

What is an array element? When you define any type of array, you are actually defining a set of variables of the same data type that can be referenced by a single name. Each one of those item is called an element of the array. For instance in the following example: 1 is an element of the array arrNumbers().

Dim arrNumbers() As Integer
arrNumbers = New Integer() {0,1,2,3,4}

1.4            Array Indexes

To distinguish one element of an array from the others, each element of an array is associated with an index number. That index number is used to reference each distinct element of the array. Note that the index must be positive.

1.5            Changing the Base Index of an Array

At times, starting an array with an index value of 0 (zero) seems counter-intuitive. For example, do users really think of January as zeroth month of the year, or do they think of it is the first month of the year? Generally speaking, January is considered as the first month of the year. Therefore, it would be nice to define the array in a way that is consistent with the way you expect to use the array. It would make more sense to have January have an index value of 1 than an index value of 0. There are several ways to accomplish this. Let’s use an example.

Dim sport(6) As String
sport(0) = "Saturday"
sport(1) = "Sunday"
sport(2) = "Monday"
sport(3) = "Tuesday"
sport(4) = "Wednesday"
sport(5) = "Thursday"
sport(6) = "Friday"


One way to handle the above problem is to start by assigning nothing to the array at location 0, that is:

Dim sport(7) As String
sport(0) = ""
sport(1) = "Saturday"
sport(2) = "Sunday"
sport(3) = "Monday"

1.6            Array Dimension

An array can be one-dimension (linear arrays) or more than one (multidimensional arrays). The dimensionality of an array refers to the number of subscripts used to identify an individual element. 

1.7          Declaring Arrays

There are two ways of initializing the arrays: to declare and initialize them in one statement, or to declare an array and choose to initialize it later.

When declaring and initializing arrays in the same statement, you must specify the type of the array elements and the number of the elements the array will hold. You must specify the number of array elements by indicating the upper bound of the array; the upper bound is the number that specifies the index of the last element in the array. For instance, to declare & initialize an array of 5 integers, with indexes ranging from 0 to 4, we can write:

Dim arrNumbers(4) As Integer
Another way to declare and initialize arrays is to perform these operations in two separate steps. If you declare an array without specifying a number of elements on one line, you have to provide the values for each item of the array when you initialize it. The initial values are provided enclosed in the {} braces, using a comma as a separator.
To declare and initialize an array in two separate steps, we can write:
Dim arrNumbers() As Integer 
arrNumbers = New Integer() {0,1,2,3,4}

2       DEMONSTRATING ARRAYS USING EXAMPLE

Example 1:

               Create a form with one button so that if you click the button, the value stored in array ..






Download Learn array in vb.net / PDF
















Learn array in vb.net / PDF

0

Download course VB : programming in ASP.NET

Download course VB : programming in ASP.NET 










Download course VB : programming in ASP.NET
















As it was mentioned before, ASP.NET supports several languages such as VB.NET, C-Sharp and J-Script. In this section, we will discuss how VB.NET program structures are implemented in ASP.NET pages. Mainly, we will some examples.

Using Variables

Variables are used in all programming language to hold data during the run-time of a program. All variables are declared within the

Creating Variables Example
            The contents of CapitalCityOfUk is:       
The contents of NumberOfStates is:      
The contents of IndependenceDay is: 
   























Using Various Data Types

VB.NET and hence the ASP.NET supports a variety of data types such as integer (short and long), decimal (single and double), char, string, date, Boolean, etc. Most of these data types can be used in arithmetic operations, comparison operations, and string concatenations.  The following is an example that declares few integer and decimal variables and performs a simple tax calculation.  Again, the page load event is used to perform the calculation, and there is no user interaction.



    
 Declaring Variables
    
    
  Your total earnings after tax are $ 
    
   























Concatenating Strings

String concatenation is common in an ASP.NET page. The following codes show how strings can be combined or concatenated using & and + signs in two different ways. 

Example 1: Using values and & sign

strCombine = “Jack” & “ “ & “Jill”

The result when strCombine is displayed: Jack Jill

Example 2: Using Variables and & sign

Dim firstString As String
Dim secondString As String
Dim twoString As String

firstString = “I am a “
secondString = “graduate student“
twoString = firstString & secondString

The result when strCombine is displayed: I am a graduate student

 Arrays

ASP.NET also supports array data type. Thus multiple values of a particular data type can be stored in an array. Note that in VB.NEt array index starts with 0. Thus a 10-member array should be declared as 0-9. The following is an example of an one-dimensional array in which text values are read from three input boxes and are stored in an array. The function “CStr” is used to delete any empty spaces in the input texts and the texts are displayed.

 
    Text Box Example
 
 
       
       
       

   
Please enter your name:     
Please enter your address:   
textmode="multiline" />  

Please enter your chosen password:  
textmode="password" /> 

                                              
   
 
   




































Control Structures

Various control structures are used in any programming language such as
·        If.. Then .. Else
·        Select Case
·        For ... Next
·        Do While ...
·        For .... Each.......






















Download course VB : programming in ASP.NET 



0

Learn visual basic step by step

Learn visual basic step by step






Learn visual basic step by step












Introduction

Visual Basic 2008 is Microsoft’s latest incarnation of the enormously popular Visual Basic language, and it’s fundamentally different from the versions that came before it. Visual Basic 2008 is now more powerful and more capable than ever before, and its features and functionality are on par with “higher-level” languages such as C++. One consequence of this newfound power is added complexity. Gone are the days when you could sit down with Visual Basic and the online Help and teach yourself what you needed to know to create a functional program.


This book is targeted toward those who have little or no programming experience or who might be picking up Visual Basic as a second language. The book has been structured and written with a purpose: to get you productive as quickly as possible. I’ve used my experiences in writing large commercial applications with Visual Basic and teaching Visual Basic to create a book that I hope cuts through the fluff and teaches you what you need to know.

All too often, authors fall into the trap of focusing on the technology rather than on the practical application of the technology. I’ve worked hard to keep this book focused on teaching you practical skills that you can apply immediately toward a development project.



This book is divided into five parts, each of which focuses on a different aspect of developing applications with Visual Basic 2008. These parts generally follow the flow of tasks you’ll perform as you begin creating your own programs using Visual Basic 2008. I recommend that you read them in the order in which they appear.


  • . Part I, “The Visual Basic 2008 Environment,” teaches you about the Visual Basic environment, including how to navigate and access Visual Basic’s numerous tools. In addition, you’ll learn about some key development concepts such as objects, collections, and events.


  • . Part II, “Building a User Interface,” shows you how to build attractive and functional user interfaces. In this part, you’ll learn about forms and controls—the user interface elements such as text boxes and list boxes.

  • . Part III, “Making Things Happen: Programming,” teaches you the nuts and bolts of Visual Basic 2008 programming—and there’s a lot to learn. You’ll discover how to create modules and procedures, as well as how to store data, perform loops, and make decisions in code. After you’ve learned the core programming skills, you’ll move into object-oriented programming and debugging applications.

  • . Part IV, “Working with Data,” introduces you to working with graphics, text files, and programming databases and shows you how to automate external applications such as Word and Excel. In addition, this part teaches you how to manipulate a user’s file system and the Windows Registry.

  • . Part V, “Deploying Solutions and Beyond,” shows you how to distribute an application that you’ve created to an end user’s computer. In Hour 24, “The 10,000-Foot View,” you’ll learn about Microsoft’s .NET initiative from a higher, less-technical level.

Many readers of previous editions have taken the time to give me input on how to make
this book better. Overwhelmingly, I was asked to have examples that build on the examples
in the previous chapters. In this book, I have done that as much as possible. Now, instead
of learning concepts in isolated bits, you’ll be building a feature-rich Picture Viewer program
throughout the course of this book. You’ll begin by building the basic application. As
you progress through the chapters, you’ll add menus and toolbars to the program, build an
Options dialog box, modify the program to use the Windows Registry and a text file, and
even build a setup program to distribute the application to other users. I hope you find this
approach beneficial in that it allows you to learn the material in the context of building a
real program.









Download Learn visual basic step by step







Learn visual basic step by step



1

Teach yourself visual basic / PDF

Teach yourself visual basic / PDF







Teach yourself visual basic / PDF
















What is Visual Basic?
·  Visual Basic is a tool that allows you to develop Windows (Graphic User Interface - GUI) applications. The applications have a familiar appearance to the user.

·  Visual Basic is event-driven, meaning code remains idle until called upon to respond to some event (button pressing, menu selection, ...). Visual Basic is governed by an event processor. Nothing happens until an event is detected.Once an event is detected, the code corresponding to that event (event procedure) is executed. Program control is then returned to the event processor.


·  Some Features of Visual Basic
Ăž  Full set of objects - you 'draw' the application
Ăž  Lots of icons and pictures for your use
Ăž  Response to mouse and keyboard actions
Ăž  Clipboard and printer access
Ăž  Full array of mathematical, string handling, and graphics functions
Ăž  Can handle fixed and dynamic variable and control arrays
Ăž  Sequential and random access file support
Ăž  Useful debugger and error-handling facilities
Ăž  Powerful database access tools
Ăž  ActiveX support
Ăž  Package & Deployment Wizard makes distributing your applications simple


Visual Basic 6.0 versus Other Versions of Visual Basic
·  The original Visual Basic for DOS and Visual Basic For Windows were
introduced in 1991.
·  Visual Basic 3.0 (a vast improvement over previous versions) was released in
1993.

·  Visual Basic 4.0 released in late 1995 (added 32 bit application support).
·
·  Visual Basic 5.0 released in late 1996. New environment, supported creation of
ActiveX controls, deleted 16 bit application support.

·  And, now Visual Basic 6.0 - some identified new features of Visual Basic 6.0:
Ăž  Faster compiler
Ăž  New ActiveX data control object
Ăž  Allows database integration with wide variety of applications
Ăž  New data report designer
Ăž  New Package & Deployment Wizard
Ăž  Additional internet capabilites
16 Bits versus 32 Bits
·  Applications built using the Visual Basic 3.0 and the 16 bit version of
Visual Basic 4.0 will run under Windows 3.1, Windows for Workgroups,
Windows NT, or Windows 95

·  Applications built using the 32 bit version of Visual Basic 4.0, Visual Basic
5.0 and Visual Basic 6.0 will only run with Windows 95 or Windows NT
(Version 3.5.1 or higher).
·  In this class, we will use Visual Basic 6.0 under Windows 95, recognizing
such applications will not operate in 16 bit environments

Structure of a Visual Basic Application


Application (Project) is made up of:
Ăž  Forms - Windows that you create for user interface
Ăž  Controls - Graphical features drawn on forms to allow user interaction (text boxes, labels, scroll bars, command buttons, etc.) (Forms and Controls are objects.)
Ăž  Properties - Every characteristic of a form or control is specified by a property. Example properties include names, captions, size, color, position, and contents. Visual Basic applies default properties. You can
change properties at design time or run time.
Ăž  Methods - Built-in procedure that can be invoked to impart some action to a particular object.
Ăž  Event Procedures - Code related to some object. This is the code that is executed when a certain event occurs.
Ăž  General Procedures - Code not related to objects. This code must be invoked by the application.
Ăž  Modules - Collection of general procedures, variable declarations, and constant definitions used by application.



Steps in Developing Application
·  There are three primary steps involved in building a Visual Basic application:

  • 1. Draw the user interface
  • 2. Assign properties to controls
  • 3. Attach code to controls

We’ll look at each step.


Drawing the User Interface and Setting Properties

·  Visual Basic operates in three modes.
     Ăž  Design mode - used to build application
     Ăž  Run mode - used to run the application
     Ăž  Break mode - application halted and debugger is available

We focus here on the design mode.

·  Six windows appear when you start Visual Basic.
      Ăž  The Main Window consists of the title bar, menu bar, and toolbar. Th title bar indicates the project name, the current Visual Basic operating mode, and the current form. The menu bar has drop-down menus from which you control the operation of the Visual Basic environment. The toolbar has buttons that provide shortcuts to some of the menu options.

The main window also shows the location of the current form relative to the upper left corner of the screen (measured in twips) and the width and length of the current form........






Download Teach yourself visual basic / PDF










Teach yourself visual basic / PDF











0

Download course VB : Scripting

Download course VB : Scripting











Download course VB : Scripting

















Once the script is generated by recording, we may want to enhance the script to make it more effective. QTP allows you to do this with the help of VB script language elements. Following are some of the VB Script language elements that are commonly used.

Command: InputBox.
Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
Syntax: InputBox(“Enter your name”)
Command: MsgBox.
Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Syntax: MsgBox(“Hello World”)



String Functions:
StrComp: Returns a value indicating the result of a string comparison.
Usage:
A=Strcmp(“Hello”,”Hello”)
A will have value 0 which means true.
InStr: Returns the position of the first occurrence of one string within another
Usage:
val1="welcome to India"
val2="India"
val=InStr(1,val1,val2)
val will have  value 12 . This means that the position of the word India in val1 is 12.

Split: Returns a zero-based, one-dimensional array containing a specified number of substrings with respect to delimiter.
Usage:
Val=”appleXballXcatXdog”
Sval=Split(val,”X”,-1)
Now Sval(0) will have apple
Sval(1)=ball
Sval(2)=cat.
That is Split command will split the string based upon the delimiter specified.



Date and Time Functions:
Now: Returns the current date and time according to the setting of your computer's system date and time.
Usage:
Dim MyVar
MyVar = Now ' MyVar contains the current date and time.

DateAddf: Returns the number of intervals between two dates
Usage:
DiffADate = "Days from today: " & DateDiff("d", Now,"2/7/2008" )
MsgBox DiffADate
DiffADate will have the no of days between today and "2/7/2008"

DateAdd: Returns a date to which a specified time interval has been added.
Usage:
NewDate = DateAdd("m", 1, "31-Jan-95")
The NewDate will be “28-Feb-95”. One month latter than “31-Jan-95”

Day(now): This will return todays day alone. Like 21, 15 or 12
Hour(now): This will retun the current hour alone.




User Defined Function:
Example Function
Public Function Total(a,b, ByRef c)
c=a+b
End Function
Call Total(2,3,d)
D will have the output, the value of c.
Syntax For Writing a Function.
[Public [Default] | Private] Function name [(arglist)]
   [statements]
   [statements]
End Function

Public
Indicates that the Function procedure is accessible........ 





























Download course VB : Scripting



0

Exam in vb / PDF


 Exam in vb / PDF






Exam in vb / PDF










1.      Define each of the following ALU, BASIC, RAM, ROM, and GUI.
2.      What is machine language?
3.      What is the purpose of the Form Layout Window in VB?
4.      How you know that a line is a comment line? Hint: the first character in the line
5.      What is the difference between Name and Caption properties of an object?
6.      What are the initials used in naming the objects text box, label, picture box?
7.      How you represent a string constant? Hint: first and last character should be “
8.      How you store the input box result in a string variable x? How you store the input box result in an integer variable y?
Hint: x=inputbox(“enter value”) y=val(inputbox(“enter value”))
9.      What is the difference between drag and hover is using the mouse?
10.  Give an example of each of the following:
a.       Flowchart
b.      Psedocode
c.       Hierarchy chart
11.  Discuss the steps of the program development cycle, and their order importance.
12.  Which of the following is considered as an input tool, or an output one or both?
a.       Picturebox: for output
b.      Textbox: for input & output
c.       Label:  for output
d.      Inputbox: for input
13.  How to change the font style and the size of the text within the code.
Example:
Text1.Font.Size=14
Text1.Font.Bold=True
14.  Mention the rules of naming variables in VB. Give examples of valid and invalid names.
15.  What is the default name of a label, command buttons, picture box, textbox, etc.
Text1, Text2,….. for textboxes
Command1, command2,…. For command buttons.  … etc
16.  What is the purpose of the Chr, Val, Asc, and Str functions? Give examples.
17.  How to clear the pictureboxes, textboxes, and labels?
Text1.Text=””
Label1.Caption=””
Picture1.Cls
18.  What is the output of the following Code:
a.       Print  “AB” & “CD”
b.      Print  “AB”; ”CD”
c.       Print  “AB” , “CD”
d.      Print  “AB” & 1
e.       Print  “AB” ; 4
f.       Print  3 & “AB” & 1
g.       Print  3 ; “AB” ; 1
h.      Print  3 , “AB” , 1
i.        Print  4 ; “AB”
j.        Print  1 ; 2
k.      Print  1 , 2
l.        Print  str(2) , 2
19.  Discuss the functionality of Len, Left, Right, Mid, InStr, Tab, FormatNumber, and FormateCurrency functions. Give example for using each of them separately or mixed. Example: right(left(“abcd”,2),1)  ,    len(left(“abcdefgh”,4)) …   etc
20.  what is the result of   int(rnd*15)+7?


21.         Which of the following is an invalid filename

  1. home;     work1.doc
  2. [homework1].txt
  3. Homework*2.xls
  4. 2.home,work.txt
  5. All of the above

22.         Which of the following is an invalid filespec

  1. C:\temp#\data.pdf
  2. A:\VisualBasic\cs116\munzer@just.edu.jo
  3. \Temp\data.pdf
  4. 1 and 2
  5. All of the above.....








Download Exam in vb / PDF















 Exam in vb / PDF


0

Tags