Solved

save to text file

Posted on 2001-06-15
10
163 Views
Last Modified: 2010-05-02
Is there any way i can save from a listbox to a text file to show my figures like this
12345 12345 12345 12345 12345
12345 12345 12345 12345 12345 etc?
0
Comment
Question by:animazoo
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 2

Expert Comment

by:kiprimshot
ID: 6195539
Im not sure if this is what you want ...

Open yourFile For Output As #1

   then loop through listbox
      Print #1, listboxvalue
   end loop

Close #1


something like this

0
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 6195544
Dim strLine As String
Dim intItem As Integer
Dim intItem1 As Integer
Dim intColumns As Integer
intColumns = 5 ' Number of columns across
Open "MyFile.txt" For Output As #1
For intItem = 0 To List1.ListCount - 1
  strLine = ""
  For intItem1 = intItem To intItem + 4
    If intItem1 < List1.ListCount Then
      strLine = strLine & " " & List1.List(intItem1)
    End If
  Next
  Print #1,strLine
Next

0
 
LVL 2

Expert Comment

by:brookman
ID: 6195545
do you want to save all entries from the listbox?


open "c:\list.txt" for output as #1
for x=0 to list1.listcount - 1
print #1,list1.list(x) & " ";
if x/5 = fix(x/5) then
print #1,""
end if
next x



0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 2

Expert Comment

by:kiprimshot
ID: 6195547
...for the loop this would work or looping through indexes

Dim X As Integer

For X = 0 To listbox1.ListCount - 1
   listbox1.Selected(X) = True
   Print #1, Listbox1.text

Next X
0
 
LVL 2

Expert Comment

by:dwalsarie
ID: 6195556
use this:

Dim Filename As String
Dim iItem As Long

Filename = "c:\output.txt"

' Overwrite existing data
Open Filename For Output As #1

' Append to existing data
Open Filename For Append As #1

For iItem = 0 To List1.ListCount - 1

  ' Print one line in the textfile
  Print #1, List1.List(iItem)

  ' Print data on same line
  ' Print #1, List1.List(iItem);

Next iItem

Close #1
0
 

Author Comment

by:animazoo
ID: 6195558
kiprim
sorry no it does not work
0
 

Author Comment

by:animazoo
ID: 6195574
done it agin thanks
0
 

Author Comment

by:animazoo
ID: 6195642
brookman
yes please
0
 

Author Comment

by:animazoo
ID: 6195648
TimCottee
i cant see any further ref to this variable in your code
intColumns = 5 ' Number of columns across
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6195654
Sorry, that should have been For intItem1 = intItem To intItem + Step intColumns - 1 rather than For intItem1 = intItem To intItem + 4
   
   
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…
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…

774 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