Solved

Working with Files

Posted on 2000-04-30
7
132 Views
Last Modified: 2010-05-18
I have a array and want to save it in file but without space between each field.
See my source.
Open TochkiOut For Output As #1
    For i = 1 To n
Print #1, masiv(i, 1), ",", masiv(i, 2), ",", masiv(i, 3), ",", masiv(i, 4), ",", masiv(i, 5), ",", masiv(i, 6), ",", masiv(i, 7), ",", masiv(i, 8), ",", masiv(i, 9)
    Next i
Close #1

I want to have this kind of orientation ot text.
1,100,100,100 .........
Without space between arrays.
Thanks
0
Comment
Question by:Nick1_bg
7 Comments
 
LVL 7

Accepted Solution

by:
Vbmaster earned 50 total points
ID: 2763852
You can use & instead of ',' between the elements like this..

Print #1, masiv(i, 1) & "," & ...
0
 

Expert Comment

by:flench
ID: 2763853
Put in place of a "," character, a ";" between the arrays values.

Example :

Print #1, masiv(i, 1); ","; masiv(i, 2); ","; masiv(i, 3); ","; masiv(i, 4); ","; masiv(i, 5); ","; masiv(i, 6); ","; masiv(i, 7); ","; masiv(i, 8); ","; masiv(i, 9)

You can also convert the arrays numbers into string, and then use the "Format" function to print the correct value.

Example : Format(<string)

   
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2763867
Concatenating the array element with the '&' character is better than using the approach recommended by flench because '&' will create one 'large' string in memory and then save this string to disk 'at once', instead of having to communicate with the disk for every element a'la using ';'. Harddisk access is slow - memory is fast(er).
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 14

Expert Comment

by:wsh2
ID: 2765249
It sounds like you just want a standard CSV file which is very portable from application to application. To do this simply, you want to use the Write # statement, rather than the Print #. The Write # will automatically add commas and place double quotes around string Text if it is present. To write your whole table would then look like this..

Open TochkiOut For Output As #1
For x = 1 To xLimit
   Write #1, _
       masiv(x,1), _
       masiv(x,2), _
       masiv(x,3), _
       masiv(x,4), _
       masiv(x,5), _
       masiv(x,6), _
       masiv(x,7), _
       masiv(x,8), _
       masiv(x,9)
Next x
Close #1

To Read it back in use:

Open TochkiOut For Input As #1
For x = 1 To xLimit
   Input #1, _
       masiv(x,1), _
       masiv(x,2), _
       masiv(x,3), _
       masiv(x,4), _
       masiv(x,5), _
       masiv(x,6), _
       masiv(x,7), _
       masiv(x,8), _
       masiv(x,9)
Next x
Close #1

This will give you a CSV file that is portable from apllication to application. One cautionary note though, if you are writing strings that have a double quote in them.. ie Chr(34).. you want to first double them up inside the string (ie "" -or- chr(34)chr(34)) before writing, so that they are read and processed properly.

0
 
LVL 1

Author Comment

by:Nick1_bg
ID: 2765614
I will accept the answer of VBMASTER
0
 
LVL 1

Author Comment

by:Nick1_bg
ID: 2765617
Thansk VBMASTER :-))
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2765891
Glad I could help.
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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now