How to stop Tkinter TextBox from terminating string on null character - python-3.x

I am new to tkinter and python, I need an editable textbox that supports null characters but
self.text.insert(tk.END, 'hello\0test')
displays only hello
I tried running print(self.text.get('1.0', tk.END)) which gives only hello
I am replacing the null character before assiging to TextBox for now 'hello\0test'.replace('\0', '\\x00'). but after editing, converting the value '\\x00' back to null character becomes a problem if the input string already had '\\x00' that also will get converted to null.

Related

#Error when exporting to .csv from ssrs when trying to replace a comma with another field

I am trying to replace a comma with another field so you can import the data using a csv. I can do that successfuly by adding .ToString().Replace(","," And ") to the end of the field
EX. Fields!Fieldname.Value.ToString().Replace(","," And ")). This will replace the comma with the word And.
The issue I have encounterd is when the field is blank. It then exports a #Error in the cell. I have tried hiding the cell if it is blank but that works for everything but when it exports to a .csv.
If I cannot get the field to be just blank I would like to have it display 99.
Please help.
I have tried this as well...
=Iif(isNothing(Fields!FieldName.Value),"99",(Fields!FieldName.Value.ToString().Replace(","," And ")))
It still displayed an error
The problem is that you are trying to convert NULL (Nothing) to a string. Both sides of IIF are evaluated so even though you will never see the result, false part is failing when FieldName is null.
TO get round this, we first check if the field is null, then replace that with and emptry string "" and then do the ToString() bit.
try the following...
=IIF(
isNothing(Fields!TestField.Value),
"",
(IIF(IsNothing(Fields!TestField.Value),
"",
Fields!TestField.Value
).ToString().Replace(","," And "))
)

How to print conditional fields in PPFA code

How do I print a conditional field using PPFA code. When a value is an 'X' then I'd like to print it. However, if the 'X' is not present then I'd like to print an image. Here is my code:
LAYOUT C'mylayout' BODY
POSITION .25 in ABSOLUTE .25 in
FONT TIMES
OVERLAY MYTEMPOVER 8.5 in 11.0 in;
FIELD START 1 LENGTH 60
POSITION 2.0 in 1.6 in;
Where it has FIELD START 1 LENGTH 60 that will print the given text at that location. But based on the value I want to print either the given text or an image. How would I do that?
Here is an answer from the AFP-L list:
I would create two PAGEFORMATS, one with LAYOUT for TEXT and one with LAYOUT for IMAGE. With CONDITION you can jump between the Pageformats (where Copygroup is always 'NULL')
If you work in a z/OS environment, be careful of 'JES Blanc Truncation'.
That means in one sentence:
if there is a X in the data, condition is true
if there is nothing in the data, condition doesn't work and is always wrong (nothing happens)
In this case you must create a Condition which is always true. I call it a Dummy-Condition.
PPFA sample syntax:
CONDITION TEST start 1 length 1
when eq 'X' NULL PAGEFORMAT PRTTXT
when ge x'00' NULL PAGEFORMAT PRTIMAGE;
You must copy this CONDITION into both PAGEFORMATS after LAYOUT command.
Blanc truncation is a difficult problem on z/OS.
In this sample, the PAGEFORMAT named PRTTXT contains all the formatting and printing directives when the condition is true, and the other called PRTIMAGE contains every directive needed to print the image.
HTH

Printf does not stop printing when it reaches a null character

Im trying to debug a null dereference in my program. The program receives data from a web form submitted by the user. It seems that the problem is related with empty fields. When user submit the form the table data is finally retrieved in a char *tabledata variable.
tabledata handle the data of the table using this format:
"row1column1value/row1column2value/row1column3value|row2column1value/row2column2value/row2column3value|\0"
For debugging purpose im printing tabledata content using:
printf("\n tabledata is = %s \n\n", tabledata);
But when i submit the table if i leave the first column of the second row empty im getting this output:
tabledata is = 11/22/33/44/55/22/33|(null)/1/44/55/88/33/44|
How is it possible that printf does not stop printing when it reaches a null character? How can i check that this (null) value is really a \0 null character?
%s along with printf will not do it.
You have to use puts(tabledata);
Hope this answers your question.

How to verify ANY text is present with selenium IDE

I know how to verify if a specific text is present in a web page using Selenium IDE. But what I wanted to know is, can you verify that any text is present in an element?
For example there's a text box with the title "Top Champion". This text box will be changed daily with the name of a person. Now I just wanted to check whether there is a text in this text box, no matter what the text actually is. I've tried the verify text command and tried blanking the value, but it doesn't work. If the command can return a true or false command that would be really helpful
BTW, verify value doesn't work either since the element that I'm testing is not a form field
Your best bet is as follows (I have written single tests for this for numbers)
Medium rigour:
waitForText | css=.SELECTORS | regex:.+?
This will wait until there is at least 1 character present.
Strong rigour (only works if you have a subset of characters present):
waitForText | css=.SELECTORS | regex:^[0-9]+$
This will wait until there is text. This text must start with a number, have at least 1 number, and then finish. It does not permit any character outside of the subset given. An example you could do to match numbersNAMEnumbers would be.
waitForText | css=.SELECTORS | regex:^[0-9]+[a-zA-Z]+[0-9]+$
This would wait for a string such as 253432234BobbySmith332
Luke
If i have understood your question properly there below is one way you can search for an element contains a string. Not sure if this is what you are looking.
List<WebElement> findElement = webElement.findElements(By.xpath("YOUR_TEXTINPUT_PATH_HERE"));
if( findElement.size() > 0 ){
if( findElement.get(0).getText() != null && findElement.get(0).getText().indexOf("THE_STRING_THAT_YOU_WANT_TO SEARCH") != -1 ) {
// IF IT COMES HERE, THAT MEANS THE ELEMENT IS PRESENT WITH THE TEXT
}
}
store text|[your element]|StoredText
execute script|return ${StoredText}.length > 0|x
assert|x|true
Using these three lines in the Selenium IDE, the first line will extract the text from the element into the variable StoredText.
The second line will store whether the length of that text is greater than zero into the variable x (a true or false result).
The third line asserts that the result was true, failing the test if not. You don't need the third line if all you want is the true or false result.
So if the element contains any text, the extracted text length will be greater than zero, the variable x will be true, and the assert will pass. This verifies that any text is present in the element.

Deleting contents of a string - TextBox behaves slightly differently from DataGridView text cell

If you set up a simple test form with a TextBox bound to a string property of a class and delete the content the value passed back to the property setter is "".
If you do the same thing with a cell in a DataGridView the value passed back to the property setter is Nothing.
Why the difference and is there anything we can apply to the DataGridView to make it behave the same as a TextBox?
if am correct the DataGridViewTextBoxCell by default is Null and the TextBox by Default is String.Empty
you might check the Null vs Empty
Nothing is VB's version of C#'s null or a database's NULL. It means that there is no value, as opposed to "" which means that there is a value, of an empty string.
I'm not entirely sure, but I suspect the difference is because a textbox's Text property is always a string, but a cell's Value property can be any object. You can use the null-coalescing operator to return an empty string when the value is Nothing.
Set(ByVal value As String)
_Surname = If(value, "")
End Set
Alternatively, you can validate the cell post-edit and set it to ""explicitly. see here for an example - instead of messaging the user, you'd just change the value.
DataGridView converts "" into Null during cell parsing.
If you handle CellParsing event and just set ParsingApplied, then no further parsing will be performed and the resulting value will remain "".

Resources