?
Solved

VB text file

Posted on 2000-04-24
9
Medium Priority
?
241 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

743 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