Results 1 to 3 of 3

Thread: Simple Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Orlando, Fl
    Posts
    12

    Simple Problem

    Hey everyone, I know this is probably a simple answer but I am new to VB and this has me stumped. Here is the problem.

    You have 4 input Boxes come up. In each box a number is entered. Then the four numbers are compared, and then each number is assinged to a variable from least to greatest, and then a total is assigned to a fifth variable. Like this.

    numbers entered: 3,8,5,2

    Displayed in 5 labels
    A= 2
    B= 3
    C= 5
    D= 8

    E= 18

    Please Help!

    James

  2. #2
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    put four text boxes, one command button and five labels on the
    form. Paste this code
    int o the form code and thats it.

    Code:
    Private Sub Command1_Click()
    Dim A As Double ' declare our varibles
    Dim B As Double
    Dim C As Double
    Dim D As Double
    Dim E As Double
    Dim temp As Double ' a temp variable to hold values
    Dim i As Integer   ' the count for the for loop
    
    A = Text1.Text   ' assign text1.text to A
    B = Text2.Text
    C = Text3.Text
    D = Text4.Text
    E = A + B + C + D ' Add up A B C and too make E
    For i = 0 To 3 ' loop 4 times. so that if D is smaller than A goes thrue All the other variable and change place with a
    
        If A > B Then ' A need to be less than D so check and see if it is. If it's not change A to B And B to A
            temp = B
            B = A
    
            A = temp
        End If
        If B > C Then 'same as with A
            temp = C
            C = B
            B = temp
        End If
        If C > D Then ' Smae as with A
            temp = D
            D = C
            C = temp
        End If
    Next i
    Label1.Caption = A ' put the values int the lables
    Label2.Caption = B
    Label3.Caption = C
    Label4.Caption = D
    Label5.Caption = E
    
    End Sub
    Note i'm sleepy so the comments might not make sense.
    VB-World addict!

    All spelling errors are undocumented words!
    http://www.bells.f2s.com

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Orlando, Fl
    Posts
    12
    Thanks Bjwbell,


    James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width