455,096 Members | 1,348 Online
Need help? Post your question and get tips & solutions from a community of 455,096 IT Pros & Developers. It's quick & easy.

# Converting Numbers to Single Quotes

 P: 37 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: Expand|Select|Wrap|Line Numbers 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: Expand|Select|Wrap|Line Numbers 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?" Mar 23 '07 #1
4 Replies

 P: 84 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: Expand|Select|Wrap|Line Numbers 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: Expand|Select|Wrap|Line Numbers 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 Mar 23 '07 #2

 P: 37 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: Expand|Select|Wrap|Line Numbers Dim strOctave As Integer, strOctaveNew as String . . . . Do Until rst.EOF strOctave = rst!Octave   If strOctave = "2" Then strOctaveNew = " (') " + " (') " Does't work with or without parenthesis End if   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. Mar 23 '07 #3

 Expert 100+ P: 807 Your original code works for me, but I would use the String function instead. Here's what works for me: Expand|Select|Wrap|Line Numbers         strOctaveNew = String(6, "'")         MsgBox strOctaveNew         strOctaveNew = "''''''"         MsgBox strOctaveNew   Mar 23 '07 #4

 P: 17 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, Expand|Select|Wrap|Line Numbers 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. Mar 23 '07 #5