Solved

Extra characters in file contents

Posted on 2014-10-03
17
109 Views
Last Modified: 2015-04-23
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?
0
Comment
Question by:isnoend2001
  • 9
  • 5
  • 3
17 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40360495
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
 

Author Comment

by:isnoend2001
ID: 40360540
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
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40360571
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
 

Author Comment

by:isnoend2001
ID: 40360620
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
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40360627
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
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40360630
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
 

Author Comment

by:isnoend2001
ID: 40360635
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
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40360661
Can you post the code that fills the array?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:isnoend2001
ID: 40360677
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
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40360684
did you try my suggestion?

What format do you want the file?
0
 

Author Comment

by:isnoend2001
ID: 40360686
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
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40360689
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
 

Author Comment

by:isnoend2001
ID: 40360734
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
 

Author Comment

by:isnoend2001
ID: 40360889
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
 

Author Comment

by:isnoend2001
ID: 40360893
The project is attached
Get-Bids.zip
0
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 40360974
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
 

Author Closing Comment

by:isnoend2001
ID: 40361225
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now