My data types.docx - My data types...

This preview shows page 1 - 3 out of 16 pages.

The preview shows page 1 - 3 out of 16 pages.
My data typesdgdgdgdgfhgjhkjljklkdgfdgdgdgdladgdst modified July 6, 2020gdgdgdIn this part of the Visuadgdgdgdgdgl Basic tutorial, we willtalk about data types.Computer programs work with data. Tools to work with variousdata types are essential part of a modern computer language.According to the Wikipedia definition, adata typeis a set of values,and the allowable ogdgddggddperations on those values.gdThe two fundamental data types in Visual Basic are value typesand reference tgdgdgdypes. Primitive types (except strings),enumerations, and structures are value types. Classes, strings,standard modules, interfaces, arrays, and delegates are referencetypes. Every type has a default value.Reference typesare createdon the Heap. The lifetime of tgdgddhe reference type is managedby the .NET framework. The default value for reference types isnull reference. Assignment to a variable of a reference typecreates a copy of the reference rather than a copy of thereferenced value.Value typesare created on the stack. Thelifetime is determined by the lifetime of the variable. Assignmentto a variable of a value type creates a copy of the value beingassigned. Value types have different default values. For example,boolean defagdgdgdgult value is False, decimal 0, string an emptystring "".dgdgddgThere is a duality built in our world. There is a Heaven and Earth,water and fire, jing and jang, man and woman, love and hatred. InVisual Basic theBooleandata type is a primitive data type havingone of two values: True ogdgdr False. This is a fundamental datatype. Very common in computer prgdgdgdgdograms.Happy parents are waiting a child to be born. They have chosen aname for both possibilities. If it is going to be a boy, they havechosen John. If it is going to be a girl, they have chosen Jessica.Option Strict On
Modulgdgdgde ExampleDim num As ByteDim male As BooleanSub Main()Randomize()num = CType(Math.Round(Rnd()), Byte)If num = 0 Thenmale = TrueElsemale = FalseEnd IfIf male = True ThenConsole.WriteLine("We will use name John")ElseConsole.WriteLine("We will use name Jessica")End IfEnd SubEnd ModuleThe program uses a random number generator to simulate ourcase.Dim num As ByteThe num variable has a Byte data type. This is important. Bytedata types may have integer values 0..255.Randomize()num = CType(Math.Round(Rnd()), Byte)These two lines pick up randomly 0 or 1. TheRnd()functionreturns a random value less than 1, but greater than or equal tozero. We use theRound()method to round the number. Randomvalues greater than 0.5 are rounded to 1. All other random valuesare rounded to 0. The Double data type is convertedintoByteusing theCType()function. So thenumvariable is assigned0 or 1. TheRandomize()function initializes a random-numbergenerator with a seed based on the system timer.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 16 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Two
Professor
N/A
Tags

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture