VB cursor in a textbox

redwire Posted messages 259 Registration date   Status Member -  
 G -
Hello!

1- In my VB project, I want my cursor to be placed in a specific textbox upon loading.
I use text_nombre.setfocus...

but it doesn't work...

2- Moreover, this textbox is filled by a laser gun scanner that scans a barcode, but this gun scans the number and ends with a "carriage return"
since it is used for another application, I have no choice.
How can I make this carriage return trigger the action I want to perform based on the barcode it scanned?

Thank you

PS: How do you install a VB5 program on a NT4.0 workstation?

6 answers

DFR.eXia
 
Hello,
Placing the cursor in a TextBox of your choice makes it the active control.
This is not a property of the TextBox itself, but a property of the form that contains the control (the TextBox).
To place the input cursor in TextBox3 of the Form1, for example:

Form1.ActiveControl = TextBox3

If you want to do the same at form load, you must use the "Form1_Load" event, but the line becomes:

Me.ActiveControl = TextBox3

Good luck.

Denis FROELIGER Professor at eXia
19
benoit_iund Posted messages 121 Status Member 43
 
You can also place your textbox first in these properties.
tabindex = 0 and the other objects, button, combo, etc. in any order you like.
2
Veve
 
Regarding the carriage return, I've done the same thing before; you need to act on the KeyPressed event of your textbox and test if the typed character is not equal to char(13). If it is equal to char(13), you set the Cancel parameter to true (to prevent the carriage return from being kept) and trigger the actions you want.

Let me know if it's not clear enough ;)
(Oops, this topic dates back to 2005 :P You never know, it might still be useful to some passersby)
1
fredmajor Posted messages 9 Status Member 1
 
In which event do you put your instruction?
I think it should be in the activate() event of the sheet in question.
Try it to see.
0
ENDYMION PUBLISHING Posted messages 1 Status Member
 
In VB.NET, you just need to do text_example.Focus()
0
G
 
You just need to count the characters in the text box using the LEN function --> followed by a character count

example:

Private Sub TextBox_SILOE_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox_codebar.TextChanged

'check for the presence of the 28 characters of the bar code at each state change of TextBox_codebar
Longueur_siloe = Len(TextBox_SILOE.Text)

If Longueur_siloe = 28 Then
'save the bar code
SILOE = TextBox_codebar.Text
'Activate the control and validation form
validation.Activate()
'Display the control and validation form
validation.Show()
'convert the siloe number to Text from DB references

End If
End Sub
0