ADVERTISEMENT
ADVERTISEMENT

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

Find the output of VB.Net programs | Data Types | Set 3: 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 as SDouble=-10.34
        dim num2 as UShort=20
        
        Console.WriteLine("Num1: {0}",num1)
        Console.WriteLine("Num2: {0}",num2)
    End Sub
    
End Module

Output:

main.vb (4,28) : error VBNC30451: 'SDouble' 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 there is no SDouble data type in VB.NET.


Question 2:

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

Output:

Unhandled Exception:
System.OverflowException: Arithmetic operation resulted in an overflow.

Explanation:

The above program will generate an exception, here we tried to initialize variable num2 with 128, which will create an overflow exception because we can store a value between -128 to 127 in a Signed Byte variable.


Question 3:

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

Output:

Unhandled Exception:
System.OverflowException: Arithmetic operation resulted in an overflow.

Explanation:

The above program will generate an exception, here we tried to initialize variable num2 with 128, which will create an overflow exception because we can store values between -128 to 127 in a Signed Byte variable.


Question 4:

Module VBModule
 
    Sub Main()
        Console.WriteLine("Size of Double: {0}",len(Double))
        Console.WriteLine("Size of Single: {0}",len(Single))
    End Sub
    
End Module

Output:

main.vb (4,59) : error VBNC99999: <no message written yet>

/home/cg/root/62a5b665d3a94/main.vb (5,59) : error VBNC99999: <no message written yet>

There were 2 errors and 0 warnings.

Explanation:

The above program will generate syntax errors because we cannot get the size of the datatype using the len() method.


Question 5:

Module VBModule
 
    Sub Main()
        dim num1 as Single = 10.23
        dim num2 as Double = 10.45
        dim num3 as UShort =  25
        
        dim res as Double =  0.0
        
        res = (len(num1) * len(num2))/len(num3)
        
        Console.WriteLine("Result: {0}",res)
        
    End Sub
    
End Module

Output:

Result: 16

Explanation:

In the above program, we created 3 variables. Then we used the len() function to get the length of the variables.

Now we evaluate the expression:

res = (len(num1) * len(num2))/len(num3)
res  = (4 * 8)/2
res = 32/2
res = 16


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.