Question:

VISUAL BASIC code for a math program for S,A,D,M

by  |  earlier

0 LIKES UnLike

I need help!! I need a program that has sub procedure that generates random numbers and nothing else. It needs to allow the user to select what he wants to do SE: Add, Divide,Multiply, Subtract and then display the numbers with the appropriate math symbol.It should also then call a funtion to calculate the correct answer and then the answer is assigned to a public variable. Also if other characters entered except A,M,D,S it should then display message to ask the user to re-enter. There should be no public variables except when used for the correct answer.

 Tags:

   Report

1 ANSWERS


  1. If this does not help you email me.

    You can cut and paste this into the code pane.

    Dim Number4 As Single

    Private Sub Command1_Click()

    Dim MyValue1, MyValue2 As Single

    Dim NValue As Variant

    NValue = (Time) 'Constantly changing seed value for random number generation.

    Randomize [NValue]  ' Initialize random-number generator.

    MyValue1 = ((150 * Rnd) + 1)   ' Generate random value between 1 and 150.

    If MyValue1 > 100 Then

      Randomize [NValue]  ' Initialize random-number generator.

       MyValue1 = ((150 * Rnd) + 1)   ' Generate random negative value between 1 and 150.

        MyValue1 = MyValue1 * -1

    End If

    If Check1.Value = 1 Then MyValue1 = Fix(MyValue1)

    Label1.Caption = MyValue1

    Randomize [NValue]  ' Initialize random-number generator.

    MyValue2 = ((150 * Rnd) + 1)   ' Generate random value between 1 and 150.

    If MyValue2 > 100 Then

      Randomize [NValue]  ' Initialize random-number generator.

       MyValue2 = ((150 * Rnd) + 1)   ' Generate random negative value between 1 and 150.

        MyValue2 = MyValue2 * -1

    End If

    If Check2.Value = 1 Then MyValue2 = Fix(MyValue2)

    Label2.Caption = MyValue2

    End Sub

    '''Add

    Private Sub Command2_Click()

    Text3.Text = "+"

    Text1.Text = Label1.Caption

    Text2.Text = Label2.Caption

    End Sub

    '''Subtract

    Private Sub Command3_Click()

    Text3.Text = "-"

    Text1.Text = Label1.Caption

    Text2.Text = Label2.Caption

    End Sub

    '''Multiply

    Private Sub Command4_Click()

    Text3.Text = "x"

    Text1.Text = Label1.Caption

    Text2.Text = Label2.Caption

    End Sub

    '''Divide

    Private Sub Command5_Click()

    Text3.Text = "/"

    Text1.Text = Label1.Caption

    Text2.Text = Label2.Caption

    End Sub

    '''Reset

    Private Sub Command6_Click()

    Label1.Caption = ""

    Label2.Caption = ""

    Text1.Text = ""

    Text2.Text = ""

    Text4.Text = ""

    Text3.Text = ""

    Check1.Value = 0

    Check2.Value = 0

    Option1.Value = False

    End Sub

    '''Swap Values

    Private Sub Command7_Click()

    Dim MyNumber1, MyNumber2, MyNumber3, MyNumber4 As Variant

    If Option1.Value = True Then

    MyNumber1 = Label1.Caption

    MyNumber2 = Label2.Caption

    MyNumber3 = MyNumber1

    MyNumber4 = MyNumber2

    Label1.Caption = MyNumber4

    Label2.Caption = MyNumber3

    Option1.Value = False

    End If

    If Option1.Value = False Then

    MyNumber1 = Label1.Caption

    MyNumber2 = Label2.Caption

    Label1.Caption = MyNumber1

    Label2.Caption = MyNumber2

    End If

    End Sub

    '''Calculate

    Private Sub Command8_Click()

    Dim MyNumber1, MyNumber2 As Variant

    MyNumber1 = CDec(Label1.Caption)

    MyNumber2 = CDec(Label2.Caption)

    If Text3.Text = "+" Then Text4.Text = MyNumber1 + MyNumber2

    If Text3.Text = "-" Then Text4.Text = MyNumber1 - MyNumber2

    If Text3.Text = "x" Then Text4.Text = MyNumber1 * MyNumber2

    If Text3.Text = "/" Then Text4.Text = MyNumber1 / MyNumber2

    Number4 = CDec(Text4.Text)

    End Sub

    : )

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.