Results 1 to 13 of 13

Thread: Still Lurking at TextBox calculations Problem... Plz Help:(

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Still Lurking at TextBox calculations Problem... Plz Help:(

    Dear mentors,

    This should happen only once when i add something in texbox. But it pluses again values of textbox1.text + textbox2 when i modify a record.

    VB Code:
    1. Private Sub textbox2_KeyPress(KeyAscii As Integer)  
    2.            If keyascii = 13 then  
    3.                    textbox3= val(textbox1.text) + val (textbox2.text)  
    4.             End IF
    5. End IF


    I want: the Result remain stable, if i add something in textbox1 it add in Result and when i delete any value which is already in textbox 1 or 2 it effects on result during modification.

    plz help rapid..
    thanx inadvance
    Last edited by Plucky; Dec 26th, 2005 at 07:53 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    hi folks, it is a second day, but still i'm waiting for response from any one who could be enough kind...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    Lets take it this way.. if you are not understanding what i wanted to ask you...


    I have 3 texboxes on my form. What I want I tell you in detail.

    When I reached on text2.text after entering any value in it I press Enter,
    If keyascii = 13 then
    Txtresult.text = val(text1.text) + val(text2.text)
    Endif

    This code added value 1 in to value 2 and results shows in txtresult.text. Well it is working, but when I again come on text2.text and without any change in value I only press Enter Key (keyascii = 13) same value which is already in text2.text again added in txtresult.text. This addition go on and on each time when I press enter key in text2.text.

    I wish it should only add that value which I change or write in text2.text instead of by pressing Enter Key it added same value into the result again. This is problem, please help me to solve it.

  4. #4
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    Plucky:

    Well, it is the Christmas Holiday weekend and so there are not a lot of people hanging out in the forum.

    Private Sub textbox2_KeyPress(KeyAscii As Integer)
    If keyascii = 13 then
    textbox3= val(textbox1.text) + val (textbox2.text)
    End IF
    End IF
    To start with you need to change the last End If to End Sub.

    Also in your third posting you say "txtresult.text, but that is not in your code?

    Did you change textbox3.text to txtresult.text?

    It seems to work when I try it.

    I put 50 in textbox1 and 25 in textbox2 and when I press enter I get 75 in textbox 3. If I go back and delete 50 from textbox 1 and enter 100 in textbox 1 then when I put the cursor in textbox2 and press enter I get 125 in textbox3.

    You must have some other code that you have not posted that is effecting it.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    Mr. AIS4U
    Thanx for your response, but as you told me that you try it on your screen. I also tried it like you did, it is working fine. But i'm saving data in MS Access Database.
    I think you did'nt try it, please just press Enter key (keyascii=13) in text box 2 or 1 and look at the result. on key press event it simply added the same value which is already in textbox 1 or 2 into the result.
    It was my typing mistake, i have textbox3.text instead of textresult.text..
    help, plz

  6. #6
    Hyperactive Member
    Join Date
    May 2005
    Posts
    278

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    Quote Originally Posted by Plucky
    Mr. AIS4U
    Thanx for your response, but as you told me that you try it on your screen. I also tried it like you did, it is working fine. But i'm saving data in MS Access Database.
    I think you did'nt try it, please just press Enter key (keyascii=13) in text box 2 or 1 and look at the result. on key press event it simply added the same value which is already in textbox 1 or 2 into the result.
    It was my typing mistake, i have textbox3.text instead of textresult.text..
    help, plz
    why dont you setting some flag to skip after first attempt. means,
    try this

    If flag = 0 Then
    If KeyAscii = 13 Then
    Text3.Text = Val(Text1.Text) + Val(Text2.Text)
    End If
    flag = 1
    End If

    here flag is a simple variable and declare it in general and each text change(text1 and text2) event change the value of flag=0
    Last edited by sajankk; Dec 27th, 2005 at 12:25 AM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    Mr. sajankk
    Thanx for help, but this flag is working in between only 2 textboxes like i wrote under:
    If flag = 0 Then
    If KeyAscii = 13 Then
    Text3.Text = Val(Text1.Text) + Val(Text2.Text)
    End If
    flag = 1
    End If
    -------------------------
    Not working like this:

    If flag = 0 Then
    If KeyAscii = 13 Then
    Text3.Text = Val(Text1.Text) + Val(Text2.Text)
    Text3.Text = val(Text3.Text) + val(text2.text)
    Text7.Text = val(Text7.Text) - val(Text8.text)
    End If
    flag = 1
    End If

    ------------
    Plz help

  8. #8
    Hyperactive Member
    Join Date
    May 2005
    Posts
    278

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    when u want to do the calculation. keypress event of text2 or what ?

    saj

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    Mr. Sajankk
    Yes, i want calculation on text2.text keypress even.

  10. #10
    Hyperactive Member
    Join Date
    May 2005
    Posts
    278

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    Quote Originally Posted by Plucky
    Mr. Sajankk
    Yes, i want calculation on text2.text keypress even.
    what is not working there. can u brief

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    ok, Mr. Sajan
    It is not working on more than 2 or 3 calculation at same time.
    When i change value in Text1.Text it effects only once in single additoin which is like this, detail is under with my orignal textbox names:
    -----------------
    Private Sub txtgypconop1_KeyPress(KeyAscii As Integer)

    If flag = 0 Then
    If KeyAscii = 13 Then
    cemprodop1 = Val(txtckconop1) + Val(txtgypconop1.Text)
    cemprodop1.Text = Val(txtckconop1.Text) + Val(txtgypconop1.Text)
    txtcemstockop.Text = Val(txtckconop1.Text) + Val(txtgypconop1.Text)
    txtmtdcemprodop1.Text = Val(txtckconop1.Text) + Val(txtgypconop1.Text)
    ytdcemprodop1.Text = Val(txtckconop1.Text) + Val(txtgypconop1.Text)

    End If
    flag = 1
    ckconsr.SetFocus
    End If
    ===============
    Help, me.. plz

  12. #12
    Hyperactive Member
    Join Date
    May 2005
    Posts
    278

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    its working nice with me i feel,

    did u changed the flag=0, in the textchange even of these 2 text boxes,
    txtckconop1.Text
    txtgypconop1.Text



    saj

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    102

    Re: Still Lurking at TextBox calculations Problem... Plz Help:(

    Mr. Sajankk
    You are right it is working between
    txtckstockop.text = val(txtckconop1.text) + val(txtgypconop1.text)
    but not working as

    cemprodop1 = Val(txtckconop1) + Val(txtgypconop1.Text)
    cemprodop1.Text = Val(txtckconop1.Text) + Val(txtgypconop1.Text)
    txtcemstockop.Text = Val(txtckconop1.Text) + Val(txtgypconop1.Text)
    txtmtdcemprodop1.Text = Val(txtckconop1.Text) + Val(txtgypconop1.Text)
    ytdcemprodop1.Text = Val(txtckconop1.Text) + Val(txtgypconop1.Text)

    help help help help help help help help help help help help help help help help help

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