Text_change the problem.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Text_change the problem.

  1. #1
    Join Date
    Sep 2013
    Posts
    6

    Text_change the problem.

    Hello Guys,
    There are 3 textboxes in form.


    -txtmiktar
    -txtbfiyat
    -txttutar

    Code:
    Private Sub txtmiktar_Change()
    
    txttutar = Val(txtmiktar * txtbfiyat)
    
    End Sub
    
    Private Sub txttutar_Change()
    
    txtmiktar = Val(txttutar / txtbfiyat)
    
    End Sub
    When i run like this, it happens infinite loop. I want that when i write sth to "txtmiktar", make passive the "txttutar"s change code. If i write a velue to "txttutar" i want "txtmiktar"s code got passive. If i write to keypress action, i got the "mismatch error".

    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,990

    Re: Text_change the problem.

    You could set a variable as a flag, and check for that.

    Code:
    Dim ValidChange as Boolean
    ValidChange = vbFalse
    I'll let you figure out the logic as where to place the check(s)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2013
    Posts
    6

    Re: Text_change the problem.

    By using the codes below,i am blocking the entering space and letter in to the textbox
    Code:
    Private Sub txtmiktar_KeyPress(KeyAscii As Integer)
    If KeyAscii <> 8 Then
    If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
    End If
    End Sub
    
    
    Private Sub txttutar_KeyPress(KeyAscii As Integer)
    If KeyAscii <> 8 Then
    If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
    End If
    End Sub

    And i am get rid of unlimited turnovers. But when i delete the index of the textbox, it says error for the type mismatch.
    Code:
    Private Sub txtmiktar_Change()
    
    txttutar.Text = CDbl(txtmiktar) * CDbl(txtbfiyat)
    
    End Sub
    
    Private Sub Txttutar_Change()
    Dim x As Double
     x = CDbl(txttutar) / CDbl(txtbfiyat)
     txtmiktar.Text = x
    
    End Sub
    Thank you.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,990

    Re: Text_change the problem.

    that's a totally different problem. why not try what I first suggested?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,845

    Re: Text_change the problem.

    Think about it when does that code run and what does it do?

    You change the text in one text box and the change event fires where you change the text in the other text box which fires the change event for it which then changes the text in the first one and round and round you go. It should be no surprise when your program falls into an endless loop.

    You should be doing this int he keypress event or you need to have a flag that stops it from repeating the event.

    This question was answered already in another thread on VB forumns and an example was given that showed how to avoid the endless loop using the change event.
    Last edited by DataMiser; October 2nd, 2013 at 11:37 AM.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center