Welcome, Guest. Please login or register.
May 23, 2012, 10:41:05 PM
Home Help Search Login Register
News: IELTS at www.ielts.ysapak.com Share your Ideas at this Forum..Share Knowledge....

+  ..::ysapak.com Study help forum::..
|-+  Study Online, Notes, Tips, Tricks, Helping Material, Past papers, Solved, Unsolved Model Papers, Test Papers, Genernal Knowledge Information, Free Educational Courses
| |-+  Visual Basic
| | |-+  3. Doubl e click the return button and add the followi ng code to its _onClick(
0 Members and 2 Guests are viewing this topic. « previous next »
Pages: [1] Go Down Send this topic Print
Author Topic: 3. Doubl e click the return button and add the followi ng code to its _onClick(  (Read 2062 times)
admin
Administrator
Hero Member
*****

Ranking: 200
Offline Offline

Posts: 16074


Looking for some members that can help other students in Studies


« on: January 24, 2011, 07:29:47 PM »

3.  Doubl e click the return button and add the followi ng code to its _onClick() event
 
 Unload Me
 
 

example 2 in your menu to add the appropriate code. 
 
5.  Use <F5> function key to test your project.  Save and backup.
Naming conventions 
U p till now, we have often accepted default names, Text1, Label1, etc.  In a big project,
this is not good practice as it makes the code harder to read or maintain.  Naming
conventions use a prefix of three lowerCase letters to identify the type of control,
followed by a meaningful  name. eg.  lblTitle
 
 Prefix Abbreviations for Control names
Prefix  Control
 Prefix  Control
cbo  combo box
 chk  check box
cmd  command button  dir  directory li st box
drv  drive l ist box
 fil  fil e list box
fil  file list box
 fra   frame
frm  form
 grd  grid
hsb  horizontal scrollbar  img  image
lbl  label
 lin  line
lst  list box
 mnu  menu
ole   OLE client
 opt  option button
pic  picture box
 shp  shape
tmr  timer
 txt   text box
vsb  vertical scrollbar
   
 
Data types in VB
A variable is a named location that holds data.  A variable can only hold one datatype. 
A program can have as many variables as you need but before you can use a variable it
must be declared.
 
You use a DIM statement to declare variables (where DIM stands for di mension).  Here is
the format of the DIM statemen t:
 
Dim VarName As Datatype
 
e.g.  Dim curCost As Currency, Dim strSurname As String
 
 Datatype  Description and Range
 Prefix
Boolean  One of two values only. e.g. True or False  e.g. blnIsOverTime  bln
Byte  Positive numeric values without decimals from 0-256  e.g. 
 byt
bytAge
Currency  Data that holds dollar amounts from 
 cur
-$922,337,203,685,477.5808 to +-
$922,337,203,685,477.5807   e.g. curHourlyPay
Date  Date and time values from Jan 1, 100 to Dec 31, 9999  e.g. 
 dte
dteFir stLesson
Double  Numeric values from –1.79769313486232E+308 to
 dbl
+1.79769313486232E+308. Often called doubl e-precision. 
e.g.  dblMicroMeasurement
Integer  Numeric values with no decimal point or fracti on from –
 int
32,768 to 32,767  e.g.  intCount
Long  Integer values beyond the range of Integer datatype from   lng
 
4.  Use the Project Explorer window to return to your main form and double click
 

 –2,147,483,648 to 2,147,483,647   e.g.  lngStarDistance
Object  A special datatype that holds and references objects such as
 obj
controls or forms.  e.g.  objSoundClip
Single  Numeric values that range from –3,402823E+38 to
 sng
3,402823E+38. Often called single-precision. 
sngYearSalesFigures
String  Data that consists of 0 to 65,400 characters of alphanumeri c
 str
data including special characters such as @, ^, ½  e.g. 
strFirstName
Variant  Data of any datatype used for control and other values for
 vn t or
var
which the datatype is unknown. e.g.   vntControlValue
 
A function is a segment of code that accepts zero, one or more arguments and returns a
single result.  Visual Basi c i ncludes many built-in functions (intrinsic functions).  Some
perform basic mathematical tasks.  Others manipulate string data such as converting text
to upperCase or lowerCase letters.   
 
An argument is a value you pass to a function so the function has data to work with.
 
Function names have parentheses at the end to hold the function arguments.  Even if a
function has no arguments, the parenthesis are required.
 
Two intrinsic functions include message boxes and input boxes.
 
Activity 3: Message and input boxes
Message and input boxes are intrinsic functions in Visual Basic 6.0 which allow the end
user to interact with the program.
 
Follow the instructions Add new form to menu  at the end of Activity 1  to create a new
form with a menu heading on the main form.  Call this “Message and Input Boxes”
•  Make the Form.Caption = “Message and Input Boxes”
•  Put a label on the top of the form  “Computer Conversation”.  Underneath have a
command button with the caption “Talk to me!”  Name the command button cmdTalk.
•  Doubl e click the command button to add the following code sequence.
Private Sub cmdTalk_Click()
Dim strQuestion As String
 ‘First you must declare your variables’
Dim intAnswer As Integer
‘Then use the input and message box functions’
strQuestion = InputBox(“Type in your name!”, “Ebeneezer”)
intAnswer = MsgBox(“Hello there” & strQuestion, vbOKCancel, “Chat”)
End Sub
•  Add a return button, called cmdBack as you did in the ColourChanger, using the code
Private Sub cmdBack_Click()
Form1.Show
End Sub
•  Run your program using <F5>.  Don’t forget to save your work.
 
H ere are some handy literals (values that don’t change).  You don’t have to learn them
as the help prompt supplies a drop down list as you start to type.
 
 
 

Named Literal  Value  Description
vbOKOnly  0  Displays the OK button
vbOKCancel  1  Displays the OK button and Cancel buttons
vbAbortRetryIgnore  2  Displays the Abort, Retry and Ignore buttons.
vbYesNoCancel  3  Displays the Yes, No and Cancel buttons.
vbYesNo  4  Displays the Yes and No buttons.
vbRetryCancel  5  Displays the Retry and Cancel buttons.
 
Icons in Message Boxes
Named literal  Value  Description
vbCritical  16  Displays Critical Message icon
vbQuestion  32  Displays Warning Query icon.
vbExclamation  48  Displays Warning Message icon.
vbInformation  64  Displays Information message icon.
vbSystemModal  4096  Displays a System Modal dialog box.  The user must
acknowledge this box before doing anything else.
 
Remarks are added in code to explain the purpose of a section of code or to add
i nformation for code maintenance.  If Rem or ‘ is placed in front of the remark, that line
of code is ignored completely.
 
Activity 4
Create a calculator that can add, subtract, multiply and di vide two numbers given by the
user.   
[A possible soluti on might use two input boxes (txtOne and txtTwo) and a label to display
the answer (lblAnswer).
 
D eclare  variables:
dblNo1 As Double
dblNo2 As Double
dblAnswer As Double
intError As Integer
 
U se Val function to change string from input box to a number, then an assignment
statement to put that value into the variable.   
 
 dblNo1 = Val (txtOne.text)
Repeat for second number.
 
U se a Format function to ensure answer is rounded off to two deci mal places.
 
 lblAnswer.Caption = Format (dblAnswer, “#,##0.00”)
If you are very clever, this might be an option for the user.
 
Ensure that it is not possible to divide by zero, either by entering nothing or by entering
zero.  Use the MsgBox() function to indicate the problem to the user.
If Val (txtTwo.Text) = 0 Then
IntError = MsgBox (“You cannot divide by 0!”, VbOkCancel, “Whoops!)
Else …
End If
 
Buttons in Message Boxes
Logged
Pages: [1] Go Up Send this topic Print 
« previous next »
Jump to:  
Get Daily Ayat & Ahadith. To subscribe simply write JOIN ysa1 in sms send it to 8002. for Quotation, Recipes, Joke, Words alerts click here


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.134 seconds with 20 queries.