• Welcome to Valhalla Legends Archive.
 

Quotations in Strings

Started by Dyndrilliac, November 13, 2003, 07:15 PM

Previous topic - Next topic

Dyndrilliac

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?
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

K

#1
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

iago

#2
eww..

msgbox "Hello ""VB"" world!" is by far the best.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Grok

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.

Dyndrilliac

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
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Spht

#5
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).

iago

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?
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Spht

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)).