Implicit and Explicit Type Conversion Notes

Implicit and Explicit Type Conversion Notes - about...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Implicit and Explicit Type Conversion Notes Implicit Type Conversion Visual Basic will try to automatically convert variables from one type to another, if necessary For example, a “double” (decimal value) can be assigned as an integer; in this case, the decimal is truncated. Strings, if numeric, can be assigned as numbers; otherwise, these yield an error. Explicit Type Conversion Many different functions exist to explicitly convert one variable to another type Examples of these include, but are not limited to: CBool CDec CDate CStr Public Class RandomNumberGenerator 'Global variable: we will discuss these in future lessons
Image of page 1

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

View Full Document Right Arrow Icon
Dim intRandomNumber As Integer = 0 Private Sub btnClose_Click(sender As Object , e As EventArgs ) Handles btnClose.Click 'Close the application Me .Close() End Sub Private Sub btnGenerate_Click(sender As Object , e As EventArgs ) Handles btnGenerate.Click 'Create a new random number 'This is code that we will use by the end of the course; do not worry
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: about understanding it entirely right now intRandomNumber = CInt ( Math .Floor(6) * Rnd()) + 1 End Sub Private Sub btnCheck_Click(sender As Object , e As EventArgs ) Handles btnCheck.Click 'Create intInput as variable to store user input Dim intInput As Integer = txtInput.Text 'Check user input against random number: one of three things will happen: '1. User number is higher '2. User number is lower '3. User number is the same; congrats! 'This is code that we will use by the end of the next Unit (Unit 4); try to follow along, but again, 'Don't worry too much if you do not understand all of it right now If (intInput > intRandomNumber) Then MessageBox .Show( "Your number is higher than the random number!" ) ElseIf (intInput < intRandomNumber) Then MessageBox .Show( "Your number is lower than the random number!" ) Else MessageBox .Show( "You chose the random number! Congrats!" ) End If End Sub End Class...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern