Results 1 to 8 of 8

Thread: Removing apostrophe from text string

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Removing apostrophe from text string

    I have a program that queries a database and loads data into a DataGridView. From there, I have a button that copies the datagrid data onto the clipboard where I can paste it into an Excel spreadsheet.

    The issue I'm having is with my date fields. Here's what's going on. I have a data reader and as I loop through that I put the fields into a dataset. So, for the birthdate I have this:

    Code:
      anyRow("DOB") = "'" & Format(ERDataReader.Item("Birthdate"), "MMddyyyy").ToString
    This works as I would expect and places a date in the datagridview like "02031927". The problem is that it for some reason puts: '02031927. Note the apostrophe in front.

    I want the date exactly like it is, just without the apostrophe. How do I accomplish this?

    In a similar vein, I have a field called "Visit Type" which is supposed to be 3 characters long (e.g. 002). I format this field accordingly and it looks perfect in the DataGridView:

    Code:
     anyRow("LOS") = Format(DataReader.Item("LOS"), "000").ToString.PadLeft(3, "0")
    If I copy the datagridview contents to the clipboard and paste into Excel, a value like 003 is converted to just 3. How do I maintain the leading zeros?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Removing apostrophe from text string

    Excel needs the apostrophe... otherwise it will treat it as a number... which you don't want (you'll lose the leadong zero if you do) ... since you're setting a string with a numeric value, in order to preserve the value, Excel puts an apostrophe on the front of it. That's also why you get 3 instead of 003 ...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: Removing apostrophe from text string

    Interesting... did not know that.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Removing apostrophe from text string

    try it... open excel, select any cell... enter 003 ... in the next cell enter '003 ... and look at the difference.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: Removing apostrophe from text string

    Tried some different cell formats... Excel really doesn't like numbers stored as text. Seems to always squawk about it.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Removing apostrophe from text string

    You sound surprised. Of course it doesn't. It's a number crunching spreadsheet system... it was meant to do calculations and deal with numbers.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: Removing apostrophe from text string

    It's not that surprising. It's just that I've seen so many folks use excel for things other than numbers, or for a mix of text and numbers.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Removing apostrophe from text string

    Yeah, like a lot of office applications it often gets misused.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width