Artificial intelligence, robotics, PHP, Javascript, hacking, CSS, Photoshop, deep learning, machine learning, Visual basic

Wednesday, 29 August 2018

Visual Basic | Introduction

Visual Basic | Introduction


Visual Basic is a programming language and development environment created by Microsoft. It is an extension of the BASIC programming language that combines BASIC functions and commands with visual controls. Visual Basic provides a graphical user interface GUI that allows the developer to drag and drop objects into the program as well as manually write program code.
Visual Basic, also referred to as "VB," is designed to make software development easy and efficient, while still being powerful enough to create advanced programs. For example, the Visual Basic language is designed to be "human readable," which means the source code can be understood without requiring lots of comments. The Visual Basic program also includes features like "IntelliSense" and "Code Snippets," which automatically generate code for visual objects added by the programmer. Another feature, called "AutoCorrect," can debug the code while the program is running.
Programs created with Visual Basic can be designed to run on Windows, on the Web, within Office applications, or on mobile devices. Visual Studio, the most comprehensive VB development environment, or IDE, can be used to create programs for all these mediums. Visual Studio .NET provides development tools to create programs based on the .NET framework, such as ASP.NET applications, which are often deployed on the Web. Finally, Visual Basic is available as a streamlined application that is used primarily by beginning developers and for educational purposes.

Features of Visual Basic

GUI Interface

VB is a Graphical User Interface (GUI) language. This means that a VB program will always show something on the screen that the user can interact with (usually via mouse and keyboard) to get a job done. The first step in building the VB program is to get the GUI items on the screen. This is done via pull-down menus that list the available graphical objects. Every system is slightly different (Mac differs from Windows and VB4 Differs from VB6) but, generally speaking, left-clicking on an object allows you to describe attributes like size and position. Right clicking allows you to write code. For example, if the GUI item is a switch, left-clicking would allow the programmer to say how big the switch was, how it was labeled and where on the screen it is positioned. Right-clicking on the switch would bring up a window that allows the programmer to write the code that describes what happens when the user clicks the switch.

Modularization

It is considered good programming practice to modularize your programs. Instead of thinking of a computer program as a single large collection of code, the good programmer writes code so that you never need to look at more code than fits on the screen (or page) at one time. If you program in modules like this, the program is easier to understand and easy to update. Updating will likely be done by someone else so it is import that the program be easy to understand. Small (page size) modules where it is clearly indicated what comes into the module and what goes out makes a program easy to understand. VB forces you to program in a modular fashion because each GUI item contains part of the code---the part that applies to that GUI item.

Object Orentation

Object Oriented Programming (OOP) is a concept where the programmer thinks of the program in "objects" (however abstract the objects may be) that interact with each other. In OOP, all the code associated with that object is in one place. Once again, VB forces this good programming practice. The GUI items are the objects and all the code associated with the object are just a click away. This natural way of enforcing good programming practices---plus the ease of programming in BASIC---is exactly why VB has found so many devoted fans.

The Integrated Development Environment(IDE)

One of the most significant changes in Visual Basic 6.0 is the Integrated Development Environment (IDE). IDE is a term commonly used in the programming world to describe the interface and environment that we use to create our applications. It is called integrated because we can access virtually all of the development tools that we need from one screen called an interface. The IDE is also commonly referred to as the design environment, or the program.

Tha Visual Basic IDE is made up of a number of components
·        
         Menu Bar
·         Tool Bar
·         Project Explorer
·         Properties window
·         Form Layout Window
·         Toolbox
·         Form Designer
·         Object Browser

Menu Bar

This Menu Bar displays the commands that are required to build an application. The main menu items have sub menu items that can be chosen when needed. The toolbars in the menu bar provide quick access to the commonly used commands and a button in the toolbar is clicked once to carry out the action represented by it.

Toolbox

The Toolbox contains a set of controls that are used to place on a Form at design time thereby creating the user interface area. Additional controls can be included in the toolbox by using the Components menu item on the Project menu.

Project Explorer

Docked on the right side of the screen, just under the tollbar, is the Project Explorer window. The Project Explorer as shown in in figure servres as a quick reference to the various elements of a project namely formclasses and modules. All of the object that make up the application are packed in a project. A simple project will typically contain one form, which is a window that is designed as part of a program's interface. It is possible to develop any number of forms for use in a program, although a program may consist of a single form. In addition to forms, the Project Explorer window also lists code modules and classes.

Properties Window

The Properties Window is docked under the Project Explorer window. The Properties Window exposes the various characteristics of selected objects. Each and every form in an application is considered an object. Now, each object in Visual Basic has characteristics such as color and size. Other characteristics affect not just the appearance of the object but the way it behaves too. All these characteristics of an object are called its properties. Thus, a form has properties and any controls placed on it will have propeties too. All of these properties are displayed in the Properties Window.

Object Browser

The Object Browser allows us to browse through the various properties, events and methods that are made available to us. It is accessed by selecting Object Browser from the View menu or pressing the key F2. The left column of the Object Browser lists the objects and classes that are available in the projects that are opened and the controls that have been referenced in them. It is possible for us to scroll through the list and select the object or class that we wish to inspect. After an object is picked up from the Classes list, we can see its members (properties, methods and events) in the right column.
A property is represented by a small icon that has a hand holding a piece of paper. Methods are denoted by little green blocks, while events are denoted by yellow lightning bolt icon.

Control


Control
Description
Pointer
Provides a way to move and resize the controls form
PictureBox
Displays icons/bitmaps and metafiles. It displays text or acts as a visual container for other controls.
TextBox
Used to display message and enter text.
Frame
Serves as a visual and functional container for controls
CommandButton
Used to carry out the specified action when the user chooses it.
CheckBox
Displays a True/False or Yes/No option.
OptionButton
OptionButton control which is a part of an option group allows the user to select only one option even it displays mulitiple choices.
ListBox
Displays a list of items from which a user can select one.
ComboBox
Contains a TextBox and a ListBox. This allows the user to select an ietm from the dropdown ListBox, or to type in a selection in the TextBox.
HScrollBar and VScrollBar
These controls allow the user to select a value within the specified range of values
Timer
Executes the timer events at specified intervals of time
DriveListBox
Displays the valid disk drives and allows the user to select one of them.
DirListBox
Allows the user to select the directories and paths, which are displayed.
FileListBox
Displays a set of files from which a user can select the desired one.
Shape
Used to add shape (rectangle, square or circle) to a Form
Line
Used to draw straight line to the Form
Image
used to display images such as icons, bitmaps and metafiles. But less capability than the PictureBox
Data
Enables the use to connect to an existing database and display information from it.
OLE
Used to link or embed an object, display and manipulate data from other windows based applications.
Label
Displays a text that the user cannot modify or interact with.


Share:

Saturday, 18 August 2018

Python | Python syntax

Python | Python syntax


Python is an interpreted, object-oriented programming language similar to PERL, that has gained popularity because of its clear syntax and readability. Python is said to be relatively easy to learn and portable, meaning its statements can be interpreted in a number of operating systems.

Comment

Comments are used to document and are ignored by the compiler.
In python, comments are of two types. That is,
·        Single line comment
·        Multi-line comments

Single line comments
In python, all comment characters are written after the # sign.

Example

# Python Basic Syntax - Example Program
# We are comments


Multiline Comment in Python
Multiline starting commenting code is ''' and ending with same, that is '''.
Example
''' This
    is
    multiline
    comment
'''
''' Multiline comment
    starts with \'''
    and ends with
    \'''
'''

Printing statement
General form to use print statement in python.
print("any character or string");
 
In the above syntax of print statement, print is the keyword, opening (" and closing ") followed by ; are the syntax to write print statement in python to successfully output any required combination of characters on the output screen.
 
Variables
Variables in Python, are the reserved memory locations to store the values in a Python program. To create a variable and assign some values to it, follow the given syntax or general form in Python.

variable_name = "value to be assign";
 
You can also say that the above statement is called as assignment statement. In the above statement variable_name is the name of the variable, and the value is assine inside “ and “ sign.
 
Operators
Operators in Python, are used to perform mathematical and logical operations. There are the following types of operators available in Python:
  • Arithmetic Operators
  • Logical Operators
  • Comparison (Relational) Operators
  • Assignment Operators
  • Bitwise Operators
  • Membership Operators
  • Identity Operators
Arithmetic operators

Operator
Name
Meaning
+
Addition Operator
Add two values
-
Subtraction Operator
Used for subtraction
*
Multiplication Operator
Used for multiplication
/
Division Operator
Used for division
%
Modulus Operator
Returns remainder after dividing
//
Floor Division Operator
Returns the quotient without any digits after decimal
**
Exponent Operator
Used to perform exponential calculation on operators
 
Comparison operators

Operator
Meaning
==
Returns true if values of the two operands are equal, otherwise returns false if not equal
!=
Returns true if value of the two operands are not equal, otherwise returns false if equal
> 
Returns true if value of the left operand is greater than right one, otherwise false if value of the right operand is greater than left one
< 
Returns true if value of the left operand is less than right one, otherwise false if value of the right operand is less than left one
>=
Returns true if value of the left operand is greater than or equal to the value of the right one, otherwise false if value of the right operand is greater than left one
<=
Returns true if value of the left operand is less than or equal to right one, otherwise false if value of the right operand is less than or equal to left one
 
Assignment operators

Operator
Name
Meaning
=
Simple Assignment Operator
Used for assigning values
+=
Add and Assignment Operator
This operator adds the right operand to the left operand and assigns the result to the left operand
-=
Subtract and Assignment Operator
This operator subtracts the right operand from the left operand and then assigns the result to the left operand
/=
Divide and Assignment Operator
This operator divides the left operand with the right operand and then assigns the result to the left operand
*=
Multiply and Assignment Operator
This operator multiplies the right operand with the left operand and then assigns the result to the left operand
**=
Exponent and Assignment Operator
This operator performs the exponential calculation on operators and then assign the value to the left operand
%=
Modulus and Assignment Operator
This operator takes modulus using the two operands and then assigns the result to the left operand
//=
Floor Division and Assignment Operator
This operator performs the floor division on the operators and then assign the value to the left operand
 
Bitwise operators    
              
Operator
Name
Meaning
&
Binary AND Operator
This operator copies a bit to the result only if its exists in both the operands
^
Binary OR Operator
This operator copies a bit only if it exists in either the operand
|
Binary XOR Operator
This operator copies the bit only if it is the set of one operand but not the both
~
Binary Ones Complement Operator
This is unary operator, has the effect of 'flipping' bits
>> 
Binary Right Shift Operator
The left operand's value is moved right by the number of bits specified by the right operand
<< 
Binary Left Shift Operator
The left operand's value is moved left by the number of bits specified by the right operand
 
 Logical operators

Operator
Name
Meaning
and
Logical AND Operator
If both the operands are true, then the condition becomes true, otherwise false
not
Logical NOT Operator
This operator used to reverse the logical state of its operand
or
Logical OR Operator
If any of the two operands are non-zero, then the condition becomes true, otherwise false
 
Import statement
The import statement is used to import or load modules (modules are files, contains code to be used in other program just by importing that module using the import statement), for example, to load random module,
 General form.
import random
 
Example
import random
val1 = random.randrange(100);
val2 = random.randrange(100);
print("Following are the two generated random numbers \
under 100.");
print("First: ",val1);
print("Second: ",val2);
 
Function
A function in python, is a block of code, used to perform a particular action.
Rules for defining a function
To define a function in python, follow these rules:
  • function blocks in python, begins with the keyword def, followed by the function name and then parentheses
  • the parameters/arguments should be placed inside these parentheses
  • the code block of the function starts with a colon (:)
  • and now the return statement exits a function, passing back an expression to the function caller
  • a return statement with no any arguments is the same as return None
General form

def function_name(parameters):
               "function_doc_string"
               function_suite
               return [expression]
 
Example
def printit(strn):
                    "This will print the passed string into this function"
                    print(strn)
                    return
 
Decision making statement
Decision-making statements in python help in controlling your program accordingly. There are the following decision-making statements available in Python:
  • if statement
General form

if expression:
            statement(s)

  • if-else statement
General form
if expression:
                    statement(s)
else:
                    statement(s)

  • nested if statement
General form
if expression1:
               statement(s)
               if expression2:
                               statement(s)
               elif expression3:
                               statement(s)
               else:
                               statement(s)
else:
               statement(s)

Loops
Loops in Python are used to control your program. Loops are basically used to execute a block of code several numbers of times accordingly. There are the following types of loops available in Python:
  • for loop
general form
for iterating-var in sequence:
                    statement(s)

  • while loop
General form
while expression:
statement(s)

  • nested loop
General form (nested for loop)
for iterating-var in sequence:
               for iterating-var in sequence:
                               statement(s)
               statement(s)

     General form (nested while loop)
while expression:
   while expression:
      statement(s)
   statement(s)


Share:

Copyright © Technotalk | Powered by Academy for brilliance