Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, August 10, 2011

VB-95 : The number of digits in the entered Number

Enter a Number.The output will say the number of digits in the number.

Refer the same type of more complicatedprograms from  these four :
Number of characters in a given string , 
Total words,Characters,sentence,length of ...,
Occurrence of a String 
Count Blanks,Tabs,etc in a String   etc.


(A)Program Design : 


(B) Property(Controls Used) :
  • 2 Labels with Caption Enter a Number and You entered.
  • One More Label with Name Label3 and with No Caption (For your understanding , I am put the caption here as Label3)
  • One Command Button with Name-Command1 and Caption - Print
(If we remove the Caption from Label3 , the form should look like as given below :)


(C) Attaching Code to the Object :



Private Sub Command1_Click()
Dim n As Integer
n = Val(Text1.Text)
If n < 10 Then
Label3.Caption = "a One Digit Number"
ElseIf n < 100 Then
Label3.Caption = "a Two Digit Number"
ElseIf n < 1000 Then
Label3.Caption = "a Three Digit Number"
ElseIf n < 10000 Then
Label3.Caption = "a Four Digit Number"
ElseIf n < 100000 Then
Label3.Caption = "a Five Digit Number"
Else
Label3.Caption = "A Number with more than Five Digit"
End If
End Sub



(D) Output :

====================================================================

Assignment :


Here, I used 3 labels , and 3 Text Boxes and One Command Button (Print). Text Boxes are used to display the entered number and the number of digits.

The output of the screen is :



Do it yourself............

or, see the comment section for the answer.

      • ====================================================================
        Back to Home   &  VB
    ===========================================================

    1 comment:

    Priyada Mohanan said...

    Answer of the Assignment is :
    ==========================================
    Private Sub Command1_Click()
    Text2.Text = Text1.Text
    Dim n As Integer
    n = Val(Text1.Text)
    If n < 10 Then
    Text3.Text = "One"
    ElseIf n < 100 Then
    Text3.Text = "Two"
    ElseIf n < 1000 Then
    Text3.Text = "Three"
    ElseIf n < 10000 Then
    Text3.Text = "Four"
    ElseIf n < 100000 Then
    Text3.Text = "Five"
    Else
    Text3.Text = "More than five"
    End If
    End Sub