OK what am I missing here?

I’m putting this in “getting started” because it must be a noob question, but given a textbox with the value “WHATEVER” (including the quotes) in Text, I observe the following in the debugger:

var dq As String = Chr(34) // puts a double quote into dq
var fc As String = Me.Text.Left(1) // gets a double quote from first position of text
var t1 As Boolean = Me.Text.Left(1) = Chr(34) // False. WTAF?

I have noticed this before … a string of length 1 seems to be some special case or something, it never seems to be equal to anything. When I saw it before it was code trying to figure out if a character was upper or lower case and I ended up abandoning it because I ended up not needing that bit of code. Figured I’d circle back to it later, but that code could not seem to find “a” or “A” to be equal or greater than anything.

It gets worse … adding to the above code:

var t2 As Boolean = dq = Chr(34) // true
var t3 As Boolean = dq = dq // true
var t4 As Boolean = Chr(34) = Chr(34) // true
var t5 As Boolean = fc = dq // false
var t6 As Boolean = fc = Chr(34) // false

Adding yet more code to the test – the Asc() of fc is 34 and the length of fc is definitely 1. So in what universe is fc <> Chr(34)??

OK I knew if I posted this here in a way that would deeply and publicly humiliate me, I’d find the solution.

Even more humiliating, I have no clue why but it just started working.

The idea is if someone puts a quoted string in, leading and/or trailing quotes are removed when focus is lost.

This, I swear before the Almighty, was my original code, and now it has decided to work:

If Me.Text.Length >= 2 And Me.Text.Left(1) = “”“” And Me.Text.Right(1) = “”“” Then
Me.Text = Me.Text.Middle(1,Me.Text.Length - 2)
ElseIf Me.Text.Length >= 1 Then

If Me.Text.Left(1) = “”“” Then
Me.Text = Me.Text.Middle(1)
ElseIf Me.Text.Right(1) = “”“” Then
Me.Text = Me.Text.Left(Me.Text.Length - 1)
End If

End If

In my defense I am woozy from the latest Covid vaccine, lol

Not a noob question, you just ran into a difference between a Unicode double quote (“) and an ASCII double quote (i.e. Chr(34)). Notice the slight difference in how the characters is represented. The Unicode double quote that you are seeing in your TextBox consists of a codepoint that differs from the ASCII double quote codepoint. If you wanted the ASCII representation to appear in your TextBox, try copying and pasting the ASCII version (")

1 Like

Thanks William. I thought of that but “”“”" = Chr(34) = the variables I had in my code so IDK … maybe something in MacOS was transforming " to and open or close-quote, and now it’s not??

In the real world this is just a convenience feature for when I paste values from the .NET debugger into this app, and those will always be ASCII quotes so it is probably going to work fine.

A lot of software changes regular quotes into smart quotes without telling you. For example, the forum software is turning everything you are posting into smart quotes. I would recommend not using string checks for what you are trying to do, use the Asc() value.

If you are trying to remove all types of quotes you will need a Chr(34), Chr(8220), and Chr(8221)

1 Like

I’m using Mojave so what I have is:

System Preferences → Keyboard → Text → Use smart quotes and dashes

You’d need to disable that or set it appropriately.

The debugger is your friend in cases like these. You can always look at the string variables and view their binary contents.

Yeah that is what I was doing, down to looking at Asc() values, but I accept that I must have gotten myself turned around somehow. It’s working correctly now in any case.

As to the other thing I noticed, where comparing two one-character strings seemed to be failing, I’ll circle back to that eventually. I try not to get hung up for a full afternoon on something when I can work around it in 15 minutes, if you catch my drift. So long as the workaround isn’t offensively crufty, anyway.