|
-
Sep 10th, 2009, 09:55 AM
#1
Thread Starter
Member
[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
-
Sep 10th, 2009, 10:16 AM
#2
Addicted Member
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:
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) On Error GoTo EH Dim szText As String If ((KeyCode = vbKeyBack) Or (KeyCode = vbKeyDelete)) Then ' Backspace And Delete keys are OK ElseIf ((KeyCode >= vbKey0) And (KeyCode <= vbKey9)) Then szText = Text1.Text If (CInt(szText) > 3) Then szText = "3" Call Beep ElseIf (CInt(szText) < 1) Then szText = "1" Call Beep End If Text1.Text = szText Text1.SelStart = Len(Text1.Text) + 1 Else Call Beep End If Exit Sub EH: Call Err.Clear Call Beep Text1.Text = "1" End Sub
-
Sep 10th, 2009, 10:24 AM
#3
Thread Starter
Member
Re: Help making condition
will this work if both qty in records are not specified?
-
Sep 10th, 2009, 10:33 AM
#4
Addicted Member
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.
 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
-
Sep 10th, 2009, 11:56 AM
#5
Thread Starter
Member
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.
-
Sep 10th, 2009, 12:07 PM
#6
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
-
Sep 10th, 2009, 12:39 PM
#7
Thread Starter
Member
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?
-
Sep 10th, 2009, 01:15 PM
#8
Re: Help making condition
no... it shouldn't....it should be the same no matter what...
-tg
-
Sep 10th, 2009, 09:01 PM
#9
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|