VB syntax - quotes in string


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I am using guid keys.



In a custom data source BO for a report I am putting a filter on a child cursor



Basically I want the filter to be "cclientkey =" and then the guid as a string - but of course in quotes



_policydisplay.SourceBO.Filter = "cclientkey = " & Me.ckey.ToString



doesn't work as the guid is not surrounded by quote in the resulting filter string.



I googled and tried things like



Dim quotes As Char = ChrW(34)

Dim filtstr As String = "cclientkey = " & quotes & Me.ckey.ToString & quotes

_policyDisplay.SourceBO.Filter = filtstr





Dim filtstr As String = "cclientkey = """ & Me.ckey.ToString & """"

_policyDisplay.SourceBO.Filter = filtstr



etc and no joy



Then reverted to the old Foxpro way



Dim filtstr as String = "cclientkey = '" & me.ckey.toString & "'" ( using single quotes to surround the guid )

and it works.



But a single quote to surround a string will throw and error. Is this some magic the old Foxers at Microfour have made possible? Never saw any solution like this in VB land? And what other ways are there to do this that work?















Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Charles R Hankey (02/19/2009)
...And what other ways are there to do this that work?

How about this one:

Dim filtstr As String = String.Format("cclientkey = '{0}'", Me.cKey)



Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Thanks, Eddy



Yes I like that syntax better.



But once again, the guid is surrounded by single quotes. Are single quotes valid in VB .net or is that just something made possible by Microfour in setting the filter. I realize that in code actually sent in a sql server query the single quote would be appropriate but I was surprised to find it working in within the BO. ( now I need to test it with square brackets ... ) Smile



No complaints, of course, as there is a lot to like about some of the tricks we learned in Fox.
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
FWIW - the square brackets don't work Wink

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Charles R Hankey (02/19/2009)

But once again, the guid is surrounded by single quotes.

Charles, I am sorry, but I don't quite understand the problem here, does the version of the code I gave you worked?

The value of the GUID is of String Type and does not have a single quote in it, the single quote would be needed to construct the BO.Filter value, but using the String.Format would take care of it.

Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
The code you gave me and works fine. I was just wondering why a single quote works surrounding the guid as I have usually found VB doesn't like single quotes (except as part of a string passed to a sql backend) and doesn't see them as an alternative to doublequote. You know what I mean about Foxpro, where you can use single quotes, double quotes or square brackets so putting quotes inside a string can be done a lot of different ways.



Since a BO filter is all within the BO I am surprised the VB compiler sees the single around the guid as defining a string where you could not say



Dim str as string = 'This is a string'

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Now I understand, and yes you are right, unfortunately I don't know the answer, of course coming from VFP I also have been bit with this situation before.

Talking about VFP I had to release an update to one of my applications done in VFP and while coding I often used the single quote instead of the "*" to comment a line realizing that I was not coding in VB.NET Hehe, also I expected the IDE to properly format the code after finish a line without having to run the Beautify command.  It was a bit frustrating going back to the VFP IDE.

Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I know what you mean. I do most of my billable work in VFP and while I like a lot of things about VFP (at least in the context of my framework) the IDE is definitely not one of them. The debugger feels pretty primative too.



Even at my beginner level in .net i am really seeing the power that is available. Definitely not the RAD environment i have in VFE/VFP but I have a feeling that as my knowledge grows - and Strataframe matures - the result will be a much more powerful programming environment.



( I am about to test some of my training theories by posting a Sharpshooter walk through that I hope will save others some of the frustration I have experienced in the last couple weeks )



Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
Interesting. Single quotes bit me hard going from VFP to VB.NET (like most things), until I realized I had to replace single quotes in my SQL strings with double quotes for TSQL to interpret correctly, perhaps somewhere in the bowels of the datalayer the SF boys do this before the filter gets passed to the underlying datatable of the BO?

Replace(<<some string>>, "'", "''")



Keith Chisarik
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I don't think has anything to do with either SQL Server or SF. This is an ADO.NET thing. I'm pretty sure (I haven't looked it up in source code yet, but the SF guys don't tend to build stuff that already exists) they just set the filter on the current view of the datatable. So, I think something like this is actually going on when you set the filter:



'-- This is the BO syntax

myBo.Filter = "stringColumn = 'somefilter value'"



'-- Under the covers, Expanded to make it clear

Dim view As System.Data.DataView = myBo.CurrentDataView

view.RowFilter = "stringColumn = 'somefilter value'"





Based on this, single quotes makes sense, because MS knows that you'll be setting the value of the filter in code and that means that single quotes will work better. Here is info on the RowFilter property of the DataView:



http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter.aspx



Again, I think this is what's going on. I didn't get a chance to look at the source, but this is what I'd expect.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search