473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Converting Numbers to Single Quotes

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
  1. Dim strOctave As Integer, strOctaveNew as String
  2. If strOctave = "6" Then
  3. strOctaveNew = "    ' ' ' ' ' '    "
  4. 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
  1. Dim strOctave As Integer, strOctaveNew as String
  2. If strOctave = "6" Then
  3. strOctaveNew = "aaaaaa"
  4. 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 1441
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
  1. Dim strOctave As Integer, strOctaveNew as String
  2. If strOctave = "6" Then
  3. strOctaveNew = "    ' ' ' ' ' '    "
  4. 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
  1. Dim strOctave As Integer, strOctaveNew as String
  2. If strOctave = "6" Then
  3. strOctaveNew = "aaaaaa"
  4. 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
chopin
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
  1. Dim strOctave As Integer, strOctaveNew as String
  2. .
  3. .
  4. .
  5. .
  6. Do Until rst.EOF
  7. strOctave = rst!Octave
  8.  
  9. If strOctave = "2" Then
  10. strOctaveNew = " (') " + " (') " Does't work with or without parenthesis
  11. End if
  12.  
  13. rst.MoveNext
  14. Loop
  15.  
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
SammyB
807 Expert 512MB
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
  1.         strOctaveNew = String(6, "'")
  2.         MsgBox strOctaveNew
  3.         strOctaveNew = "''''''"
  4.         MsgBox strOctaveNew
  5.  
Mar 23 '07 #4
Geoff
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
  1. Private Sub Form_Load()
  2.  Dim intNumber, intA as Integer
  3.  On Error goto errhandler
  4.  intNumber = Inputbox("Please enter a number")
  5.  For intA = 1 to intNumber
  6.   lblDisplay.Caption =  lblDisplay.Caption & " ' "
  7.  Next intA
  8.  Exit Sub
  9.  errhandler:
  10.  Msgbox"The entered data is invalid"
  11. End Sub
Pretty sure that'll work for you.
Mar 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jakanapes | last post by:
Hi all, I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes ('). I'm using PHP to pull text out of a mySQL table and then feed the text into...
25
by: TK | last post by:
I'm used to programming in c or c++ in which my problem is simple. I want to be able to enter a value on a page (like 3.2), and then read it as a 32-bit float and break it into it's individual...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
7
by: RCS | last post by:
Okay, a rather 'interesting' situation has arisen at a place I work: I need to convert a database from Access to something that can be used over the web. I am currently maintaining and...
2
by: Benjamin Rutt | last post by:
Does anyone have C code laying around to do this? I have to read in some binary data files that contains some 4-byte IBM/370 floating point values. I would like a function to convert 4-byte...
1
by: desi.american | last post by:
I have a dynamically generates ASPX page with tables and data. Depending on user selection, the same page can be viewed as a simple web page (rendered in HTML) or as an excel spreadsheet. If the...
7
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards...
5
by: Patti | last post by:
I am struggling with converting a certain varchar column into an int. I have a table that has 2 fields - one field holds the loan number and the other field holds the codes associated with that...
3
by: jim | last post by:
Does anyone know why the query below would return numbers? I'm attempting to produce a report that shows in *one* column the names that appear in multiple columns in a single table. Table Name:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.