No of visitors who read this post: 284
Category: Visual basic
Type: Question
Author: BubAngus5
Your rating: None Average: 5 (1 vote)

How to write a program that will ask the user to enter a number then the program will determine if the number is positive or negative then also determine if the number is in ones, tens, hundreds, thousands or millions place. Also a label control can be used instead of message box.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

#

Just proceed to the Code editor Window or you have to double click the control concerned to design your program code. The following codes will be used…

code and design.png

-----------------------------------------enter button------------------ 

 Private Sub Command1_Click()

Dim x As Double

If CInt(Text1.Text) < 0 Then                    'check if + or -

    Label2.Caption = "Number is Negative..."

Else

    Label2.Caption = "Number is Positive..."

End If

x = Len(Text1.Text)                             'count nos.

If CInt(Text1.Text) < 0 Then x = x - 1          'remove negative

If x = 1 Then

    Label3.Caption = "Number is in ONES..."

ElseIf x = 2 Then

    Label3.Caption = "Number is in TENS..."

ElseIf x = 3 Then

    Label3.Caption = "Number is in HUNDREDS..."

ElseIf x = 4 Then

    Label3.Caption = "Number is in THOUSAND..."

ElseIf x = 5 Then

    Label3.Caption = "Number is in MILLIONS..."

'add more if you want

End If

End Sub

-----------------------------------------clear button------------------ 

Private Sub Command2_Click()

Text1.Text = ""

Label2.Caption = ""

Label3.Caption = ""

End Sub

-----------------------------------------exit button------------------

Private Sub Command3_Click()

End

End Sub

-----------------------------------------

I have included an attachment photo which you can view as your reference. Th picture is the actual coding I used...