Results 1 to 9 of 9

Thread: [RESOLVED] Help making condition

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    33

    Resolved [RESOLVED] Help making condition

    lets have this example

    record 1
    qty:1

    record 2
    qty:1

    total of all record is 2
    total to be compared is 4

    lets say he/she wants to edit record 2,user then input the desired number in a textbox(txtquantity.text)

    how should i limit the user so that the quantity he can enter txtquantity.text is from 3 to 1 only

    because total to be compared is only 4

    update should then look like this

    record 1
    qty:1

    record 2
    qty:3 ( if user entered 3 ) but if user enters 4 in txtquantity.text it will flag an error

    total of all record is 4
    total to be compared 4

    hope i made it clear

  2. #2
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Help making condition

    Here's something to start with. Right click the variables starting with "vb" then Click "Definition" for more info. The object browser if your friend.

    vb Code:
    1. Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    2.     On Error GoTo EH
    3.     Dim szText As String
    4.    
    5.     If ((KeyCode = vbKeyBack) Or (KeyCode = vbKeyDelete)) Then
    6.         ' Backspace And Delete keys are OK
    7.     ElseIf ((KeyCode >= vbKey0) And (KeyCode <= vbKey9)) Then
    8.         szText = Text1.Text
    9.         If (CInt(szText) > 3) Then
    10.             szText = "3"
    11.             Call Beep
    12.         ElseIf (CInt(szText) < 1) Then
    13.             szText = "1"
    14.             Call Beep
    15.         End If
    16.         Text1.Text = szText
    17.         Text1.SelStart = Len(Text1.Text) + 1
    18.     Else
    19.         Call Beep
    20.     End If
    21.     Exit Sub
    22.    
    23. EH: Call Err.Clear
    24.     Call Beep
    25.     Text1.Text = "1"
    26. End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    33

    Re: Help making condition

    will this work if both qty in records are not specified?

  4. #4
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Help making condition

    Wut? Did you try the code?

    All it does it limit the value in the TextBox from 1 to 3. I dont know what records you're using. You decide how you want to handle the max quantity and how you read the records.

    Quote Originally Posted by enjoyincubus
    how should i limit the user so that the quantity he can enter txtquantity.text is from 3 to 1 only

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    33

    Re: Help making condition

    if the records were used in the database(MsAccess)

    total to be compared also changes

    you wouldnt exactly know the specific quantity of each record, i can only traverse the records
    Last edited by enjoyincubus; Sep 10th, 2009 at 12:08 PM.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Help making condition

    Xiphias - that's a classic example of giving someone what they asked for, but not what they needed....


    in order to perform the necessary logic, you need a few things...
    the current total of all records (2)
    the current total of the current record (1)
    the current allowable total (4)
    the user input new total (3).


    the logic is like this:
    if the current allowable total (4) minus the current total of all records (2) plus the total of the current record (1) is equal to, or greater than the user input new total, then it is allowable.
    So reversing that
    if the current allowable total (4) minus the current total of all records (2) plus the total of the current record (1) is less than the user input new total, then notify the user it is too much.

    4 - 2 + 1 = 3 ... so, if the user enters 3, it's OK....
    If the user enters 4, then it is not OK.
    Now, let say the first record is 2, not one....
    if the current allowable total (4) minus the current total of all records (3) plus the total of the current record (1) is less than the user input new total, then notify the user it is too much.
    And the user enters 3.
    4 -3 + 1 = 2... since 2 is less than 3, the user will not be able to use 3.

    I hope this helps.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    33

    Re: Help making condition

    notice that if the 1st record is higher than the second the condition changes?

    and if the 2nd record is higher than the first it also changes?

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Help making condition

    no... it shouldn't....it should be the same no matter what...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    33

    Re: Help making condition

    COOL! thanks i think i got it, thanks for the reply guys, been really helpful

    i kinda suck at this so, thanks i again

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