Extra characters in file contents

debug array contents

C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Painting Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\BathRoom Remodle Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\New Lawn Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Fencing Bids
Array contents file viewed in notepad

h C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Painting Bidsp C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\BathRoom Remodle Bidsh C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\New Lawn Bidsg C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Fencing Bids                                  ers.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Painting Bidsp C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\BathRoom Remodle Bidsh C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\New Lawn Bidsg C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Fencing Bids  

File save Sub
Dim ff As Integer
ff = FreeFile
myFile = mstrOwnerNameAddress & "\ArrCboCatagorys.dat"
        Open myFile For Binary As #ff
         Put #ff, , mArrProjects
         Close #ff

  In viewing the file contents there is an extra character at the end of each array item
And a blank space in one area
What could be causing this?
isnoend2001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
In viewing the file contents there is an extra character at the end of each array item
And a blank space in one area
Please explain further what you mean by that.
0
isnoend2001Author Commented:
Thanks martinLiss
I am trying to determine what could cause the extra character and the blank space.
The path in mstrOwnerNameAddress:
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way  

The Sub that adds the items to the array:
Sub AddFromCboToArray()
        Dim i As Integer
        For i = 0 To Me.cboBids.ListCount - 1
        mArrProjects(i) = mstrOwnerNameAddress & "\" & cboBids.List(i)
        'Debug.Print mArrProjects(i)
        Next
End Sub
0
Martin LissOlder than dirtCommented:
So where exactly does the extra character or space occur? Does it occur t the end of "C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way"? And do you care where it comes from as long as you can get rid of it?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

isnoend2001Author Commented:
there is a h  at the very start of the file(see file contents above in bold) and then a extra  character at the end of each array item
cbo contents
0
Martin LissOlder than dirtCommented:
I think the only way I can help you is if you can attach your project and explain exactly how to reproduce the problem.
0
ChloesDadCommented:
Its probably because you are saving the file as binary, it is probably an end of record marker or something similar.

If you just want a text file with one array item on each lines then you would need to write it out line by line

Dim ff As Integer
Dim Count1 as integer
 ff = FreeFile
 myFile = mstrOwnerNameAddress & "\ArrCboCatagorys.dat"
         Open myFile For output As #ff
          For Count1 = 1 to UBound(mArrProjects)
            Print to #ff, mArrProjects(Count1-1)
           Next Count1
          Close #ff

Open in new window

0
isnoend2001Author Commented:
each item in the array is the full path to the selected item in the combobox eg;
if a user clicks an item in the combo box it will get the full path from the array.
Have stopped coding when i noticed this issue until i can determine a fixpathspaths
0
Martin LissOlder than dirtCommented:
Can you post the code that fills the array?
0
isnoend2001Author Commented:
Thanks MartinLiss
Already did again:
Sub AddFromCboToArray()
        Dim i As Integer
        For i = 0 To Me.cboBids.ListCount - 1
        mArrProjects(i) = mstrOwnerNameAddress & "\" & cboBids.List(i)
        'Debug.Print mArrProjects(i)
        Next
End Sub
0
ChloesDadCommented:
did you try my suggestion?

What format do you want the file?
0
isnoend2001Author Commented:
thanks ChloesDad
Your code with modification seems to work:
Dim i As Integer
Dim myFile As String
Dim ff As Integer
ff = FreeFile
myFile = mstrOwnerNameAddress & "\ArrCboCatagorys.dat"
       Open myFile For Output As #ff
          For i = LBound(mArrProjects) To UBound(mArrProjects)
            Print #ff, mArrProjects(i)
           Next
          Close #ff
 

Open in new window

But I am not ready to abandon binary as other code uses binary
0
Martin LissOlder than dirtCommented:
OK sorry about that. See if this gets rid of the characters at the end.

Sub AddFromCboToArray()
        Dim i As Integer
        Dim strTemp As String
        For i = 0 To Me.cboBids.ListCount - 1
        strTemp = Replace(mstrOwnerNameAddress & "\" & cboBids.List(i),"g","")
        strTemp = Replace(strTemp,"h","")
        mArrProjects(i) = strTemP
        'Debug.Print mArrProjects(i)
        Next
End Sub
0
isnoend2001Author Commented:
MartinLiss
The is not in that part of the code, it only developments when the array is saved:
 this Debug.Print mArrProjects(i)
produces this:
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Painting Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\BathRoom Remodle Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\New Lawn Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Fencing Bids
no extras, no missing content
0
isnoend2001Author Commented:
I changed the save path to App.Path and it still puts characters at the end of each item in the array.
Difference is they are different characters and their is no space in the middle of the file

Saved File viewed in notepad:
W C:\Program Files\Microsoft Visual Studio\VB98\Get Bids\Smith 1247 Oak Ave\Painting Bids_ C:\Program Files\Microsoft Visual Studio\VB98\Get Bids\Smith 1247 Oak Ave\BathRoom Remodle BidsW C:\Program Files\Microsoft Visual Studio\VB98\Get Bids\Smith 1247 Oak Ave\New Lawn BidsV C:\Program Files\Microsoft Visual Studio\VB98\Get Bids\Smith 1247 Oak Ave\Fencing Bids
0
isnoend2001Author Commented:
The project is attached
Get-Bids.zip
0
ChloesDadCommented:
Binary files are not text files and hence are saved differently. This difference is causing the extra characters that you see.

Taken from this article http://www.dreamincode.net/forums/topic/56171-file-handling-in-visual-basic-6-part-2-binary-file-handling/

Unlike other languages, VB does not store strings in ASCII format. The string
"ABCD" is stored in VB like this:
[ 00 08 65 00 66 00 67 00 68 00 ]
The first two bytes contain the length of the following string. The latter
portion of the string uses 2 bytes for every character. Hence the trailing zeros
for every character.

so as the first string
"C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Painting Bids"
is 104 characters, the file starts with [0 104]  and character 104 is 'h'

If you want to keep the file as Binary then you have to accept those extra characters. If you don't want those extra characters then you have to use a simple text file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isnoend2001Author Commented:
Thanks ChloesDad
That explains the problem
After more testing The file seems to read correctly, so for now i will not worry about it, will just keep it in mind in case of problems.
The file only keeps track of paths to cbo items the actual data saved to theses files is binary
This data will be put into the proper file:
ArrayDim = UBound(RoofCompany)
      Open MyFile For Binary As #FF
        Put #FF, , ArrayDim
        Put #FF, , RoofCompanyTotal
        Put #FF, , RoofCompany
      Close #FF
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.