If, ElseIF and Else operators in VB

How to make a computer to vary its responses depending on different users. Still a simple code but it is more and more interesting.Console.WriteLine("Good morning!")


       Console.ReadLine()
       Console.WriteLine("What is your name?")
       Dim userName As String = Console.ReadLine()

       Console.WriteLine("How are you today, " & userName & "?")
       Console.ReadLine()
       If userName = "Jola" Then
           Console.WriteLine("Please enter your password, Jola")
           Console.ReadLine()
       ElseIf userName = "Ignacy" Then
           Console.WriteLine("Welcome Ignacy.")
       Else
           Console.WriteLine("Pleased to meet you, " & userName & "!")
           Console.ReadLine()
       End If
       Console.ReadLine()

Very basic calculator

     For the time being it can only do one operation – here it multiplies two numbers.

    Console.WriteLine("Please enter the first number")
     Dim num1 As Double = Console.ReadLine()
     Console.WriteLine("First number: " & num1)
     Console.WriteLine("Please enter the second number")

     Dim num2 As Double = Console.ReadLine()
     Console.WriteLine("Second number: " & num2)

     Console.WriteLine("The numbers multiplied is: " & num1 * num2)
     Console.ReadLine()

How to get an input from a potential user of our code

I did manage to do it workable, only – even thought that the second part of the sentences which should be written on the screen is red and there is no errors – I cannot see it on the computer screen. Well, I will work on it when I learn how to do it.

       Dim userName As String = Nothing
       Dim userBook As Integer = Nothing
       Dim userTime As Double = Nothing
       Console.WriteLine("What is your name?")
       userName = Console.ReadLine()
       Console.WriteLine("How many books do you read per month?")
       userBook = Console.ReadLine()
       Console.WriteLine("How much time a day do you spend chatting on skype?")
       userTime = Console.ReadLine()
       Console.Write("Your name is: " & userName)
       Console.Write(" You read: " & userBook &  " books per month.")
       Console.Write("  You spend: " & userTime & " hours chatting on skype daily.")
       Console.WriteLine()
       Console.ReadLine()

There is very easy trick to get the second part of a literal string visible, we have to repeat the sign 'AND', and that is all.

Simple code to talk with numbers

Numbers from 1 to 10 times 13 (x = a * 13) where a can be any number from 1 to 10. In fact this kind of numbers are called integers (like: –9, 4, 9). Do not remember if 0 is an integer but probably yes, and the whole numbers are all number with are not 0 and not minus. Other numbers are called decimals or fractions.

There is a commend : Double in VB but not sure for what yet.

Module Module1
 
    Sub Main()

For index = 1 To 10
           Console.WriteLine(index * 13)
       Next
       Console.ReadLine()

End Sub

End Module

A few new words used in programing:

  1. concatenate
  2. operand
  3. truncate

A little bit of programming - Hello World

I started to learn VB and Python at the same time, and found it difficult to remember codes and meanings. As I am learning by watching videos and trying to do the same in programs I decided to keep some knowledge online, instead of looking for a video or for a file with code. So here I will keep some first codes to remember  and repeat it.

My first code in which I learnt how to tell the application to show a string (opposite to valuables, meaning digits).

Module Module1

    Sub Main()
        Console.WriteLine("Hello World!")
        Console.ReadLine()
    End Sub

End Module

 

And a little bit of a conversation with a computer, maybe at some point I will learn how to give different answers, depending on using some key words like: nice, fine, wonderful or bad. Smile

 

Module Module1

    Sub Main()
        Console.WriteLine("Hello World!")
        Console.ReadLine()
        Console.WriteLine("How are you today?")
        Console.ReadLine()
        Console.WriteLine("Anyway, have a wonderful day!")
        Console.ReadLine()

    End Sub

End Module

About this blog


Pages

Powered by Blogger.

Popular Posts

About Me

Blogger templates

Blogroll

Blog Archive

Blogger templates

Blogger news