Undefined String in the last character of SerialPort ReadLine VB.Net - vb.net

I make program using vb.net where it connected to barcode scanner using rs232 connection. As generally, I use serialport communication (SerialPort1.ReadLine) to get data from barcode scanner. First I think it's work because the barcode value appears in the textbox until I get it can't show the data which has relation with barcode value.
The barcode value is same with data in database, but it can't show. So I try to copy the data from textbox then found that there are the undefined string in the last character of textbox. It's like space but not, when I copy that textbox value to the winword, the value enter automatically, so, i just want to know how my programs can read the barcode value without that undefined string.
Thank you,

When a bar code scanner is configured often the default is to add a termination string called a suffix or a postamble. The termination string is useful to tell the receiving program that all of the data has been sent.
It can be set to anything; a common configuration I’ve seen is the carriage return (vbCr) linefeed (vbLf) pair. You could also set it to not send anything additional which is also a common configuration.
You can build in a configuration option in your VB code to specify a termination string. Your program would look for this termination string as you are receiving the data from the serial port and then strip it out before sending it to the next part of your program. This allows you to easily handle various scanner brands and configurations by changing your configured string.
It is possible for serial data to be delayed and not receive everything at once. By checking for the termination string you can be sure you received it all before acting on it. If you have data but do not see your terminator save the received string and add the additional data as it arrives.
Bar code scanners also have a suffix or prefix that is prepended to the beginning of a scan. This can be used to identify the bar code symbology or other useful information. Usually the default I’ve seen is not to send anything.

I have another solution and I think it's better solution then using NewLine property.
Actually the character in the last string of barcode value is vbCr or vbLf, I don't know what that's mean, but I know it in the manual of barcode scanner. So to remove that character we can use mid function and replace that character with this string "".

Related

Entering ! (exclamation sign) in the OBLIGATORY parameter doesn't work as input. Why?

Suppose we have following selection screen:
PARAMETERS: d_char OBLIGATORY.
WRITE d_char.
When the user enters ! in this field of selection-screen and runs the program, it still prompts for required entry in this field.
Why?
You can find the answer in the documentation for Dynpro Fields.
When dynpro fields are received from input fields on the screen, input fields are templates that expect a certain format depending on the data type of the underlying dynpro field. When passed to the dynpro field, the input is converted to a value of the appropriate type. This also means that some characters function as special characters by default.
The "!" character in the initial position of an input field on the screen deletes all characters in the field before the data transport.
The "=" character in the initial position of an input field on the screen initiates a search using search helps.
If an input field contains only blanks and "_" characters, the latter are transported as blanks.
To deactivate the template and also the modifying effect of special characters, the attribute Without Template can be activated in Screen Painter. However, the template cannot be deactivated for selection screens.
Define the parameter as TYPE STRING and you will receive the ! as well as the = or even a space.

vb.net or PS script to past value to a program form...

I have an older program I think was developed/complied using C++ that tracks sellable items we have. We enabled an option in the programs preferences that allows us to use an alternate sort field for reporting and inquiries. This field can contain any alpha/numeric value, but cannot be 'Blank' NULL.
However, when we enabled this feature, and we realize now we can’t un-enable it. Each item records (14,000+) now contain a "blank" NULL value for this field. At this point none of our reports will run and we get an error indicating: "Alternate Sort value can't not be NULL" So it looks like I will need to manually enter a value in the 'blank' NULL field.
I have a text file with the values for each record in the same order as they are displayed on the entry grid in the program. The database is propitiatory and there are no db tools provided to us that will allow us to import the values directly.
Does anyone know of a way to use vb.net or a PS script to basically read a value from a text file and then paste it where the cursor is on the screen and then send an {ENTER Key}, and then repeat the process?
Thanks

Embed console in form

TL;DR:
Is there a way to embed a console inside a form, so it becomes a part of it?
Scenario:
I am writing a chat-application with client, server and database using Windows Forms in VB.NET. The server should log all communication it has with clients in a textbox.
The Problem:
So far that would not be a problem - If there wasn't a maxlength for strings! I expect this server to almost never stop (Okay, there is always some point where it does.. but lets ignore that). So if i go for Textbox1.Text &= vbnewline & "Something" it will some day reach this length and run into an exception each time something is about to be logged. I also don't want to just remove the first characters of the string.
My Idea for a solution:
My idea for a work around: Use a console instead of a simple textbox and embed it into the form, so it becomes a part of it. Is there a simple way to do that? By simple I mean that I should have to write thousands of lines of code to achieve that goal.
I am open minded for different ideas and ways to do so as well.
Why not just log your chat to file (you could create a file per day)?
Dim filename = String.Format("C:\Temp\{0:yyyy-MM-dd}-log.txt", DateTime.Now)
My.Computer.FileSystem.WriteAllText(filename, "line of text", True)
Then to display it - use a ListBox and append each new line to the end of the listbox? Each time you append, you could check how many items are in the listbox and remove the first 100 if you are over 1000 as an example.

Handling ⅝ (five eights) Vulgar fraction as part of a string in VBA

As part of an access application, i retrieve data from sql server. I have a string field that contains ⅝ in one of the rows, and when i attempt to insert that value into an MsAccess recordset, i get an error
Multiple-step operation generated errors. Check each status value. Here is my code
sFieldValue = getValue() ' when i add a watch, the '⅝' is replaced by a ? e.g. "The result is ⅝" will be shown as "The result is ?"
Rs(sFieldName) = sFieldValue ' error is thrown
I then attempted to hard code the value in VBA
sFieldValue ="⅝"
And the moment i type '⅝' it automatically changes to a question mark
sFieldValue ="?"
I would like to know how i can support characters such as "⅝". The other fractions work just fine, e.g. '½'. I do not want to do any calculations, the fractions are part of a string that comes from a SQL Server, and the problem is, i get a runtime error when i try to add a string value that contains a fraction to a recordset in access.
from this page, it shows that some fractions are supported in utf-8
The problem was that the field type of Rs(sFieldName) was adVarChar. So to fix the problem, i used a adVariant field type in my recordset, and it now accepts the ⅝ vulgar character.
I am creating the recordset on the fly.
Edit: adVarWChar is more appropriate, see comment below

controlP5 textfield contents. Processing

I have a sketch in processing I am working on which contains a textfield and a submit button. When the submit button is pressed, a file with is created using the name given in the textfield. I want to make sure something has been entered into the textfield when the submit button is pressed, however, it appears that by default the string is not empty or contain white space and is not caught by if statements.
Is there any simple way to check that something has been entered in the text field without needing to resort to something like regex?
I am not sure I understood whether by default your string is not empty and also does not contain white space (which would make it an odd example). The best possible check I can think of is to trim whatever the entered string is and then check if it is empty:
if(enteredString.trim().length() > 0) println("The string is valid");
the trim() method trims leading and trailing spaces, so if there are only spaces they will be removed making the string empty. Also, since you are saving files you might want to check for invalid characters. With Processing (Java) you don't necessarily have to resort to regex since you can do stuff like these:
String s = "ashd/ah";
println(s.contains("/"));
println(s.replace("/","-"));
which will print:
true
ashd-ah