VB.Net find output programs (Data Types) | set 2

Find the output of VB.Net programs | Data Types | Set 2: Practice these programs to test and enhance the knowledge of VB.Net Data Types.
Submitted by Nidhi, on June 15, 2022

Question 1:

Module VBModule
 
    Sub Main()
        dim num1,num2 as integer=10,20
        
        Console.WriteLine("Num1: {0}",num1)
        Console.WriteLine("Num2: {0}",num2)
    End Sub
    
End Module

Output:

main.vb (4,39) : error VBNC30203: Identifier expected.

main.vb (6,16) : error VBNC90019: Expected 'End'.

main.vb (7,16) : error VBNC90019: Expected 'End'.

main.vb (8,12) : error VBNC30203: Identifier expected.

main.vb (10,11) : error VBNC30203: Identifier expected.

There were 5 errors and 0 warnings.

Explanation:

The above program will generate syntax errors, because of the below declarative statement,

    dim num1,num2 as integer=10,20

The correct program is given below,

Module VBModule
    Sub Main()
        dim num1 as integer=10, num2 as integer=20
        
        Console.WriteLine("Num1: {0}",num1)
        Console.WriteLine("Num2: {0}",num2)
    End Sub
End Module

Question 2:

Module VBModule
 
    Sub Main()
        dim num1 as integer=10, dim num2 as integer=20
        
        Console.WriteLine("Num1: {0}",num1)
        Console.WriteLine("Num2: {0}",num2)
    End Sub
    
End Module

Output:

main.vb (4,36) : error VBNC30203: Identifier expected.

main.vb (6,16) : error VBNC90019: Expected 'End'.

main.vb (7,16) : error VBNC90019: Expected 'End'.

main.vb (8,12) : error VBNC30203: Identifier expected.

main.vb (10,11) : error VBNC30203: Identifier expected.

There were 5 errors and 0 warnings.

Explanation:

The above program will generate syntax errors, because of the below declarative statement,

dim num1 as integer=10, dim num2 as integer=20

The correct program is given below,

Module VBModule
    Sub Main()
        dim num1 as integer=10, num2 as integer=20
        
        Console.WriteLine("Num1: {0}",num1)
        Console.WriteLine("Num2: {0}",num2)
    End Sub
End Module

Question 3:

Module VBModule
 
    Sub Main()
        dim num1 as Float=10.23
        dim num2 as Double=20.34
        
        Console.WriteLine("Num1: {0}",num1)
        Console.WriteLine("Num2: {0}",num2)
    End Sub
    
End Module

Output:

main.vb (4,26) : error VBNC30451: 'Float' is not declared. It may be inaccessible due to its protection level.

There were 1 errors and 0 warnings.

Explanation:

The above program will generate a syntax error. Because we cannot use the "Float" type in VB.Net. Here, we need to use the type "Single" to declare a floating-point variable.


Question 4:

Module VBModule
 
    Sub Main()
        dim num1 as Single=10.23
        dim num2 as Double=20.34
        
        Console.WriteLine("Length of Num1: {0}",len(num1))
        Console.WriteLine("Length of Num2: {0}",len(num2))
    End Sub
    
End Module

Output:

Length of Num1: 4
Length of Num2: 8

Explanation:

In the above program, we created variables num1 and num2. Then we get the length of variables using the len() method and printed the result.


Question 5:

Module VBModule
 
    Sub Main()
        dim num1 as SByte=-10
        dim num2 as UShort=20
        
        Console.WriteLine("Num1: {0}",num1)
        Console.WriteLine("Num2: {0}",num2)
    End Sub
    
End Module

Output:

Num1: -10
Num2: 20

Explanation:

In the above program, we created a variable num1 of type Signed Byte and variable num2 of type Unsigned short. After that, we printed both variables.





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.