Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Dyndrilliac on November 13, 2003, 07:15 PM

Title: Quotations in Strings
Post by: Dyndrilliac on November 13, 2003, 07:15 PM
I want to use quotations in a string. for Example:

frmMain.txtName.Text = ""Whatever Name Is""
Name = frmMain.txtName.Text
Print #1, "doc = " & Name & ";"


This errors - because i can't use double quotes like this - can anyone give me a way around this?
Title: Re:Quotations in Strings
Post by: K on November 13, 2003, 07:18 PM
Edit: link didn't work

Quote
Embed Quotation Marks
You use quotation marks in VB to define strings, but how do you include them in your output? Use whichever of these methods works the best for you:

   Dim strUseChr As String
   Dim strUseVar As String
   Dim strUseDbl As String
   
   Const Quote As String = """
   
   strUseChr = "Hello " & Chr$(34) & "VB" & _
      Chr$(34) & " World!"
   strUseVar = "Hello " & Quote & "VB" & _
      Quote & " World!"
   strUseDbl = "Hello "VB"" World!"
   
   Debug.Print strUseChr
   Debug.Print strUseVar
   Debug.Print strUseDbl

Each one prints:

   Hello "VB" World!

Source: http://www.devx.com/tips/Tip/16241
Title: Re:Quotations in Strings
Post by: iago on November 13, 2003, 07:33 PM
eww..

msgbox "Hello ""VB"" world!" is by far the best.
Title: Re:Quotations in Strings
Post by: Grok on November 13, 2003, 07:48 PM
Quote from: Dyndrilliac on November 13, 2003, 07:15 PM
I want to use quotations in a string. for Example:

frmMain.txtName.Text = """Whatever Name Is"""
Name = frmMain.txtName.Text
Print #1, "doc = " & Name & ";"


This errors - because i can't use double quotes like this - can anyone give me a way around this?

Fixed.
Title: Re:Quotations in Strings
Post by: Dyndrilliac on November 13, 2003, 08:00 PM
Now I have a whole new set of problems - whenever I put in soemthing like this:wHeight = txtHeight.Text it gives me "RunTime Error "13" - Type Mismatch", and I don't know why, but I need that so the user can define the number of the wHeight Integer.

It's Declared as : Dim wHeight As Integer
Title: Re:Quotations in Strings
Post by: Spht on November 13, 2003, 08:06 PM
Quote from: Dyndrilliac on November 13, 2003, 08:00 PM
Now I have a whole new set of problems - whenever I put in soemthing like this:wHeight = txtHeight.Text it gives me "RunTime Error "13" - Type Mismatch", and I don't know why, but I need that so the user can define the number of the wHeight Integer.

It's Declared as : Dim wHeight As Integer

wHeight = CInt(txtHeight)

CInt() returns Integer of Expression.

Edit -- You may want to check if contents of txtHeight is actually a number first (you could use IsNumeric for this).
Title: Re:Quotations in Strings
Post by: iago on November 13, 2003, 10:05 PM
Quote from: Spht on November 13, 2003, 08:06 PM
Quote from: Dyndrilliac on November 13, 2003, 08:00 PM
Now I have a whole new set of problems - whenever I put in soemthing like this:wHeight = txtHeight.Text it gives me "RunTime Error "13" - Type Mismatch", and I don't know why, but I need that so the user can define the number of the wHeight Integer.

It's Declared as : Dim wHeight As Integer

wHeight = CInt(txtHeight)

CInt() returns Integer of Expression.

Edit -- You may want to check if contents of txtHeight is actually a number first (you could use IsNumeric for this).

How's CInt different from val?
Title: Re:Quotations in Strings
Post by: Spht on November 13, 2003, 10:16 PM
Quote from: iago on November 13, 2003, 10:05 PM
How's CInt different from val?

Val() returns Double, CInt returns Integer (which is what he wants). Val has other functionality, such as stripping out non-numeric characters, and formatting string identifiers (i.e., Val("&HA") would return 10). If he wants that functionality, I suppose he could do something like wHeight = CInt(Val(txtHeight)).