Solved

save to text file

Posted on 2001-06-15
10
168 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses
Course of the Month5 days, 18 hours left to enroll

627 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