Solved

VB text file

Posted on 2000-04-24
9
234 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…

932 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

8 Experts available now in Live!

Get 1:1 Help Now