Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input #1 1

Status
Not open for further replies.

JDAEMS

Programmer
Aug 27, 2003
84
BE
Dear,

I have the following code:

Open strFileName for input as #1
input #1,ParentUserClass,UserClass,BranchName,BranchID

If I look at the csv file that I am opening for input, then I can see that in the field UserClass should normally come 057, but it seems that the input function recognizes this as a number and leaves out the zero, so 57 is loaded into userclass.

How can I make sure that the input function retrieves everything as a string?

Thanks.
Jelle
 
Somewhere, you are probably declaring your UserClass variable. If you declare this as an integer or long, then it will remove the leading zero. However, if you declare this as a string, then the leading zero will be preserved.

If you are not declaring this variable at all, then it is created as a variant. When the data is loaded, it CAN be a number so it's base type becomes a number.

Anyway, look where the UserClass is created and change it to a string. If you can't find the variable initialized anywhere, then initialize it yourself, like this...

Code:
   [red]Dim UserClass As String[/red]

   Open strFileName for input as #1
   input #1,ParentUserClass,UserClass,BranchName,BranchID

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
If you declare the variables as strings (e.g.
Code:
Dim ParentUserClass As String
Dim UserClass As String...
) then they should be populated with the values you require.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Just beat me there George... [wink]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
2 whole minutes. What'sa madder? Gettin old? [bigsmile]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Haha, I'm almost catching you mate [wink]

One thing I did forget to include in my post (which would have made it even later than it was!) is to point the OP to do some research on the OPTION EXPLICIT keyword and some reading around variable declaration (which you did touch on in your reply).



HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
JDAEMS,

There is another potential problem with your code. You may not ever be affected by this problem, but I thought I should point it out. You shouldn't be hardcoding your file number within your code. Like I said, it will probably work most of the time, but on occasion, may give you an error. Instead, you should use FreeFile to get an available file handle. It's safer, and saves you from this potential problem.

Code:
   Dim UserClass As String
[!]   Dim iFile as Integer

   iFile = FreeFile[/!]

   Open strFileName for input as #[!]iFile[/!]
   input #[!]iFile[/!],ParentUserClass,UserClass,BranchName,BranchID

   Close #[!]iFile[/!]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
There's always the FileSystemObject. The Fso has always been a great and stable way to read/write files.

--------------------------------------------------
"...and did we give up when the Germans bombed Pearl Harbor? NO!"

"Don't stop him. He's roll'n."
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top