Converting Numbers to Single Quotes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chopin
    New Member
    • Mar 2007
    • 37

    Converting Numbers to Single Quotes

    I am using Visual Basic for Applications to convert a number to the same number of single quotes. For example, if the number is 6, then I need 6 single quotes in succession. The logic is easy:

    Code:
    Dim strOctave As Integer, strOctaveNew as String
    If strOctave = "6" Then
    strOctaveNew = "    ' ' ' ' ' '    "
    End If
    Above code does not work, but the logic is correct. I need the code to replace the "6" with ' ' ' ' ' '

    The below code DOES work for letters though:

    Code:
    Dim strOctave As Integer, strOctaveNew as String
    If strOctave = "6" Then
    strOctaveNew = "aaaaaa"
    End If
    So, the code will replace the number "6" with "aaaaaa"

    My logic works only if I use characters, but does not work if I use single quotes. I need single quotes to replace the number, this is important. Is there is some kind of data type I need to use for single quotes other than "string?"
  • cyberking
    New Member
    • Jan 2007
    • 84

    #2
    Originally posted by chopin
    I am using Visual Basic for Applications to convert a number to the same number of single quotes. For example, if the number is 6, then I need 6 single quotes in succession. The logic is easy:

    Code:
    Dim strOctave As Integer, strOctaveNew as String
    If strOctave = "6" Then
    strOctaveNew = "    ' ' ' ' ' '    "
    End If
    Above code does not work, but the logic is correct. I need the code to replace the "6" with ' ' ' ' ' '

    The below code DOES work for letters though:

    Code:
    Dim strOctave As Integer, strOctaveNew as String
    If strOctave = "6" Then
    strOctaveNew = "aaaaaa"
    End If
    So, the code will replace the number "6" with "aaaaaa"

    My logic works only if I use characters, but does not work if I use single quotes. I need single quotes to replace the number, this is important. Is there is some kind of data type I need to use for single quotes other than "string?"
    Hi,

    Try this, but I am not sure. Dont have my VB studio with me now.

    Dim strOctave As Integer, strOctaveNew as String
    If strOctave = "2" Then
    strOctaveNew = " (') " + " (') "
    End if

    If this does not work, try without the paranthesis.

    Regards
    CyberKing

    Comment

    • chopin
      New Member
      • Mar 2007
      • 37

      #3
      That still doesn't work. Works for all characters, even the question mark. Let me be a little clearer with the code. I am using this in Access, using DAO. Here is the watered down version:

      Code:
      Dim strOctave As Integer, strOctaveNew as String
      .
      .
      .
      .
      Do Until rst.EOF
      strOctave = rst!Octave
      
      [B]If strOctave = "2" Then
      strOctaveNew = " (') " + " (') " [I]Does't work with or without parenthesis[/I]
      End if[/B]
      
      rst.MoveNext
      Loop
      The bold code is what I need to get working. I still can't seem to figure out why single quotes are giving me problems....It produces wacky output, and I can't understand where the output is comming from.

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        Your original code works for me, but I would use the String function instead. Here's what works for me:
        Code:
        		strOctaveNew = String(6, "'")
        		MsgBox strOctaveNew
        		strOctaveNew = "''''''"
        		MsgBox strOctaveNew

        Comment

        • Geoff
          New Member
          • Feb 2007
          • 17

          #5
          I'm not sure about this as I've not got access to Visual Basic at the moment, but ' is the symbol to start a comment, so where ever a ' is in the line of code it's converted into commenting instead. This would explain why you're getting the problem you are.

          If this is the reason, then there is no way around it as far as I know.

          If it isnt then there is a simple solution for any number you desire,
          Code:
          Private Sub Form_Load()
           Dim intNumber, intA as Integer
           On Error goto errhandler
           intNumber = Inputbox("Please enter a number")
           For intA = 1 to intNumber
            lblDisplay.Caption =  lblDisplay.Caption & " ' "
           Next intA
           Exit Sub
           errhandler:
           Msgbox"The entered data is invalid"
          End Sub
          Pretty sure that'll work for you.

          Comment

          Working...