Results 1 to 9 of 9

Thread: If Then...help[resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Location
    Dallas, TX
    Posts
    70

    Arrow If Then...help[resolved]

    Ok, I want to add 12 to all numbers from 1 To 11 that added to the combobox.
    I can only do it one at a time like this....

    VB Code:
    1. If cboHours2.Text = 5 Then
    2.    Dim intNumber As Integer
    3.    MsgBox Val(cboHours2.Text) + 12
    4.    End If
    There has to be a way to do it with one If..Then Statement.

    please help

    Last edited by notSOMLS1; Jan 22nd, 2003 at 06:19 PM.

  2. #2
    Member
    Join Date
    Jan 2003
    Location
    Beer City
    Posts
    33
    hi

    you could try this:

    If cboHours2.Text <12 Then
    Dim intNumber As Integer
    MsgBox Val(cboHours2.Text) + 12
    End If

    i assume I am missing something though seems to easy

    tal mcmahon

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Can you rephrase the question? It's hard to understand what you are trying to do. Assume we know nothing about your project...
    ~seaweed

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Location
    Dallas, TX
    Posts
    70
    Originally posted by seaweed
    Can you rephrase the question? It's hard to understand what you are trying to do. Assume we know nothing about your project...
    heh, ok
    Lets say the user can enter in any number between 1 and 20.
    12 will be added to any number between 1 and 11. The numbers from 12 to 20 will have nothing added.
    So for example the user enters "7", the output will be 19.
    Or if 10 is entered, the output will be 22
    It seems like I should be able to write something like this....
    VB Code:
    1. If txtNumber.Text is 1 To 11 Then
    2. lblOutput.Caption = txtNumber.Text + 12
    3. End If
    But that code isn't right... So is there a way to do it without using < or > ??

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    VB Code:
    1. If txtNumber.Text is < 12 Then
    2.     lblOutput.Caption = txtNumber.Text + 12
    3. End If
    ~seaweed

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Oh...didn't see your restriction on "<". Try this instead:
    VB Code:
    1. If txtNumber.Text \ 12 = 0 Then
    2.     lblOutput.Caption = txtNumber.Text + 12
    3. End If
    ~seaweed

  7. #7
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    VB Code:
    1. If txtNumber.Text \ 12 = 0 Then
    2.     lblOutput.Caption = txtNumber.Text + 12
    3. End If
    Would the above work as he wanted it to? It looks to me that
    this code would only add 12 if txtNumber \ 12 = 0 and he wants
    all numbers 1 through 11 right?

    If I am wrong so be it, but I can't think of a way to do it without the > operator. I bet there is a more detailed way but can't think of it without having to use a ton of Or's and And's on that statement.

  8. #8
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Uhhh...

    It looks to me that this code would only add 12 if txtNumber \ 12 = 0 and he wants all numbers 1 through 11 right?
    You're right, it only adds 12 if number \ 12 = 0.

    This includes all numbers from 1 to 11. So, yes, it works just fine the way he wants it to! (Notice that it is not a normal division /, but integer division \).
    ~seaweed

  9. #9
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    Didnt notice the "/" was on here from linux last night before bed and the Linux mozilla browser makes my eyes hurt. Sry =)

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