+ Reply to Thread
Results 1 to 7 of 7

Input # Problem

  1. #1
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Input # Problem

    Hi folks,

    I am maintaining a program which reads through a pre-prepared CSV file using Input #. The first line of the CSV file contains field names, one of which has recently been changed from "Protection Type" to "1st Protection Type". For some reason VBA simply returns the number 1 instead of the full string.

    I find this strange, since within the subsequent data lines there are many alphanumeric fields which begin with numbers and they are all read correctly.

    Before I start making wholesale changes to the software (plan is to either use Line Input # and parse each line manually, or import the entire CSV file and move the data using an array) does anyone know if there is a way around this behaviour?

    Cheers

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Input # Problem

    can you show some of the code you actually use, including variable declaration.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Input # Problem

    Hi Andy,

    Was loath to do so, simply for embarrassment's sake as it's someone else's code and quite shoddy! I'm not entirely sure why they've done it this way instead of just importing the file, but it's part of a very large project with many global variables, some of which are set by this Sub. Further data is added by other subs.

    Also, a slight change to my OP... It turns out the field in question ("1st Protection Type") isn't being read simply as the number 1, but being split into two parts - the first containing "1" and the second containing "Protection Type", with the interceding "st " being treated as if it were a delimiter.

    My comments (referenced in the code)

    1: "pathIn" is a global variable set at startup which points to a source directory
    2: "shtS.getVal" is a Function which returns a filename string from a table (contained on that sheet)
    3: "tRowMax" & "tColMax" are global variables which retain the row/column extent of the imported data, including title rows.

    Please Login or Register  to view this content.
    As I said before, the ONLY thing which has changed is the source data.

    Sample source data (BEFORE the change):
    Please Login or Register  to view this content.
    Sample source data (AFTER the change):
    Please Login or Register  to view this content.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Input # Problem

    The code works for me. 1st Protection Type is in O2.

  5. #5
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Input # Problem

    In that case I inadvertently fixed it when I added the variable declarations at the top of the Sub. These were not there before, so cTitle was being initialised as a Variant, presumably causing the problem.

    Thanks for your time, and sorry to have wasted it!

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Input # Problem

    Yep, if I make it a variant it does as you described.

    Not a waste, it's why I asked you to post the code as I thought variables might be the problem.

  7. #7
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Input # Problem

    That's true, thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1