same old quotation marks problem

barkode

Member
Joined
Dec 30, 2011
Messages
14
Programming Experience
Beginner
I searched the forum but couldn't find a "fix." So if I enter in a TextBox a word or phrase without quotation marks, what follows it'll be processed correctly. But if I dare to use any quotation marks* then disaster strikes. Double, triple, quintuple quotes won't help. And I'm talking here about UI: the user entering whatever he needs in that TextBox at runtime.

*
When the user enters:
(A). "dog"
(B) "My name is"
(C) She says "Hello!"

It's extraordinarily annoying, I can't believe there isn't a simple fix for this bug, especially since I noticed that alotta people are complaining
 
It's not the fact that the TextBox has double quotes in it that is the problem. The is in your own code. It's how you're processing that data that is the issue. You haven't shown us that so there's no way that we can help you fix it.
 
I won't post the whole code, but simplify it to the core:

Dim a, b, p As String
a = ""
b = TextBox1.Text


If RadioButton1.Checked = True Then


a = "www.bing.com/search?q="
p = a & b
Process.Start(p)

For as long as TextBox1.Text = Joe buys a six pack (i.e., quotation marks-free)- it's fine. But "Joe buys a six pack", Jane says "Hello". or even only "Bill" will result in a total mess.
 
Interestingly, I had no issue with double quotes as long as there was no more than one word inside the double quotes. When there were multiple words inside the quotes there was no error but no page was opened.

The answer is to URL-encode the value. Change this:
VB.NET:
p = a & b
to this:
VB.NET:
p = a & Web.HttpUtility.UrlEncode(b)
The only drawback of that is that it requires you to add a reference to System.Web.dll, which means targeting the full Framework rather then the Client Profile. If that's an issue then there is an alternative.

The issue seems to be spaces between the double quotes. Unless there are some other special characters, all that UrlEncode method does is replace spaces with + symbols. You can do that with the String.Replace method if you want.
 
Tried it. It says:

Error 1 'HttpUtility' is not a member of 'Web'. Projects\Add-Del\Add-Del\Form1.vb 33 21 Add-Del
 
Then you are still targeting the Client Profile and not the full Framework, which I specifically addressed in post #4. It appears that you simply ignored what I posted. If you read something and don't understand it then the logical thing is to say that you don't understand it, not simply ignore it. Look at the Advanced Compile Options in the project properties to change the target Framework.
 
that's why I mentioned the lesson I'm at, cuz I'm a beginner. So I didn't ignore it, I just didn't get it. Anyways: I went to Advanced Compile Options and switched from .NET Framework4 Client Profile to .NET Framework4 (which I guess is "the full Framework") then I tried to run the program again. It says the same thing: 'HttpUtility' is not a member of 'Web'
 
Back
Top