Solved

VB text file

Posted on 2000-04-24
9
238 Views
Last Modified: 2010-05-02
How can I write a text file that has a length less than 256 using the VB print# statement?
0
Comment
Question by:davidgky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 1

Expert Comment

by:RichardA
ID: 2745358
If you use the print# statement VB will only write the text that is specified in the statement.

example

Dim nFile As Integer

nFile = FreeFile

Open App.Path & "\data.txt" For Output As #nFile
Print #nFile, "TEST"
Close #nFile

This should create an output file that ig 6 bytes long (it will have a carridge return/line feed characters entered)

What code are you using that gives 256 char output??
0
 
LVL 3

Expert Comment

by:DrMaltz
ID: 2746191
Use the LOF to determine how many characters exist in a file..
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2746712
RichardA:
As you are new here.. unless the answer is obvious and with no other solution.. it is customary to leave a comment, rather than an answer. The fact that you write "What code are you using that gives 256 char output?".. indicates that your answer is not conclusive. Nevertheless, you are correct in your question, as the problem identified by the questioner is quite unclear.. <smile>.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:RichardA
ID: 2746930
I agree the answer is to obvious.  What code are you using tht puts a 256 char string out??
0
 

Accepted Solution

by:
Psy earned 200 total points
ID: 2747877
private sub CharSave
Dim pathandname As String
dim recordsize as long
dim MyData as variant

  pathandname = App.Path & "\MyData.txt"
  recordsize=256
  MyData = "What you want"

  Open pathandname For Binary Access Write As #99
        Put #99, recordsize, MyData
    Close #99

end sub


put:

Writes data from a variable to a file.

Put [#]filenumber, [recnumber], varname

/filenumber have to be between 1 and 99/

Okay. The recordnumber is a littlebit tricky because it can be a user-type or anything (almost). :)
0
 

Expert Comment

by:Psy
ID: 2747883
If you must use print, first you have to check (and maybe modify) the writable data's size (fill with spaces etc.).

like:

dim s as string
dim x as long

 s = "String Size is 17"
 x = Len (s)

etc...
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2748142
Psy:
While your answer is very clear.. (as was RichardA's).. the question certainly is not. In cases like this, it is customary on EE to comment, until the questioner clarifies their intention. As such, please change your answer to a comment.. <smile>.
0
 

Expert Comment

by:Psy
ID: 2750711
wsh2:

???
0
 
LVL 1

Expert Comment

by:csameer1
ID: 2848600
try the fileSystemObject for such operations.It is a neat way.

You can search vb help for that

1)you need windows scriping host on the system(is thr by dflt)
2)for now works with text file only,dont try bmp
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

740 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