Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 32

Thread: If Statements With Mutiple Inputs And Multiple Outputs

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location

    If Statements With Mutiple Inputs And Multiple Outputs

    Hey guys, was wondering if anyone could help me out with this quick program I need to write. I am trying to input 3 different values at 3 different textboxs in a form. Depending on what values are inputed in, a certain statment should show up in another text box. I also have a calculate button which is the command to this code. It is not working and I am not sure why. Here is the code. Any help would be much much appreciated. Thanks a lot.
    Last edited by zizou; 06-30-2008 at 01:11 PM.

  2. #2
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    [VBA]Private Sub Command1_Click()
    Dim text1 As Double
    Dim text2 As Double
    Dim text3 As Double
    Dim text4 As TextBox
    text1 = z
    text2 = y
    text3 = z
    text4 = a
    If x > 10001 And y < 4.99 And z < 4.99 Then a = CABIN
    If x > 10001 And y < 4.99 And z > 4.99 Then a = BOX
    If x < 10001 And y > 4.99 And z > 4.99 Then a = HORIZONTAL
    If x < 10001 And y < 4.99 And z < 4.99 Then a = VERTICAL


    End Sub[/VBA]

  3. #3
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Questions that I have:
    1- Is this VB or is this VBA? (Command1_Click is VB, CommandButton1_Click is VBA)
    2- Is text1 really a textbox on the form?
    3- Where are x,y,z defined?
    4- Is text1 and text3 supposed to = z?

    My understanding of your problem is you have 3 textboxes on a form and according to the input of these 3 textboxes you want something to show up in textbox4 Right?

    My assumptions:
    text1, text2, text3, and text4 are really names of textboxes.
    [vba]
    Private Sub Command1_Click()
    Dim x As Double
    Dim y As Double
    Dim z As Double
    Dim a As String
    'set values
    x = Val(text1.Text)
    y = Val(text2.Text)
    z = Val(text3.Text)
    'check values to define the output of a
    If x > 10001 And y < 4.99 And z < 4.99 Then a = CABIN
    If x > 10001 And y < 4.99 And z > 4.99 Then a = BOX
    If x < 10001 And y > 4.99 And z > 4.99 Then a = HORIZONTAL
    If x < 10001 And y < 4.99 And z < 4.99 Then a = Vertical
    text4.Text = a
    End Sub
    [/vba]

  4. #4
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    Tommy, thanks for the reply
    1-This is VB
    2- text1 is a textbox on the form
    3- x,y and z are just defined as variables
    4- No text3 is what i put equal to z

    From the certain numbers put into the text1,text2,text3. I wanted to have an output (text4) to show one of those four selections (BOX, CABIN, HORIZONTAL, VERTICAL)

    I put your code in and it didnt work. Does that help?
    Thanks a whole lot.

  5. #5
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    Your assumptions were right. I was just trying to define the textboxes as x, y, and z to be neater. Nothing is showing up in textbox4 though.

  6. #6
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Look in the properties of the form for the actual name of each textbox and place it over text1. SO if the textbox name is TextBox1 then text1.text should read TextBox1.Text - etc...

  7. #7
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    Ya sorry about that. Didnt mean Textbox1. In properties it says Text1.

  8. #8
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Can you zip up the project and post it so I can actually see what is happening?

  9. #9
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    Tommy,
    Here you go. Sorry about the confusion.

  10. #10
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    It looks ok right now but I don't have VB with me so...

    What does it say when you click the button?

  11. #11
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Try this one. I think it is not checking for no matches.
    [VBA]
    Private Sub Command1_Click()
    Dim x As Double
    Dim y As Double
    Dim z As Double
    Dim a As String
    'set values
    x = Val(text1.Text)
    y = Val(text2.Text)
    z = Val(text3.Text)
    'check values to define the output of a
    If x > 10001 And y < 4.99 And z < 4.99 Then
    a = CABIN
    ElseIf x > 10001 And y < 4.99 And z > 4.99 Then
    a = BOX
    ElseIf x < 10001 And y > 4.99 And z > 4.99 Then
    a = HORIZONTAL
    ElseIf x < 10001 And y < 4.99 And z < 4.99 Then
    a = Vertical
    Else 'did not match any of the checks
    a = "I hate It when this happens!!"
    End If
    text4.Text = a
    End Sub
    [/VBA]

  12. #12
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    Tommy,
    It doesnt say anything. I click the button and nothing happens. It is just blank in the last textbox I have on the form, where the output should be.

  13. #13
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Bummer Like I said I hate it when that happens:

    New and improved

    [VBA]Private Sub Command1_Click()
    Dim x As Double
    Dim y As Double
    Dim z As Double
    Dim a As String
    'set values
    x = Val(Text1.Text)
    y = Val(Text2.Text)
    z = Val(Text3.Text)
    'check values to define the output of a
    If x > 10001 And y < 4.99 And z < 4.99 Then
    a = "CABIN"
    ElseIf x > 10001 And y < 4.99 And z > 4.99 Then
    a = "BOX"
    ElseIf x < 10001 And y > 4.99 And z > 4.99 Then
    a = "HORIZONTAL"
    ElseIf x < 10001 And y < 4.99 And z < 4.99 Then
    a = "Vertical"
    Else 'did not match any of the checks
    a = "I hate It when this happens!!"
    End If
    Text4.Text = a
    End Sub
    [/VBA]

  14. #14
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    Still doesn't work, but dont worry about it. I will try something else. Thanks though.

  15. #15
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    That was tested so I know it works.

    Are you getting anything? what does Still doesn't work mean? Does it mean you don't get anything in text4 or does it mean you don't see what you expected?

  16. #16
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    It means that nothing is showing up in text4. When I click on the calculate button nothing shows up, it is blank.

  17. #17
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Do you know how to set a break point and step through the code?

  18. #18
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    No I do not. What should I do.

  19. #19
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    In the code window place your cursor on this line

    [VBA]x = Val(Text1.Text) [/VBA]

    Press F9 it should be highlighted in brown, run the program and click the button, it should take you to the line that has "browned" out, hold you mouse cursor over any variable and it should display the valuse in that variable. press F8 to step through it. Let me know what happens

  20. #20
    VBAX Regular
    Joined
    Jun 2008
    Location
    tulsa, OK
    Posts
    24
    Location
    I hilighted the x=val(text1.text in brown, then ran the program, then clicked on the calculate button, then the brown line changed to yellow line then i pressed f8 and it hilighted these next lines in yellow in order
    x = Val(Text1.Text)
    y = Val(Text2.Text)
    z = Val(Text3.Text)
    If x > 10001 And y < 4.99 And z < 4.99 Then
    a = CABIN
    End If
    Text4.Text = a

Posting Permissions

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