How to create an automated input box.

C

cmdolcet69

I have the code below that will evaluate a string of characters. If
its less then 12 long it will trigger a message box if its equal it
will save the information and close the form.

I have this currectly on a button event, how could i place this same
logic say once i enter in my last character it will trigger the logic
written in the button control.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
If Len(Me.txtBarCode.Text) = 12 Then
_barcode = Me.txtBarCode.Text
Close()
Else
MessageBox.Show("The Current BarCode Scanned was not
correct, Please Re Enter")
Me.txtBarCode.Text = String.Empty
txtBarCode.Focus()
End If
End Sub
 
K

kimiraikkonen

I have the code below that will evaluate a string of characters. If
its less then 12 long it will trigger a message box if its equal it
will save the information and close the form.

I have this currectly on a button event, how could i place this same
logic say once i enter in my last character it will trigger the logic
written in the button control.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
If Len(Me.txtBarCode.Text) = 12 Then
_barcode = Me.txtBarCode.Text
Close()
Else
MessageBox.Show("The Current BarCode Scanned was not
correct, Please Re Enter")
Me.txtBarCode.Text = String.Empty
txtBarCode.Focus()
End If
End Sub

Remove button, put the "if - then" code blocks into a timer control in
a timer_tick event and enable it.
then don't forget to disable it in order not to have a
endless(forever) messagebox.

Hope this helps.
 
A

Armin Zingler

cmdolcet69 said:
I have the code below that will evaluate a string of characters. If
its less then 12 long it will trigger a message box if its equal it
will save the information and close the form.

I have this currectly on a button event, how could i place this same
logic say once i enter in my last character it will trigger the
logic written in the button control.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
If Len(Me.txtBarCode.Text) = 12 Then
_barcode = Me.txtBarCode.Text
Close()
Else
MessageBox.Show("The Current BarCode Scanned was not
correct, Please Re Enter")
Me.txtBarCode.Text = String.Empty
txtBarCode.Focus()
End If
End Sub

Move the code from Button1_Click into a new sub. Call the sub in the Click
handler and additionally in the Textbox' TextChanged event. (But, as a user,
I would like to be able to edit the text I entered until I pressed the
button.)


Armin
 
K

kimiraikkonen

I have the code below that will evaluate a string of characters. If
its less then 12 long it will trigger a message box if its equal it
will save the information and close the form.

I have this currectly on a button event, how could i place this same
logic say once i enter in my last character it will trigger the logic
written in the button control.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
If Len(Me.txtBarCode.Text) = 12 Then
_barcode = Me.txtBarCode.Text
Close()
Else
MessageBox.Show("The Current BarCode Scanned was not
correct, Please Re Enter")
Me.txtBarCode.Text = String.Empty
txtBarCode.Focus()
End If
End Sub

Addition: Pay attention to put "timer1.enabled = false" before
messagebox, if you don't disable or disable after messagebox every OK
prompt for messagebox circulation will never end.
 
C

Cor Ligthert[MVP]

Armin,

Move the code from Button1_Click into a new sub. Call the sub in the Click
handler and additionally in the Textbox' TextChanged event. (But, as a
user, I would like to be able to edit the text I entered until I pressed
the button.)
If you have only on a form to enter 1000 numbers in an hour you be probably
glad that there is no button click needed.

My expirience is that in those situations mostly the users don't even look
what they have typed when clicking the button.

(Or set the focus on the Button when it is 12 and then let the Enter key do
this job to get both)

Just my thought,

Cor
 
A

Armin Zingler

Cor Ligthert said:
Armin,


If you have only on a form to enter 1000 numbers in an hour you be
probably glad that there is no button click needed.

My expirience is that in those situations mostly the users don't
even look what they have typed when clicking the button.

(Or set the focus on the Button when it is 12 and then let the Enter
key do this job to get both)

Just my thought,

Ok, I see. The OP might have reasons why he needs it, that's why I only
wrote my comment in braces. :)


Armin
 
C

cmdolcet69

Move the code from Button1_Click into a new sub. Call the sub in the Click
handler and additionally in the Textbox' TextChanged event. (But, as a user,
I would like to be able to edit the text I entered until I pressed the
button.)

Armin- Hide quoted text -

- Show quoted text -

Armin, if i move the code or create another sub and place it under the
text change event. Each time i enter a number i get the message box
because the text change event is evaluating it each time.
 
C

Cor Ligthert[MVP]

That is the normal behaviour,

However don't botter about that, you see this while debugging, however not
one human can type that quick that he can be faster than that (even not
with repeating the key).

Cor


"cmdolcet69" <[email protected]> schreef in bericht
Move the code from Button1_Click into a new sub. Call the sub in the Click
handler and additionally in the Textbox' TextChanged event. (But, as a
user,
I would like to be able to edit the text I entered until I pressed the
button.)

Armin- Hide quoted text -

- Show quoted text -

Armin, if i move the code or create another sub and place it under the
text change event. Each time i enter a number i get the message box
because the text change event is evaluating it each time.
 
C

Cor Ligthert[MVP]

Correction,
However don't botter about that, you see this while debugging, however not
one human can type that quick that he can be faster than that (even not
with repeating the key).
I am glad Stephany not yet did see this one "he/she"

Cor
 
J

Jack Jackson

Armin, if i move the code or create another sub and place it under the
text change event. Each time i enter a number i get the message box
because the text change event is evaluating it each time.

Of course. You need to call your Sub only when the user has entered
the last character. It is up to you to decide what that means.

One possibility is to call the Sub only when Me.Text.Length = 12.
 
C

Cor Ligthert[MVP]

Jack,
Of course. You need to call your Sub only when the user has entered
the last character. It is up to you to decide what that means.

One possibility is to call the Sub only when Me.Text.Length = 12.

It seems that Armin and I miss something, can you show us how to do that?

This all is about measuring WHEN the 12th character is entered.


Cor
 
A

Armin Zingler

Jack Jackson said:
Of course. You need to call your Sub only when the user has entered
the last character. It is up to you to decide what that means.

One possibility is to call the Sub only when Me.Text.Length = 12.

Right, that's what I've overlooked. Thx.


In addition, in the Button_Click event, the check for the length 12 can be
left out, because, the Form has already been closed /before/ in the
TextChanged event. In other words, if the user has the time to click the
button, the length is never 12. (Is this correct?)

So,..

Private Sub Button1_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnOK.Click

MessageBox.Show( _
"The Current BarCode Scanned was not correct, Please Re Enter" _
)
Me.txtBarCode.Text = String.Empty
txtBarCode.Focus()

End Sub

private sub txtbarcode_Textchanged(...) handles txtbarcode.textchanged

If Len(Me.txtBarCode.Text) = 12 Then
_barcode = Me.txtBarCode.Text
Close()
end if

end sub


Armin
 
Z

Zebra Code

"cmdolcet69" <[email protected]> ha scritto
Move the code from Button1_Click into a new sub. Call the sub in the Click
handler and additionally in the Textbox' TextChanged event. (But, as a
user,
I would like to be able to edit the text I entered until I pressed the
button.)

Armin- Hide quoted text -

- Show quoted text -
Armin, if i move the code or create another sub and place it under the
text change event. Each time i enter a number i get the message box
because the text change event is evaluating it each time.

Private Sub txtChartSize_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtChartSize.LostFocus
MessageBox.Show(txtChartSize.Text.Trim.Length.ToString)
End Sub

or

Private Sub txtChartSize_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtChartSize.Validating
If txtChartSize.Text.Trim.Length < 12 Then MessageBox.Show( _
"HEY! You lost " & (12 - txtChartSize.Text.Trim.Length).ToString
& " chars!")
End Sub

hth, ciao, ZC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top