Thursday, September 2, 2021

Visual basic interface


Visual basic interface

     Visual Basic is a computer programming language allows the creation of user-defined functions and the automation of specific computer processes and calculations. Users do not have to buy a copy of Visual Basic professional because Visual Basic for Applications is a standard feature of Microsoft Office products. Visual Basic for Applications (VBA) allows users additional customization beyond what is normally available in Microsoft Office products, such as Excel, Access, Word and PowerPoint.

How to open the VBA environment

     
Select the Developer tab from the toolbar at the top of the screen. Then click on the Visual Basic option in the Code group.

Now the Microsoft Visual Basic editor should appear and you can view your VBA code.


Project Explorer


The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's take a few moments to analyze the various sections in the Microsoft Visual Basic window.
The Project Explorer can usually be found in the top left portion of the Microsoft Visual Basic window. It is a hierarchical listing of the objects recognized by VBA.


In this example, there are four Excel objects which represent each sheet and workbook in your Excel file - Sheet1, Sheet2, Sheet3, and ThisWorkbook.
There is also one module called Module1. The VBA code in Module1 can used anywhere in your spreadsheet. Whereas, the code within an Excel object is typically only used by that object.
If the Project Explorer is not visible when you open the Microsoft Visual Basic for Appliations window, you can make it visible by selecting Project Explorer under the View menu.

Properties Window

The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's analyze the Properties window in the VBA environment.
The Properties window is usually found directly below the Project Explorer in Excel 2010. It displays the properties for the object currently highlighted in the Project Explorer.


In the example above, it is displaying the properties for the module called Module1.
If the Properties Window is not visible when you open the Microsoft Visual Basic for Applications window, you can make it visible by selecting Properties Window under the View menu. 

Code Window
The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's analyze the Code window in the VBA environment. The Code window is usually found to the right of the Project Explorer in Excel 2010. It displays the VBA code for the object currently highlighted in the Project Explorer.


In the example above, it is displaying the VBA code for the module called Module1.

If the Code window is not visible when you open the Microsoft Visual Basic for Applications window, you can make it visible by selecting Code under the View menu.
Immediate Window
The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's analyze the Immediate window in the VBA environment.


In Excel 2010, the Immediate window is usually found below the Code window. It is an essential element of the debugger found within the VBA environment. It lets you:

  • Type code and press ENTER to view the results of the code.
  • When in debug mode, it lets you view the value of a variable in its current state. This will be discussed in the tutorial on Debugging VBA Code.
If the Immediate window is not visible when you open the Microsoft Visual Basic for Applications window, you can make it visible by selecting Immediate Window under the View menu.

Watch Window

The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's analyze the Watch window in the VBA environment.


In Excel 2010, the Watch window is usually found below the Code window. It is one of the most valuable tools when debugging in the VBA environment. It lets you:

  • Define and monitor any expression.
  • When in debug mode, it lets you view the value of the watched expression in its current state. This will be discussed in the tutorial on Debugging VBA Code.
If the Watch window is not visible when you open the Microsoft Visual Basic for Applications window, you can make it visible by selecting Watch Window under the View menu.

Wednesday, June 6, 2018

batch script


Batch script

Batch Scripts are stored in simple text files containing lines with commands that get executed in sequence, one after the other. Scripting is a way by which one can alleviate this necessity by automating these command sequences in order to make one’s life at the shell easier and more productive. This tutorial discusses the basic functionalities of Batch Script along with relevant examples for easy understanding.
Batch scripts are stored in simple text files containing lines with commands that get executed in sequence, one after the other. These files have the special extension BAT or CMD. Files of this type are recognized and executed through an interface (sometimes called a shell) provided by a system file called the command interpreter. On Windows systems, this interpreter is known as cmd.exe.

Functions
Ver functions
            This batch command shows the version of MS-DOS you are using
Syntax
            Ver
Example
           @echo off
            Ver
Output
Microsoft windowso[6.3.9600]

Assoc functions
            This is a batch command that associates an extension with a file type (FTYPE), displays existing associations, or deletes an association.
Syntax
            Assoc – file path
            Assoc | find “.doc” > file path
Example
@echo off
Assoc > c:\lists.txt
Assoc | find”.doc” > c:\lists.txt
Output
.doc=word.docment8
.dochtml= word html file

cd functions
This batch command helps in making changes to a different directory, or displays the current directory.
Syntax
Cd
Example
@echo off
Rem changing the program files
Cd\program files
Cd
Rem changing the path to program files
Output
C:\program files

Cls function
This batch command clears the screen.
Syntax
cls
Example
@echo off
Cls
The comment prompt screen will be cleared

Copy function
This batch command is used for copying files from one location to the other
Syntax
Copy[source][destination ]
Example
@echo off
Copy c:\list.txt c:\new folder
Output
All actions are performed as per the remarks in the batch file.

Del functions
          This batch command deletes files and not directories.
Syntax
          Del[file name]
Example
          @echo off
          Del c:\lists.txt
Output
Delete the c directory file

Dir function
This batch command lists the contents of a directory.
Syntax
          Dir
Example
@echo off
Dir *.txt
Output
Give the .txt extension file in dir

Date function
          This batch command help to find the system date.
Syntax
          Date
Example
          @echo off
          Date
Outputs
The current date will be displayed in the command prompt.

Echo function
          This batch command displays messages, or turns command echoing on or off.
Syntax
Echo ”string”
Example
Echo “hello world”
Output
Hello world

Exit function
this batch command exits the DOS console.
Syntax
          Exit
Example
@echo off
Echo “hello world”
Exit
Output
The batch file will terminate and the command prompt window will close.

Md functions
          This batch command creates a new directory in the current location.
Syntax
          Md[directory name]
Example
@echo off
Md newfolder
Cd new folder
Outputs
C:\new folder

Move function
          This batch command moves files or directories between directories.
Syntax
           Move[source][destination]
Example
@echo off
move c:\list.txt c:\new folder
Output
All actions are performed as per the remarks in the batch file.

Path function
This batch command displays or sets the path variable.
Syntax
          Path
Example
          @echo off
          Echo%path%
Output
The value of the path variable will be displayed in the command prompt.
Pause function
          This batch command prompts the user and waits for a line of input to be entered.
Syntax
          Pause
Example
          @echo off
          Pause
Output
The command prompt will show the message “Press any key to continue….” to the user and wait for the user’s input.

Prompt function
          This batch command can be used to change or reset the cmd.exe prompt.
Syntax
          Prompt[newpromptname]
Example
@echo off
prompt myprompt$g
output
The prompt shown to the user will now be myprompt>

Rd function
          This batch command removes directories, but the directories need to be empty before they can be removed.
Syntax
          Rd [directory name]
Example
@echo off
Rd c:\newfolder
Output
All actions are performed as per the remarks in the batch file.

Ren function
          Renames files and directories
Syntax
          Ren[old file name][new file name]
Example
          @echo off
          Ren c:\list.txt c:newlist.txt
Output
the file lists.txt will be renamed to newlists.txt.

start function
          This batch command starts a program in new window, or opens a document
Syntax
          Start”program name”
Example
          @echo off
          Start notepad.exe
Output
When the batch file is executed, a new notepad windows will start.

Choice function
          This batch command provides a list of options to the user.
Syntax
          Choice /c [option] /m [message]
Example
          @echo off
          Echo “what is the file size”
          Echo “a:10mb”
          Echo “b:20mb”
          Choice /c ab /m “what is your option a , b ”
Output
What is the file system
A:10mb
B:20mb
What is your  option a, b




         



















Batch script

Batch Scripts are stored in simple text files containing lines with commands that get executed in sequence, one after the other. Scripting is a way by which one can alleviate this necessity by automating these command sequences in order to make one’s life at the shell easier and more productive. This tutorial discusses the basic functionalities of Batch Script along with relevant examples for easy understanding.
Batch scripts are stored in simple text files containing lines with commands that get executed in sequence, one after the other. These files have the special extension BAT or CMD. Files of this type are recognized and executed through an interface (sometimes called a shell) provided by a system file called the command interpreter. On Windows systems, this interpreter is known as cmd.exe.

Functions
Ver functions
            This batch command shows the version of MS-DOS you are using
Syntax
            Ver
Example
           @echo off
            Ver
Output
Microsoft windowso[6.3.9600]

Assoc functions
            This is a batch command that associates an extension with a file type (FTYPE), displays existing associations, or deletes an association.
Syntax
            Assoc – file path
            Assoc | find “.doc” > file path
Example
@echo off
Assoc > c:\lists.txt
Assoc | find”.doc” > c:\lists.txt
Output
.doc=word.docment8
.dochtml= word html file

cd functions
This batch command helps in making changes to a different directory, or displays the current directory.
Syntax
Cd
Example
@echo off
Rem changing the program files
Cd\program files
Cd
Rem changing the path to program files
Output
C:\program files

Cls function
This batch command clears the screen.
Syntax
cls
Example
@echo off
Cls
The comment prompt screen will be cleared

Copy function
This batch command is used for copying files from one location to the other
Syntax
Copy[source][destination ]
Example
@echo off
Copy c:\list.txt c:\new folder
Output
All actions are performed as per the remarks in the batch file.

Del functions
          This batch command deletes files and not directories.
Syntax
          Del[file name]
Example
          @echo off
          Del c:\lists.txt
Output
Delete the c directory file

Dir function
This batch command lists the contents of a directory.
Syntax
          Dir
Example
@echo off
Dir *.txt
Output
Give the .txt extension file in dir

Date function
          This batch command help to find the system date.
Syntax
          Date
Example
          @echo off
          Date
Outputs
The current date will be displayed in the command prompt.

Echo function
          This batch command displays messages, or turns command echoing on or off.
Syntax
Echo ”string”
Example
Echo “hello world”
Output
Hello world

Exit function
this batch command exits the DOS console.
Syntax
          Exit
Example
@echo off
Echo “hello world”
Exit
Output
The batch file will terminate and the command prompt window will close.

Md functions
          This batch command creates a new directory in the current location.
Syntax
          Md[directory name]
Example
@echo off
Md newfolder
Cd new folder
Outputs
C:\new folder

Move function
          This batch command moves files or directories between directories.
Syntax
           Move[source][destination]
Example
@echo off
move c:\list.txt c:\new folder
Output
All actions are performed as per the remarks in the batch file.

Path function
This batch command displays or sets the path variable.
Syntax
          Path
Example
          @echo off
          Echo%path%
Output
The value of the path variable will be displayed in the command prompt.
Pause function
          This batch command prompts the user and waits for a line of input to be entered.
Syntax
          Pause
Example
          @echo off
          Pause
Output
The command prompt will show the message “Press any key to continue….” to the user and wait for the user’s input.

Prompt function
          This batch command can be used to change or reset the cmd.exe prompt.
Syntax
          Prompt[newpromptname]
Example
@echo off
prompt myprompt$g
output
The prompt shown to the user will now be myprompt>

Rd function
          This batch command removes directories, but the directories need to be empty before they can be removed.
Syntax
          Rd [directory name]
Example
@echo off
Rd c:\newfolder
Output
All actions are performed as per the remarks in the batch file.

Ren function
          Renames files and directories
Syntax
          Ren[old file name][new file name]
Example
          @echo off
          Ren c:\list.txt c:newlist.txt
Output
the file lists.txt will be renamed to newlists.txt.

start function
          This batch command starts a program in new window, or opens a document
Syntax
          Start”program name”
Example
          @echo off
          Start notepad.exe
Output
When the batch file is executed, a new notepad windows will start.

Choice function
          This batch command provides a list of options to the user.
Syntax
          Choice /c [option] /m [message]
Example
          @echo off
          Echo “what is the file size”
          Echo “a:10mb”
          Echo “b:20mb”
          Choice /c ab /m “what is your option a , b ”
Output
What is the file system
A:10mb
B:20mb
What is your  option a, b




         


















Data base function

Database function Daverage function      Averages the values in a field (column) of records in a list or database that match conditio...