Type EmpType(Emp_Num As String, Emp_FirstName As String, Emp_LastName As String, Emp_AllowEdits As Boolean, Emp_AllowMulti As Boolean, Emp_Rate As Double, Emp_ShiftStart As String, Emp_ShiftEnd As String, EmpDate As String, Emp_Brake1Start As String, Emp_Brake1Length As Int, Emp_LunchStart As String, Emp_LunchLength As Int, Emp_Brake2Start As String, Emp_Brake2Length As Int, Emp_Wage As Double, PassWord As String)
Here is the running code:
Note the value and length of ActiveEmp.Password after ActiveEmp.Initialize.
After setting the value of Password to Null the length changes to 4!
I will point out that the PRIOR value of Password had a length of 4. But this should have cleared after initializing again.
I see this now as TWO bugs.
1. Inconsistant behavior for Null. Null should set a Null value (as the return value of the database does), or fail if it can't because null is not valid.
2. The Debugger does not display any difference between the two. "null" is displayed as null and Null is displayed as null. This has caused me no end of grief trying to debug this. In the VBA debug window strings have quotes around them for clarity. That would help here as well. It would also help in distinguishing numbers from numeric strings.
Yes, and when GetString returns a Null it returns a pointer to a Null object that is assigned to (in this case) ActiveEmp.Password. This object then has no methods which is why the Debugger shows that the (Length) method does not exist (see @MrKim's link). Someone's opinion about Null: https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/
This is not considered a bug. It is a programming mistake to set Null to a string.
The compiler automatically converts the unknown object type to a string and it gets converted to "null".
The default value of strings is an empty string, not Null. Overall you will not see many uses for Null in B4X.
There is a historic mistake in some libraries which do return Null for strings (SQL.ExecSingleResult for example). The behavior cannot be changed without breaking existing code.
This is not considered a bug. It is a programming mistake to set Null to a string.
The compiler automatically converts the unknown object type to a string and it gets converted to "null".
The default value of strings is an empty string, not Null. Overall you will not see many uses for Null in B4X.
There is a historic mistake in some libraries which do return Null for strings (SQL.ExecSingleResult for example). The behavior cannot be changed without breaking existing code.
Return different results.. It appears that ActiveEmp.PassWord actually IS getting converted to a Null, which you are saying shouldn't happen?
In VB I would simply do this:
But I can't figure out how to write an Nz function that will properly evaluate Crsr.GetString("Emp_BadgeNum")
Also, you are correct in VBA
B4X:
ActiveEmp.PassWord = Null
would throw an error, which is why i always Nz it.
Because it does NOT throw an error in B4A I was assuming that it was setting to null and trying to test for it. (It SAYS the value is null, but the length function is throwing an error.) Again, take a look at my other post.
Thanks for your patience - and brilliance. I don't know how you do it. I am in awe.
BTW Nulls ARE a pain in the ass, but they do have there use in the Data world. Without adding a separate field they are the only way to know that the user has not yet entered a value for that field. Sometime the value is NOTHING ("") but if it is null you want to prompt the user in case they forgot to fill it in. And this may happen later, AFTER the record has been saved but before proceeding to some other operation which depends on this record.
Cursor.GetString returns a String type so the compiler sets it without any conversion. This is not the same as setting it with:
B4X:
Dim s As String = Null
Log(s.Length) '4 ("null")
The case with Cursor.GetString is an exception. This is one of the few cases where a string object can be set to Null.
As I wrote above, it is a mistake to set a string variable to Null in B4X. You should instead set it to an empty string. You can then check for empty value with:
B4X:
If s = Null OR s = "" Then 'Null from the database or "" from the default value
'empty
End If