|
-
Mar 22nd, 2000, 05:48 PM
#1
Thread Starter
Hyperactive Member
Save textbox and listbox in one file (VB3)
In my programm there's listlox (List1), which I can save in
a Text-File. Now I want to add a textbox, in which the user
can write his name or something else. Now I want, that
this textbox is the first line of the textfile and the following lines are from the listbox.
1. How is the code for saving it ?
2. How must I write the code, that the first line gets
into a textbox and the rest into the listbox when I open the
file ?
For this programm I use VB 3.0 (but normally this isn't a problem)
Thanks for some advice, Matt
[Edited by Matt-D on 03-23-2000 at 10:45 AM]
-
Mar 22nd, 2000, 10:09 PM
#2
Fanatic Member
Hi Matt-D.
If I understand your questions correctly, this code should do the trick. To test it, create a new project with a textbox, listbox and a command button.
Code:
Option Explicit
Private Sub Command1_Click()
Dim iCounter As Integer
Open "c:\windows\desktop\myfile.txt" For Output As #1
Write #1, Text1
For iCounter = 0 To List1.ListCount - 1
Write #1, List1.List(iCounter)
Next iCounter
MsgBox "All Done"
End Sub
Private Sub Form_Load()
List1.AddItem "one"
List1.AddItem "two"
List1.AddItem "three"
End Sub
If you need more help, just re-post.
All the best.
-
Jan 12th, 2009, 02:12 PM
#3
New Member
Re: Save Textbox and Listbox in one file (VB3)
first put the text file into the listbox
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
OpenFileDialog1.Filter = "Text Files (*.TXT)|*.TXT" 'looks for files ending in TXT
OpenFileDialog1.ShowDialog() 'Common dialog
If OpenFileDialog1.FileName <> "" Then 'Is there a real filename
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) 'if so open the file for input
Call ReadFile() 'a subroutine to read the file
End If
On Error Resume Next
FileClose()
End Sub
-------------------
Sub ReadFile()
While Not EOF(1)
ListBox1.Items.Add(LineInput(1)) 'text items in file go into listbox
End While
End Sub
--------------------------------
hope this helps
-
Jan 12th, 2009, 04:44 PM
#4
Re: Save textbox and listbox in one file (VB3)
 Originally Posted by Matt-D
In my programm there's listlox (List1), which I can save in
a Text-File. Now I want to add a textbox, in which the user
can write his name or something else. Now I want, that
this textbox is the first line of the textfile and the following lines are from the listbox.
1. How is the code for saving it ?
2. How must I write the code, that the first line gets
into a textbox and the rest into the listbox when I open the
file ?
For this programm I use VB 3.0 (but normally this isn't a problem)
Well the procedure is the same whether is VB3/4/5 or 6. As explained by OneSource.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jan 12th, 2009, 06:59 PM
#5
Re: Save Textbox and Listbox in one file (VB3)
It's almost 9 years later - I really hope he doesn't actually care about this any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|