Solved

Working with Files

Posted on 2000-04-30
7
138 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
[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
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

690 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