Capturing input from a textbox

  • Thread starter Thread starter dteribery
  • Start date Start date
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
 
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
 
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.
 
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
 
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.
 
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
 
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
 
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.
 
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
 
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.
 
WriteLine write the data and a carriage return to end the line. Use the
Write method instead.
 
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
 
Back
Top