Solved

VB text file

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

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

9 Experts available now in Live!

Get 1:1 Help Now