-
September 28th, 2013, 06:29 AM
#1
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.
-
September 28th, 2013, 01:19 PM
#2
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)
-
September 29th, 2013, 03:51 AM
#3
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.
-
September 29th, 2013, 02:50 PM
#4
Re: Text_change the problem.
that's a totally different problem. why not try what I first suggested?
-
October 2nd, 2013, 11:32 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|