Solved

VB text file

Posted on 2000-04-24
9
239 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Script Host failed (Access is denied.) error 6 440
message box in access 4 55
how to know if my Checkbox is True in VB6.0? 9 68
Automatic Email Reminder 4 92
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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

738 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