Capturing input from a textbox

D

dteribery

Hello,

I am trying to make a program that when someone uses a scanner to scan
a barcode that the number will automaticly be entered into a .txt
file. I tired to use the most of the events and none have seemed to
work .Does anyone have any ideas. I and using VB.net 2005. Thank you
 
S

Steve

My barcode scanners (Intermec) add a CRLF to the end of the text
automatically, and yours probably does to. If you look for that
character on the KeyDown event, you should be able to pick up the text
and use the System.IO namespace classes to write the file.


Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
D

dteribery

My barcode scanners (Intermec) add a CRLF to the end of the text
automatically, and yours probably does to. If you look for that
character on the KeyDown event, you should be able to pick up the text
and use the System.IO namespace classes to write the file.

Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA






- Show quoted text -

Steve,

Thank you for that idea. I will have to try that out and see what
happens.
 
M

Miro

Steve,

Thank you for that idea. I will have to try that out and see what
happens.

Also,
Take a look at the com port "serialport" object as well.
Some new scanners are USB and they have a driver that actually assigns a
com port to the USB port of a scanner.
So what I do is I have teh SerialPort listening to a comport and flush
that to the "topmost" application or to whatever textbox I need to.

Miro
 
D

dteribery

Also,
Take a look at the com port "serialport" object as well.
Some new scanners are USB and they have a driver that actually assigns a
com port to the USB port of a scanner.
So what I do is I have teh SerialPort listening to a comport and flush
that to the "topmost" application or to whatever textbox I need to.

Miro- Hide quoted text -

- Show quoted text -

Miro,

I will also look into this one. I will have to see what will work be
for this application. Thank you again.
 
D

dteribery

My barcode scanners (Intermec) add a CRLF to the end of the text
automatically, and yours probably does to. If you look for that
character on the KeyDown event, you should be able to pick up the text
and use the System.IO namespace classes to write the file.

Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA






- Show quoted text -

Steve,

I did code this as follows. However I am having the problem of it only
getting the last digit of the serial number. Can you give me a little
more help.


Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter

oWrite = oFile.CreateText("C:\sample2.txt")
oWrite.WriteLine(TextBox1.Text)
oWrite.Close()
TextBox1.Text = ""


End Sub
 
S

Steve

You're missing the .Flush() call before you close the StreamWriter. It
should be something like this:

oWrite.WriteLine(TextBox1.Text)
oWrite.Flush()
oWrite.Close()

See if that helps.


Steve C.
MCSD,MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
D

dteribery

You're missing the .Flush() call before you close the StreamWriter. It
should be something like this:

oWrite.WriteLine(TextBox1.Text)
oWrite.Flush()
oWrite.Close()

See if that helps.

Steve C.
MCSD,MCAD,MCSE,MCP+I,CNE,CNA,CCNA








- Show quoted text -

It did not help. It has something to do with how I am clearing the
text box at the end. If I comment out textbox1.text out this part of
the code I can get the whole sku to show up in my file. If i had to
delete the old sku from the textbox everytime this would defeat the
purpose.
 
S

Steve

So if you don't clear the textbox, it works fine. Then you say that you
don't want to clear the textbox. So what's the problem? (I think I'm
missing something...)

Also, you can simplify the code more by passing the filename string
directly to the constructor of StreamWriter. Then you don't need oFile
at all.


Steve C.
MCSD,MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
D

dteribery

Steve,

No I do want to clear the text box. I want them to be able to scan all
the items without having to touch a mouse or keyboard. I found
different code and it will let me clear it but it lines up funny. I
have posted the Code and the output below.
Dim fw As StreamWriter

Dim ReadString As String

Try
'Pass the file path and name to the StreamWriter
constructor.
'Indicate that Append is True, so file will not be
overwritten.
fw = New StreamWriter("C:\sample2.txt", True)
ReadString = TextBox2.Text
fw.WriteLine(ReadString)
Finally
'Close the file.
fw.Close()

End Try
TextBox2.Text = ""

I get this for output in the sample.txt file.
1
2
3
4
5
6

I want it to be:
123456

Thank you again for all your help.
 
P

Patrice

WriteLine write the data and a carriage return to end the line. Use the
Write method instead.
 
S

Steve

In your example, if 1, 2, 3, 4, 5, and 6 are individual SKUs, then you
need to use fw.Write() instead of fw.WriteLine().

If they're actually one SKU spread out over 6 lines, then you may have
an extended ASCII character (like a CRLF) being inserted between each
"normal" character. You may need to do some cleanup of the string before
you store it, to remove any unwanted characters.


Steve C.
MCSD,MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 

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