samandrew
asked on
text box data manipulation
Hi All
I have 2 txtboxs both have numbers in
eg txtBox1 = 200
txtBox2 = 50
I have the following code which on each relative txt change event the number entered is subtracted from txtBox1 firstly and then txtBox2 if txtBox1 is zero, however i cant seem to get this to only switch to txtBox2 when txtBox1 reads zero!! can someone have a look at my code and offer advice please.
Private Sub txtatherstoneactual_Change (Index As Integer)
If Not IsNumeric(txtatherstoneact ual(0).Tex t) Then Exit Sub
If txtjcstandardcoderemaining stock(1).T ext - CInt(txtatherstoneactual(0 ).Text) > 0 Then
txtjcstandardcoderemaining stock(1).T ext = txtjcstandardcoderemaining stock(1).T ext - CInt(txtatherstoneactual(0 ).Text)
Else
txtjcprecoderemainingstock (1).Text = txtjcprecoderemainingstock (1).Text - CInt(txtatherstoneactual(0 ).Text)
End If
End Sub
Private Sub txtchelmsfordactual_Change (Index As Integer)
If Not IsNumeric(txtchelmsfordact ual(0).Tex t) Then Exit Sub
If txtjcstandardcoderemaining stock(1).T ext - CInt(txtchelmsfordactual(0 ).Text) > 0 Then
txtjcstandardcoderemaining stock(1).T ext = txtjcstandardcoderemaining stock(1).T ext - CInt(txtchelmsfordactual(0 ).Text)
Else
txtjcprecoderemainingstock (1).Text = txtjcprecoderemainingstock (1).Text - CInt(txtchelmsfordactual(0 ).Text)
End If
End Sub
Private Sub txtdarlingtonactual_Change (Index As Integer)
If Not IsNumeric(txtdarlingtonact ual(0)) Then Exit Sub
If txtjcstandardcoderemaining stock(1).T ext - CInt(txtdarlingtonactual(0 )) > 0 Then
txtjcstandardcoderemaining stock(1).T ext = txtjcstandardcoderemaining stock(1).T ext - CInt(txtdarlingtonactual(0 ))
Else
txtjcprecoderemainingstock (1).Text = txtjcprecoderemainingstock (1).Text - CInt(txtchelmsfordactual(0 ).Text)
End If
End Sub
Many Thanks
Andy
I have 2 txtboxs both have numbers in
eg txtBox1 = 200
txtBox2 = 50
I have the following code which on each relative txt change event the number entered is subtracted from txtBox1 firstly and then txtBox2 if txtBox1 is zero, however i cant seem to get this to only switch to txtBox2 when txtBox1 reads zero!! can someone have a look at my code and offer advice please.
Private Sub txtatherstoneactual_Change
If Not IsNumeric(txtatherstoneact
If txtjcstandardcoderemaining
txtjcstandardcoderemaining
Else
txtjcprecoderemainingstock
End If
End Sub
Private Sub txtchelmsfordactual_Change
If Not IsNumeric(txtchelmsfordact
If txtjcstandardcoderemaining
txtjcstandardcoderemaining
Else
txtjcprecoderemainingstock
End If
End Sub
Private Sub txtdarlingtonactual_Change
If Not IsNumeric(txtdarlingtonact
If txtjcstandardcoderemaining
txtjcstandardcoderemaining
Else
txtjcprecoderemainingstock
End If
End Sub
Many Thanks
Andy
You don't seem to be using the index passed into the event anywhere. That might be relevant.
I have substituted the txtBox names into the Atherstone code block:
Private Sub txtBox3_Change(Index As Integer)
If Not IsNumeric(txtBox3(0).Text) Then Exit Sub
If txtBox1(1).Text - CInt(txtBox3(0).Text) > 0 Then
txtBox1(1).Text = txtBox1(1).Text - CInt(txtBox3(0).Text)
Else
txtBox2(1).Text = txtBox2(1).Text - CInt(txtBox3(0).Text)
End If
End Sub
This says that you subtract from txtBox1(1) (txtJCStandardCodeRemainin gStock) unless that would take the value in that box below zero, in which case subtract from txtBox2 (precode).
That could match the description of your rquirement, but since you say you want somthing else, perhaps you mean that you want to subtract from box1 until it is zero, then start taking from box2, leaving 0 in box 1
Private Sub txtBox3_Change(Index As Integer)
If Not IsNumeric(txtBox3(0).Text) Then Exit Sub
txtBox1(1).Text = txtBox1(1).Text - CInt(txtBox3(0).Text)
If txtBox1(1).Text < 0 Then
txtBox2(1).Text = txtBox2(1).Text + txtBox1(1).Text
txtBox1(1).Text = 0
End If
End Sub
Private Sub txtBox3_Change(Index As Integer)
If Not IsNumeric(txtBox3(0).Text)
If txtBox1(1).Text - CInt(txtBox3(0).Text) > 0 Then
txtBox1(1).Text = txtBox1(1).Text - CInt(txtBox3(0).Text)
Else
txtBox2(1).Text = txtBox2(1).Text - CInt(txtBox3(0).Text)
End If
End Sub
This says that you subtract from txtBox1(1) (txtJCStandardCodeRemainin
That could match the description of your rquirement, but since you say you want somthing else, perhaps you mean that you want to subtract from box1 until it is zero, then start taking from box2, leaving 0 in box 1
Private Sub txtBox3_Change(Index As Integer)
If Not IsNumeric(txtBox3(0).Text)
txtBox1(1).Text = txtBox1(1).Text - CInt(txtBox3(0).Text)
If txtBox1(1).Text < 0 Then
txtBox2(1).Text = txtBox2(1).Text + txtBox1(1).Text
txtBox1(1).Text = 0
End If
End Sub
ASKER
Hi Graham
Yes I understand the long txtbox names is a bit of an issue I will try to tidy these up but as there is a lot of code for me I name them something I will recognize. The second code is exactly what I was looking for although this does return 0 in txtBox1..............txtBo x2 shows a number then a minus sign then another number?
Many Thanks
Andy
Yes I understand the long txtbox names is a bit of an issue I will try to tidy these up but as there is a lot of code for me I name them something I will recognize. The second code is exactly what I was looking for although this does return 0 in txtBox1..............txtBo
Many Thanks
Andy
Not too much code, Andy. They are controls, so you only need to change them in the properties Window. However there are rather a lot of them, even for that.
The display in txtBox2 is wrong because VB is interpreting the + sign as a string concatenation operator. The & was not in the the original versions (VB1 and VB2), so the + had to do both jobs, depending on context. It still does. Forcing one of the operands to a numeric value will make it act as an addition sign.
If Not IsNumeric(txtBox3(0).Text) Then Exit Sub
txtBox1(1).Text = txtBox1(1).Text - CInt(txtBox3(0).Text)
If txtBox1(1).Text < 0 Then
txtBox2(1).Text = Val(txtBox2(1).Text) + txtBox1(1).Text
txtBox1(1).Text = 0
End If
The display in txtBox2 is wrong because VB is interpreting the + sign as a string concatenation operator. The & was not in the the original versions (VB1 and VB2), so the + had to do both jobs, depending on context. It still does. Forcing one of the operands to a numeric value will make it act as an addition sign.
If Not IsNumeric(txtBox3(0).Text)
txtBox1(1).Text = txtBox1(1).Text - CInt(txtBox3(0).Text)
If txtBox1(1).Text < 0 Then
txtBox2(1).Text = Val(txtBox2(1).Text) + txtBox1(1).Text
txtBox1(1).Text = 0
End If
ASKER
Hi Graham
This works great now except I need to figure out a error code incase my second text txtBox2(1).Text
is less than txtBox3(0) Total.
Many Thanks
Andy
This works great now except I need to figure out a error code incase my second text txtBox2(1).Text
is less than txtBox3(0) Total.
Many Thanks
Andy
Can you do that, or are you having a problem?
ASKER
Hi Graham
Its not that i am lazy or do not want to try to do it, my problem is time at the moment 2 kids under 2 (both unwell) and building up a new business. Any ideas would be gratefully accepted.
Thanks
Andy
Its not that i am lazy or do not want to try to do it, my problem is time at the moment 2 kids under 2 (both unwell) and building up a new business. Any ideas would be gratefully accepted.
Thanks
Andy
Hope the kids aren't too ill, though even minor illnesses can be disruptive.
The problem is that some things take longer to explain to others than to do yourself. Also, the more that you do, the more you learn. However, see how this fits.
If Not IsNumeric(txtBox3(0).Text) Then Exit Sub
txtBox1(1).Text = txtBox1(1).Text - CInt(txtBox3(0).Text)
If txtBox1(1).Text < 0 Then
IF Val(txtBox2(1).Text) + txtBox1(1).Text < 0 tHEN
MsgBox "Insufficient stock"
txtBox2(1).Text = Val(txtBox2(1).Text) + txtBox1(1).Text
txtBox1(1).Text = 0
End If
The problem is that some things take longer to explain to others than to do yourself. Also, the more that you do, the more you learn. However, see how this fits.
If Not IsNumeric(txtBox3(0).Text)
txtBox1(1).Text = txtBox1(1).Text - CInt(txtBox3(0).Text)
If txtBox1(1).Text < 0 Then
IF Val(txtBox2(1).Text) + txtBox1(1).Text < 0 tHEN
MsgBox "Insufficient stock"
txtBox2(1).Text = Val(txtBox2(1).Text) + txtBox1(1).Text
txtBox1(1).Text = 0
End If
ASKER
Hi Graham
Am still at work but will try this when I get home tonight (kids permitting) Probaly not the right etiqute to ask but do you know much about database connections? as I have been on with question one for a long time. https://www.experts-exchange.com/questions/22980767/Saving-to-Database-with-Open-Connection.html
Many Thanks
Andy
Am still at work but will try this when I get home tonight (kids permitting) Probaly not the right etiqute to ask but do you know much about database connections? as I have been on with question one for a long time. https://www.experts-exchange.com/questions/22980767/Saving-to-Database-with-Open-Connection.html
Many Thanks
Andy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Graham
Many Thanks for your help have finally got round to doing some more work on my program.
Andy
Many Thanks for your help have finally got round to doing some more work on my program.
Andy
ASKER
Very helpful
I don't know about you, but I'm beginning to feel a bit tired. However, you could help us to help you by making your very long control names a bit more readable by capitilising the first letter of the embedded words.
Also you try to explain the problem with short names, but the code you use has different names, so we have to take some time to sort out which actual control matches which explanatory name.
I'll carry on looking at it now.