0% found this document useful (0 votes)
152 views

Visual Programming

Visual programming allows users to create programs by manipulating program elements graphically rather than textually. Properties are values or characteristics held by Visual Basic objects that can be set at design time or run time. A determinate loop is one where the number of iterations is known in advance, while an indeterminate loop has an unknown number of iterations. If/Else statements allow code blocks to execute conditionally based on if a condition evaluates to true or false. DateDiff can calculate time intervals between dates. Structuring code with procedures allows breaking programs into logical units and easier debugging. Control arrays in Visual Basic are groups of related controls that share event handlers. Visual Basic uses an event-driven programming model where user interactions cause events and event handlers

Uploaded by

Bharath B.v.p
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Visual Programming

Visual programming allows users to create programs by manipulating program elements graphically rather than textually. Properties are values or characteristics held by Visual Basic objects that can be set at design time or run time. A determinate loop is one where the number of iterations is known in advance, while an indeterminate loop has an unknown number of iterations. If/Else statements allow code blocks to execute conditionally based on if a condition evaluates to true or false. DateDiff can calculate time intervals between dates. Structuring code with procedures allows breaking programs into logical units and easier debugging. Control arrays in Visual Basic are groups of related controls that share event handlers. Visual Basic uses an event-driven programming model where user interactions cause events and event handlers

Uploaded by

Bharath B.v.p
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

1.

Visual programming
In computing, a visual programming language is any programming language that
lets users create programs by manipulating program elements graphically rather than by
specifying them textually.
2.

Pointer
PictureBox
TextBox
Frame
CommandButton
CheckBox
OptionButton
ListBox
ComboBox
HScrollBar and
VScrollBar
Timer
DriveListBox
DirListBox
FileListBox
Shape
Line
Image
Data
OLE
Label
3. A property is a value or characteristic held by a Visual Basic object, such as
Caption or Fore Color. Properties can be set at design time by using
the Properties window or at run time by using statements in the program code.
4. A Determinate Loop is one for which the number of times the loop will be executed
is known in advance. The number of executions of the loop is hard-coded into the
program. For example, we may be counting a number of objects whose maximum
number cannot exceed 100.
5. If the condition evaluates to true, then the block of code inside the If statement will
be executed. If condition evaluates to false, then the first set of code after the end of
the If statement (after the closing End If) will be executed.
6. You can use the DateDiff function to determine how many specified time intervals
exist between two dates. For example, you might use DateDiff to calculate the
number of days between two dates, or the number of weeks between today and the
end of the year.
7. Structuring your code with procedures gives you the
following benefits: Procedures allow you to break your programs into discrete
logical units. You can debug separate units more easily than you can debug an entire
program without procedures.
8. In Visual Basic, a control array is a group of related controls in a Visual
Basic form that share the same event handlers. ... One application of control
arrays is to hold menu items, as the shared event handler can be used for code
common to all of the menu items in the control array.
9. The programming model of Visual Basic is event driven: As the user interacts with
the controls on your form, some code is executed in response to user actions. The
user's actions cause events, and each control recognizes its own set of events and
handles them through subroutines, which are called event handlers.
10. VBA InputBox is used to prompt the user to enter the values. This message box is
used to displaying a message and waits for the user action performed by pressing
the button. A text can be return in the text box by using the InputBox function if the
user clicks on the OK or Enter button.

21. Syntax of Defining Visual Basic Data Types


Following is the syntax of defining data types in visual basic.
 
Dim [Variable Name] As [Data Type]
Dim [Variable Name] As [Data Type] = [Value]
If you observe the above syntax, we added a required data type after the variable name to tell the
compiler about the type of data the variable can hold.
 
Item Description

Dim It is useful to declare and allocate the storage space for one or more variables.

[Variable Name] It’s the name of the variable to hold the values in our application.

As The As clause in the declaration statement allows you to define the data type.

[Data Type] t’s a type of data the variable can hold such as integer, string, decimal, etc.

[Value] Assigning a required value to the variable.

Data Types in Visual Basic


The following table shows the list of available data types in a visual basic programming language
with memory size and range of values.
 
Data
Type Size Range

Boolean It depends on the Platform. True or False

Byte 1 byte 0 to 255

Char 2 bytes 0 to 65535

Date 8 bytes 0:00:00am 1/1/01 to 11:59:59pm 12/31/9999

Decimal 16 bytes (+ or -)1.0 x 10e-28 to 7.9 x 10e28

Double 8 bytes -1.79769313486232e308 to 1.79769313486232e308

Integer 4 bytes -2,147,483,648 to 2,147,483,647

Long 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Object 4 bytes on a 32-bit platform, Any type can be stored in a variable of type Object
8 bytes on a 64-bit platform

SByte 1 byte -128 to 127

Short 2 bytes -32,768 to 32,767

Single 4 bytes -3.4028235E+38 through -1.401298E-45 † for negative values;


1.401298E-45 through 3.4028235E+38 † for positive values

String Depends on Platform 0 to approximately 2 billion Unicode characters

UInteger 4 bytes 0 to 4,294,967,295

ULong 8 bytes 0 to 18,446,744,073,709,551,615 (1.8...E+19 †)


Data
Type Size Range

UShort 2 bytes 0 to 65,535

User- Depends on Platform Each member of the structure has a range determined by its data
Defined type and independent of the ranges of the other members

Now, we will see how to use the Data Types in our visual basic applications with examples.

22. Events are basically a user action like key press, clicks, mouse movements, etc.,
or some occurrence like system generated notifications. Applications need to
respond to events when they occur.
Clicking on a button, or entering some text in a text box, or clicking on a menu item,
all are examples of events. An event is an action that calls a function or may cause
another event. Event handlers are functions that tell how to respond to an event.
VB.Net is an event-driven language. There are mainly two types of events −
 Mouse events
 Keyboard events

Handling Mouse Events


Mouse events occur with mouse movements in forms and controls. Following are
the various mouse events related with a Control class −
 MouseDown − it occurs when a mouse button is pressed
 MouseEnter − it occurs when the mouse pointer enters the control
 MouseHover − it occurs when the mouse pointer hovers over the control
 MouseLeave − it occurs when the mouse pointer leaves the control
 MouseMove − it occurs when the mouse pointer moves over the control
 MouseUp − it occurs when the mouse pointer is over the control and the
mouse button is released
 MouseWheel − it occurs when the mouse wheel moves and the control has
focus
The event handlers of the mouse events get an argument of
type MouseEventArgs. The MouseEventArgs object is used for handling mouse
events. It has the following properties −
 Buttons − indicates the mouse button pressed
 Clicks − indicates the number of clicks
 Delta − indicates the number of detents the mouse wheel rotated
 X − indicates the x-coordinate of mouse click
 Y − indicates the y-coordinate of mouse click

How to connect to a Database


24.

using ODBC
This lesson demonstrates how to use ODBC to connect to a database. Here we
have accessed MS Access Database and have fetched results from it. We have
created this example using LiveCode, MS Access 2003 and Windows XP, but you
can use ODBC to connect to any database that supports it, from within LiveCode.
You can download the associated sample stack and database for this lesson below
from this url: https://tinyurl.com/ya5he5y3
 ODBC_Lesson.zip

Creating a Database using MS Access

Click File->New, this will open a Tab in the right side of the Application which will ask
you to select what type of DataBase you are creating. Click Blank Database option.
This will create a blank Database, which we have named livecodeTest.
Creating a table in MS Access
Zoom: Creating a table in MS Access

Click "Create Table in Design View" , this will open up the table design. Add two
fields labeled Name and Company to the table and save it.

Fill the table with Data


Zoom: Fill the table with Data

Double click the table "test", this will open the blank table. Fill in some data and then
save the table and database.

Create a ODBC connection for the Database livecodeTest

Zoom: Create a ODBC connection for the Database livecodeTest

Step 1: Goto Control panel -> Administrative Tools -> Data Sources(ODBC).
Step 2: Add new Data Source

Click the ADD button. This will popup a window asking for the correct driver, Select
Microsoft Access Driver (*.mdb) and click finish

Step 3: Selecting the Database file and Naming it.


Set the name as "runrev" and select the database file livecodeTest.mdb.

Step 4: Creating Login and Password


Click on Advanced button to set the Username as "testUser" and Password
"123456". Click Ok to save login details and click ok to save the Data Source. Setting
username and password is essential to protect the data, of course for a real world
database you would use a secure password.

Step 5: Accessing ODBC connection in LiveCode


Create a basic test stack with a card, a scrolling field, and a button called "Fetch
Data", as above.  We will now add code to the Fetch Data button so that it will fetch
all the data from the Database Table "Test" and display it in the scrolling field.

Step 6: Coding for Fetch Data


Zoom: Step 6: Coding for Fetch Data

on mouseUp
 
  local tDatabaseID
 
  --This will open up connection for the MS Access Database using a ODBC
connection
  put revOpenDatabase("ODBC", "runrev", "livecodeTest", "testUser", "123456" )
into tDatabaseID
     
  if tDatabaseID is null then
     answer "Not connected"
  else
     answer "connected"    
     
     --This statemenr will select all the data from the table Test
     put "SELECT * FROM test" into tQuery      
     
     --This will query the Database Table using the statement in tQuery
     put revDataFromQuery(tab, cr, tDatabaseID, tQuery) into tData
     
     --This will display all the data from the Database
     put tData into field 1
     
     --This closes the Database connection
     revCloseDatabase tDatabaseID
  end if  
 
 
end mouseUp

Step 7: Displaying Results


Click on the Fetch Data button, and you should see a result similar to the above. We
have fetched the data to LiveCode from a MS Access Database using the ODBC
connection.
14.

A message box is a special dialog box used to display a piece of information to the user. As opposed
to a regular form, the user cannot type anything in the dialog box. To support message boxes, the
Visual Basic language provides a function named MsgBox. To support message boxes, the .NET
Framework provides a class named.
To display a simple message box, you can use the MsgBox() function with the following formula:

MsgBox(Message)

Inside the parentheses, pass a string. Here is an example:


Private Sub btnMessage_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnMessage.Click
MsgBox("Welcome to Microsoft Visual Basic")
End Sub

If the message is made of different sections, you can concatenate them using the & operator. You can also

first declare a String variable, initialize it, and pass it to the function.

To create a message box using the .NET Framework, you can call the Show() method of the MessageBox

class using the following formula:

MessageBox.Show(Message)

As done for the MsgBox() function, pass a string to the method. Here is an example:

Private Sub btnMessage_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) _
Handles btnMessage.Click
MessageBox.Show("Welcome to Microsoft Visual Basic")
End Sub

In our lessons, we will mostly use the MsgBox() function, not because it is better than the MessageBox 

class. It is simply a preference; but it is also because these lessons are for Microsoft Visual Basic, so we

give preference to its own (rich) library.

15. Show / Hide Forms


Form in Visual Basic.net 2008 are displayed and hidden using two different methods.To display a form
the Show() method is used and to hide a form Hide() method is used.

Show Method:

This method is used to display the form on top of all other windows even if it is loaded or not loaded into the
memory.

Syntax:

FormName.Show
or
FormName.Show(1,)

In the above syntax, the Show method can also have argument values 0 or 1 for Modeless or Modal forms.

By default this methods modeless or normal forms, but the modal forms more interactive.

16. For Next Loop


A For Next loop is used to repeatedly execute a sequence of code or a block of code

until a given condition is satisfied. A For loop is useful in such a case when we know how

many times a block of code has to be executed. In VB.NET, the For loop is also known as For

Next Loop.

Syntax

For variable_name As [ DataType ] = start To end [ Step step ]  
[ Statements to be executed ]  
Next  

Let's understand the For Next loop in detail.

o For: It is the keyword that is present at the beginning of the definition.


o variable_name: It is a variable name, which is required in the For loop Statement. The value of

the variable determines when to exit from the For-Next loop, and the value should only be

a numeric.

o [Data Type]: It represents the Data Type of the variable_name.


o start To end: The start and end are the two important parameters representing the initial

and final values of the variable_name. These parameters are helpful while the execution begins,
the initial value of the variable is set by the start. Before the completion of each repetition, the

variable's current value is compared with the end value. And if the value of the variable is less

than the end value, the execution continues until the variable's current value is greater than the

end value. And if the value is exceeded, the loop is terminated.

o Step: A step parameter is used to determine by which the counter value of a variable is increased or


iteration in a program. If the counter value is not specified; It uses 1 as the default value.
o Statements: A statement can be a single statement or group of statements that execute during th
iteration in a loop.
o Next: In VB.NET a Next is a keyword that represents the end of the For loop's

Flowchart of For Next loop


18. Common Dialog Controls
A rather tedious, but quite common, task in nearly every application is to prompt the
user for filenames, font names and sizes, or colors to be used by the application.
Designing your own dialog boxes for these purposes would be a hassle, not to
mention that your applications wouldn’t conform to the basic Windows interface
design principles. In fact, all Windows applications use standard dialog boxes for
common operations; two of them are shown in Figure 4.10. These dialog boxes are
implemented as standard controls in the Toolbox. To use any of the common dialog
controls in your interface, just place the appropriate control from the Dialog section
of the Toolbox on your form and activate it from within your code by calling the
ShowDialog method.

The common dialog controls are invisible at runtime, and they’re not placed on your
forms, because they’re implemented as modal dialog boxes and they’re displayed as
needed. You simply add them to the project by double-clicking their icons in the
Toolbox; a new icon appears in the components tray of the form, just below the Form
Designer. The common dialog controls in the Toolbox are the following:

 OpenFileDialog – Lets users select a file to open. It also allows the selection of

multiple files for applications that must process many files at once.

 SaveFileDialog – Lets users select or specify the path of a file in which the current

document will be saved.

 FolderBrowserDialog – Lets users select a folder (an operation that can’t be

performed with the OpenFileDialog control).

 ColorDialog – Lets users select a color from a list of predefined colors or specify

custom colors. FontDialog Lets users select a typeface and style to be applied to the current

text selection. The Font dialog box has an Apply button, which you can intercept from within

your code and use to apply the currently selected font to the text without closing the dialog

box.
Figure 4.10 – The Open and Font common dialog boxes

There are three more common dialog controls: the PrintDialog, PrintPreviewDialog,
and PageSetupDialog controls. These controls are discussed in detail in Chapter,
“Printing with Visual Basic 2008,” in the context of VB’s printing capabilities.

You might also like