Chapter2 - Chapter 2 Fundamentals Sample Programs...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 2 Fundamentals
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Sample Programs HelloWorld Output to Screen TwoTimesNumber Input from Keyboard, Math Operators, Assignment Statements, Variables Hypotenuse Message Box, Double Variables, Math Module, Gravity Order of Operations, Input Box, Formatting Numbers Perimeter Modulus Operator, Integer Division, Character Variables, Detailed Format Number
Background image of page 2
3 Creating a Console Application Start VB.NET Select New Project on the start page Select Visual Basic Projects Select Console Application Enter “HelloWorld” as the name of the project and select a folder to save the project
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Current Screen VB.NET automatically creates a few lines of starter code This program is not capable of doing anything We will make the program display a short message on the screen First, we will talk about program structure …
Background image of page 4
5 Modules There has to be at least one module in every project VB.NET IDE assigns a default name to each module The name of the module can be changed For example Module1.vb can be changed to HelloWorld.vb To change the name of the module click on: File Save Module1.vb As…
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Subroutines Every module contains one or more subroutines. The main subroutine (and there is only one main subroutine) is where the program execution begins The main subroutine starts with Sub Main() and ends with End Sub
Background image of page 6
7 Complete and Run the Program Type the following line inside the main subroutine Save the program by clicking on: File Save Module There are two options to run the program Click on: Debug Start Without Debugging Press F5
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Output Screen The cursor is set at the start of the next line after printing its text.
Background image of page 8
9 Sample Program Two Times Number Write a program that lets the user enter a number, multiplies this number by two and displays the result on the screen. New Concepts Integer and string variables, Console Input, Console Output with Console.Write(), Assignment statement (=), Multiplication operator (*)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Creating the Program
Background image of page 10
11 Auto-complete Part of the user-friendliness of VB.NET shows when one writes a code. The syntax for calling the function or subroutine of a VB object such as Math or Console is “ objectName.objectFunction ”. Well, the coder is not expected to remember all the existing functions of each object, so VB has an auto-complete feature to help the coder. As soon as he or she types the “.”, an list-box unfolds next to the “.” and containing all the existing functions, subroutines, and objects of the initial object.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 Running the Program Variable Value strNumber Number TwiceNumber “23” 23 46
Background image of page 12
13 Sample Program Output Note that the input “23” is on the same line as “Please enter an integer :” Program Code
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
14 Sample Program Output If the user does not input an integer the computer will try and store the input as integer. If a decimal number was inputted, as in the figure below, only
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 72

Chapter2 - Chapter 2 Fundamentals Sample Programs...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online