Valhalla Legends Forums Archive | Visual Basic Programming | Quotations in Strings

AuthorMessageTime
Dyndrilliac
I want to use quotations in a string. for Example:

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

This errors - because i can't use double quotes like this - can anyone give me a way around this?
November 14, 2003, 1:15 AM
K
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!
[/quote]

Source: http://www.devx.com/tips/Tip/16241
November 14, 2003, 1:18 AM
iago
eww..

msgbox "Hello ""VB"" world!" is by far the best.
November 14, 2003, 1:33 AM
Grok
[quote author=Dyndrilliac link=board=31;threadid=3592;start=0#msg29068 date=1068772508]
I want to use quotations in a string. for Example:

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

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

Fixed.
November 14, 2003, 1:48 AM
Dyndrilliac
Now I have a whole new set of problems - whenever I put in soemthing like this:[code]wHeight = txtHeight.Text[/code] 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 : [code]Dim wHeight As Integer[/code]
November 14, 2003, 2:00 AM
Spht
[quote author=Dyndrilliac link=board=31;threadid=3592;start=0#msg29085 date=1068775220]
Now I have a whole new set of problems - whenever I put in soemthing like this:[code]wHeight = txtHeight.Text[/code] 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 : [code]Dim wHeight As Integer[/code]
[/quote]

[code]wHeight = CInt(txtHeight)[/code]

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).
November 14, 2003, 2:06 AM
iago
[quote author=Spht link=board=31;threadid=3592;start=0#msg29086 date=1068775608]
[quote author=Dyndrilliac link=board=31;threadid=3592;start=0#msg29085 date=1068775220]
Now I have a whole new set of problems - whenever I put in soemthing like this:[code]wHeight = txtHeight.Text[/code] 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 : [code]Dim wHeight As Integer[/code]
[/quote]

[code]wHeight = CInt(txtHeight)[/code]

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).
[/quote]

How's CInt different from val?
November 14, 2003, 4:05 AM
Spht
[quote author=iago link=board=31;threadid=3592;start=0#msg29096 date=1068782734]
How's CInt different from val?
[/quote]

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)).
November 14, 2003, 4:16 AM

Search