Open Means Open Means

A Good Example of Visual Basic Programme(Insert, Update, Delete and Record navigation)

No comments on “A Good Example of Visual Basic Programme(Insert, Update, Delete and Record navigation)”

Customer

Dim flag As Boolean
Dim strn As String
Dim strn1 As String
Dim re As Integer
Dim ss1 As Boolean
 Private Sub Command1_Click()
Form1.Visible = False
Load Form2
Form2.Visible = True
End Sub
 Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
 Private Sub Command3_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Or Text5.Text = "" Or Text6.Text = "" Then
MsgBox "Enter Data"
Text1.SetFocus
Else
 flag = True
strn = UCase(Text1.Text)
 
If rs.State = 1 Then rs.Close
rs.Open "select distinct name  from  Cust_Data", con, adOpenDynamic, adLockOptimistic
While Not rs.EOF
re = 0
strn1 = UCase(rs.Fields(0).value)
 re = StrComp(strn, strn1)
 If re = 0 Then
ss1 = True
Command2_Click
flag = False
 End If
rs.MoveNext
Wend
If ss1 = True Then
MsgBox "Name Duplication"
ss1 = False
End If
If rs.State = 1 Then rs.Close
If flag = True Then
Module1.name = strn
'rs.Open "insert into Cust_Data values('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "')", con, adOpenDynamic, adLockOptimistic
rs1.AddNew
rs1.Fields(0).value = strn
rs1.Fields(1).value = Text2.Text
rs1.Fields(2).value = Text3.Text
rs1.Fields(3).value = Text4.Text
rs1.Fields(4).value = Text5.Text
rs1.Fields(5).value = Text6.Text
rs1.Update
End If
End If
End Sub
 Public Sub display()
Text1.Text = rs1.Fields(0).value
Text2.Text = rs1.Fields(1).value
Text3.Text = rs1.Fields(2).value
Text4.Text = rs1.Fields(3).value
Text5.Text = rs1.Fields(4).value
Text6.Text = rs1.Fields(5).value
 End Sub
 Private Sub Command4_Click()
'Command5.Enabled = True
'Command6.Enabled = False
 rs1.MoveFirst
display
End Sub
 
Private Sub Command5_Click()
rs1.MoveNext
If rs1.EOF Then
rs1.MoveLast
'Command5.Enabled = False
'Command6.Enabled = True
End If
display
End Sub
 Private Sub Command6_Click()
rs1.MovePrevious
If rs1.BOF Then
rs1.MoveFirst
' Command6.Enabled = False
' Command5.Enabled = True
End If
display
End Sub
 Private Sub Command7_Click()
'Command6.Enabled = True
'Command5.Enabled = False
 rs1.MoveLast
display
End Sub
 Private Sub Command8_Click()
Dim ans
ans = MsgBox("DO You Want To Update Record", vbYesNo + vbQuestion, "UPDATE")
If ans = vbYes Then
rs1.Fields(0).value = Text1.Text
rs1.Fields(1).value = Text2.Text
rs1.Fields(2).value = Text3.Text
rs1.Fields(3).value = Text4.Text
rs1.Fields(4).value = Text5.Text
rs1.Fields(5).value = Text6.Text
  rs1.Update
MsgBox "Record updated"
Else
MsgBox "Record is as it is"
End If
End Sub
 Private Sub Command9_Click()
 
If rs1.EOF Then
rs1.MovePrevious
rs1.Delete
 rs1.MovePrevious
 Else
 rs1.Delete
rs1.MoveNext
 End If
If rs.State = 1 Then rs.Close
Dim ans
ans = MsgBox("Do you want to delete this record ? ", vbYesNo + vbQuestion, "Confirm")
If ans = vbYes Then
rs.Open "delete from Customer where Cust_ID='" & Text1.Text & "'", con, adOpenDynamic, adLockOptimistic
End If
 If rs.State = 1 Then rs.Close
 End Sub
 Private Sub Form_Activate()
If rs1.State = 1 Then rs1.Close
rs1.Open "select * from Cust_Data", con, adOpenDynamic, adLockOptimistic
StatusBar1.Panels(2).Text = Now()
 End Sub
 
 
 Private Sub Form_Deactivate()
If rs1.State = 1 Then rs1.Close
End Sub
 Private Sub Form_Load()
Form1.Top = MDIForm1.Top + (MDIForm1.Height - Form1.Height) / 2
Form1.Left = MDIForm1.Left + (MDIForm1.Width - Form1.Width) / 2
 End Sub
 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If rs1.State = 1 Then rs1.Close
End Sub
 Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Then
StatusBar1.Panels(1).Text = ""
Else
KeyAscii = 0
StatusBar1.Panels(1).Text = "Please Enter Numeric value"
 End If
End Sub
Private Sub Text6_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Then
StatusBar1.Panels(1).Text = ""
Else
KeyAscii = 0
StatusBar1.Panels(1).Text = "Please Enter Numeric value"
End If
End Sub

 

 

Some Definitions of VBA in Excel

No comments on “Some Definitions of VBA in Excel”

VBA newcomers are often overwhelmed by the terminology that is used in VBA. I’ve put together some key

definitions to help you keep the terms straight. These terms cover VBA and UserForms (custom dialog

boxes)—two important elements that are used to customize Excel:

Code: VBA instructions that are produced in a module sheet when you record a macro. You also

can enter VBA code manually.

Controls: Objects on a UserForm (or in a worksheet) that you manipulate. Examples include buttons,

check boxes, and list boxes.

Function: One of two types of VBA macros that you can create. (The other is a Sub procedure.) A function

returns a single value. You can use VBA functions in other VBA macros or in your worksheets.

Macro: A set of VBA instructions performed automatically.

Method: An action taken on an object. For example, applying the Clear method to a Range

object erases the contents and formatting of the cells.

Module: A container for VBA code.

Object: An element that you manipulate with VBA. Examples include ranges, charts, drawing

objects, and so on.

Procedure: Another name for a macro. A VBA procedure can be a Sub procedure or a Function

procedure.

Property: A particular aspect of an object. For example, a Range object has properties, such as

Height, Style, and Name.

Sub procedure: One of two types of Visual Basic macros that you can create. The other is a function.

UserForm: A container that holds controls for a custom dialog box and holds VBA code to manipulate

the controls. (Chapters 41 and 42 explain UserForms in depth.)

VBA: Visual Basic for Applications. The macro language that is available in Excel, as well as in the

other applications in Microsoft Office.

VB Editor: The window (separate from Excel) that you use to create VBA macros and UserForms.

 

Introduction to grep, egrep and fgrep In Unix

No comments on “Introduction to grep, egrep and fgrep In Unix”

 

The “grep” command:

The name grep stands for global regular expression printer. The grep command is used to search more than one file for particular bit pattern globally and displays the line containing them, The syntax is:

grep char_pattern file[s] 

After the execution of this command, each line of each file that contain the specific  char_pattern will be displayed on the display monitor. If you specify more than one file then each line is also immediately preceded name of the file. If the char pattern does not exist in the specified file then the grep command simply displays a new prompt.

The “grep” command using a single file:

Let us search a particular char_pattern in a single file. For instance, let us suppose, we are going to find every occurrence of word great in the file players. First the contents of the file are:
$ ls players

Cricket is the most loving game in India. There are so many good players
that it is difficult to select which of them are great.
Sachin Tendulkar is one of the great player of all times.
He is the true son of India.
Of course Sunil Gavasker was a good one. But not great.
It is our good luck we are still watching Sachin playing for India.
$

If we want to search word great then we do as:
$ grep great players

that it is difficult to select which of them are great.
Sachin Tendulkar is one of the great player of all times   
Of course Sunil Gavasker was a good one. But not great.
$
   
If we want to search for “son of India “, we write the grep command as:
$grep “son of India” players
He is true son of India.
$

Here if you don’t use double quote signs then the spaces between son, of and India would not produce correct result. Now watch carefully the execution of the following grep command :
$ grep son of India players
grep: cant open of
grep: cant open India
$

Means here, son would be expected as a character pattern and of, India and players are expected as a file to be searched. Since there is no file called of and India therefore the grep command displays the message:
grep: cant open of
grep:Cant open India.

And then it proceeds to search the file players for the pattern son. Thus it, is necessary to use single quotes or double quotes on the multi words pattern string is:
$grep ‘son of India’ players      or
$grep “son of India” players 
               
The grap command using multiple files: ~

The grep command is more helpful when we search for a character pattern in two or more files. Let we search for the word great in three files players 1, players 2 and players 3.
$grep great players1 players2 players3

player1: There are so many great players in the cricket world.
player2: Mazor Dhyan Chand was a great player.
player3: Laila is daughter of great boxer Mohmad Ali.
$

Here the pattern great will found in file named as player1, player2, player3.
Options of grep command: ~

(i)    -c     :     display only the number of matches.
(ii)    -i     :    ignore case while searching
(iii)    -l    :    displays only the name of files, as well as the text itself
(iv)    -n   :    displays the line number, as well as the text itself
(v)    -s    :    displays no output or just error messages are suppressed
(vi)    -v   :    displays those lines that do not match the searched pattern

For example if we want to know how many times the pattern great occurred in a file players, then we write
$ grep –c great players

If we want to see only those lines, which do not contain the specific  pattern, then we use the grep command as:
$ grep –v great players 

We can also use more than one options with a grep command as:
$ grep great –i –c players 1 players 2.

Metacharacter: ~

We can also use metacharacters, special characters such as ?, *, ., [..]
For instance, the following grep command
$grep great players?

Searches all those files that matches upto players? To any 8 characters filenames starting with players. Here the special character, ?, stands for any one characters.

The fgrep and egrep command: ~:


The fgrep and egrep command are advanced pattern matching command. The fgrep command doesn’t use any meta character for its searched pattern. The primary advantage of fgrep it that it can also serch two or more than two strings simultaneously.
The fgrep command can be used like this:
$fgrep ‘good
bad
great’ userfile
$

Here a single quote is used to mark three strings as one argument. Here we are going to search three different strings good, bad, and great. The egrep command is used to search this in a more compact form than fgrep command:
$egrep ‘good | bad | great’ userfile

The egrep uses an or ( | ) operator to achieve this. Therefore egrep command is more compact and more versatile than fgrep. Another achievement of egrep is that we can make groups of different patterns. If we use | as operator.
$egrep ‘sunil | rohan gavasker ‘ players

Here sunil is first pattern and everything to the right is considered as second pattern.
If we want to search both sunil gavasker and rohan gavasker use this:
$egrep ‘(sunil | rohan)‘ players

Example: ~

The program given below represents the functioning of egrep and grep commands:
read statements is the shell’s internal tool for taking input from the user that is Making scripts interactive. It is used with one or more variables and input supplied . the standerd input is read into these variables. Let us suppose a script named as employee1.sh.
The script employee1 uses read to take a search string and file name from the terminal.
$ cat employee1.sh
# script : employee1.sh-interactive version
# the pattern and file name will be supplied by the user
echo “\n enter the pattern to be searched :\c”
read  pname
echo “\n enter the file to be used :\c”
read filename
echo “\n searching for $ pname from file $ filename\n”
grep “ $ pname “  $ filename
echo “\n selected record shown above \n”
\c
put the cursor at the end of echo argument root to the next line


Command Lines In Unix

No comments on “Command Lines In Unix”

 

General feature of a command:

A UNIX command consists of a single word generally using alphabetic characters. Since the designers created UNIX for their own use, they tried to ensure that a minimum number of keystrokes achieved the maximum amount of work. That is why the original UNIX commands are seldom more than four characters long. You have already used some of them – ls, cat, who etc. some modern commands are long words and occasionally contain a numeral or an underscore.

As you know, commands are essential files. These files are stored in folders which better known as directories. For instance, the ls command is also a program represented by a file that located in the directory /bin.

A UNIX command file does not need to have a special extension like .exe or .com though you can provide one if you want to. There is hardly a practical restriction on length either; a command can be up to 255 characters. Other UNIX system, however, have 14 characters long.

The PATH; locating command:

How does UNIX know whether a command is legitimate or not? When you enter a command, the system searches for its file in certain specified directories. If it finds in file in one of these directories, it executes it; otherwise it flashed the message like “Bad command” and so on.

UNIX functioning is controlled by a number of variables. UNIX obtains the list of directories that has to be searched from one of its variables – the one names PATH. If you evaluate the value of this variable, you will find a directory list separated by colons:

$echo $PATH
/bin : /usr/bin : usr/z116/bin : /oracle/bin:.

There are four directories in this list, and when you issue a command, the system will search this list in the sequence specified to locate and execute it. This means that it will first search in /bin then in /usr/bin and so on.

But in which directory the command is l
ocated  is find with the help of type command:
$type ls
ls is /bin/ls

ls is located in /bin directory and because /bin is also a component of the value of the PATH variable, the system locates it easily and executes it.

Command structure:

The structure of a command is given below:

The entire command here has five words separated by spaces. The first word “ls” is actually the command ; the other words are called arguments. The ls command here has four arguments.

Commands and arguments are separated by any number of spaces and tabs together form what is known as whitespace.

Here you can see in the diagram that there are lots of whitespaces between the command and the arguments. The UNIX system processes a special mechanism of compressing these multiple consecutive spaces or tabs into a single space.

Internal and external commands:

The agency that actually does all this work is known  as the shell. This  is a special command that starts running the moment you log in. the shell takes the command that you enter as its input and looks at its own PATH variable to find out where it is located.

Since ls command is a file having an independent existence in the /bin directory , it is called an external command. Most commands are external in nature. But there are some that are not really any where or not executed even if they are found. Take for instance the echo command
$type echo

Echo is a shell built in

When you type echo, the system (rather the shell) would not look in its PATH to locate it (even if it can find it in /bin). Rather it will execute it from its own set of built in commands that are not stored as separated files. These built in commands, of which echo is a member, are known as internal commands. The type command itself is a shell built in.

Options and filenames:

As you can see in the above example that the following command consist of four arguments. Out of the four the two are started with “–“ sign, these two are called the options. Options are used to make a command more flexible. The other two arguments “note1” and “note2” are called the file names.

“The command with its arguments and options is entered in one line that is referred as the command line.”

This line is considered complete only after user has hit “Enter Key”. The complete line is then fed to the shell as its input for interpretations and executions.

Combining option:

Unix is a such kind of operating system that provide you a facility by which you can combine the multiple options of a command in a single command line.

For example we have a command called “ls” and its option like “ –a” , “–t”, “–l”. Such command can be written in two ways like:
$ ls –a –t –l    ------------------------ cmd 1
And
$ ls –atl
    ------------------------cmd 2
Note: Here  “– l” option provides most details of the file attributes. “ – t” option sort the files as per the time of modification and “ – a” option includes the hidden files of the directory or system.

Moreover we can write down these options in any combinations like:

$ ls –alt
$ ls –tal and so on….

Each and every time you get the same output.

Flexibility in command usage:

Combining commands: UNIX and Linux are such kind of operating system that provide the facility to combine the multiple commands in a single command line. This can be done with the help of “Metacharacters”. For example I want to combine the option the command like “who” and “ls”. These commands can be combined with the help of  ; Metacharacter.

$ who; ls –l note1    
    here the “ls” command is executed after “who” command    
Here the ; is the special character that the shell understand. When the command contains this character, the shell understands that the commands on either side of it need to be processed separately.

A command line can overflow: As you know that the width of a terminal is 80 characters. But the number of characters in a single command line is up to 255. This means your single command line can be written in two or more lines of a terminal. To make two or more than two lines command line can be made a single line command by using the “Secondary prompt (>)” option.
For example : the “echo command”

$ echo “this is     
> a three line
> text message.”


Output: this is    
a three line
text message.



Inodes In Unix

No comments on “Inodes In Unix”

 

Inodes:

As we know that each and every file  in a Unix OS consist of a number by which it is uniquely identify by its file system. Such number is known as inode number or information node number.
In Unix file system the disk space is allocated in terms of blocks. These blocks are

1.    Boot Block : Contains the boot step program.
2.   Super block: Contains the information about the file system.
3.  Data Block: Data block are allocated blocks in a file system that contains the actual file contents.
4.    Inode table block: The inode table contain the basic information about the file

This table is accessed with the help of inode number. The inode number for a file is unique in a single file system. The basic information about a file in the node table is accessed with the help of inode number. If there are 10 files in the directory, then there are 1 inode number for each file. The inode table contains information like:

1.    Owner of the file
2.    Size of the file in bytes
3.    Last access date
4.    File creation/ deletion time
5.    Number of links
6.    Access control list
7.    The user and group ID of the file system
8.    Type of file (ordinary, directory or special)
9.    File protection bits.
10.    Address of the block where the file is physically exist and many more

The entry of a file in inode table is changed when the owner, group or permission are changed. The most important thing about the inode table is that it does not contain the name of the file and its contents.

Moreover, you can find out the inode number of a file by using the “- i “ option of “ls” command. Suppose I have a file called “punit”. I want to find out the number of this file. E.g

$ ls –i punit
22645 punit
$

Here 22645 is the inode number of the file “punit”.

Moreover, the changing the name of the file does not change the inode number and if you move this file to any another user defined directory even then the inode number would remain the same.       

 

More Articles …

  1. The C Compiler & Compiler Options In Unix
  2. Electronic Mail In Unix
  3. Perl Script to send an email
  4. About -->>The Evolution of Programming Languages
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Page 6 of 13

  • About Us
  • Faqs
  • Contact Us
  • Disclaimer
  • Terms & Conditions