Microsoft Knowledge Base |
|
XL: Visual Basic Input # Statement May Be Parsed Incorrectly |
|
|
Last reviewed: May 30, 1997
Article ID: Q119701 |
|
5.00 5.00c 7.00 97 | 5.00 5.00a
WINDOWS | MACINTOSHkbprg kbcode The information in this article applies to:
SYMPTOMSIn Microsoft Excel, when you use the Input # statement, fields that have mixed number and text data values may be parsed incorrectly.
CAUSEWhen Microsoft Excel reads the data using the Input # statement, it guesses the data type. So, when a field begins with numbers and also contains text, the field is parsed into two entries: one numeric and one text.
RESOLUTIONTo correct this problem, do either of the following:
MORE INFORMATIONTo keep Microsoft Excel from guessing the variable type, you need to declare the variable as string in the macro. This will force Microsoft Excel to look at each entry as a text string rather than predict the variable type.
Visual Basic Code ExampleMicrosoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. The following example assumes that you have a text file called TEST.TXT, located in your current working directory. The contents of the file is as follows:
ABC Brand, 15" color television, $599In a new module sheet enter in the following code:
Sub InputExample() Dim a as String, b as String, c as String Open "test.txt" For Input Access Read Shared As #1 Input #1, a, b, c MsgBox a MsgBox b MsgBox c Close #1 End SubTo run the example, choose Start from the Run menu, or position the cursor in the line that reads "Sub InputExample()" and press the F5 key.
REFERENCESFor more information about the Input # Statement, choose the search button in Visual Basic Help and type:
Input # Statement |
|
KBCategory: kbprg kbcode
©1997 Microsoft Corporation. All rights reserved. Legal Notices. |