Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Novice question about listbox and query

Status
Not open for further replies.

osorio

MIS
Jul 8, 2001
7
VE
Hello. I am trying to do a simple database where I input two things (name and phone number) and this appears in a listbox. However I am a very novice programmer, and have a lot of questions.
a) How do I make this information store in my hard drive, so when I run the program again every information that has been stored is still there? I have read some forums related to this and they talk a lot about querys, but I don´t know how to use them.
b) How can I take information from a form (contents of a listbox, for example) and bring it to another form?
thank you very much
 
I am assuming that you already know how to add items to a list box and find out whats in it through code.

-to store the list on your HD, you would have to write to a file and to put it back in the list box, you would have to read from the file.
-to write to a file: you would first open it (if it does not exist, VB would create it for you.) by typing:

Open "path" for output as #x
-x is a number assigned to the file by you.
then you would have a loop where you take the list items and write them to the file using:

write #x, variablename, variablename2...

after the loop, you close it by typing

Close #x
 
I am assuming that you already know how to add items to a list box and find out whats in it through code.

-to store the list on your HD, you would have to write to a file and to put it back in the list box, you would have to read from the file.
-to write to a file: you would first open it (if it does not exist, VB would create it for you.) by typing:

Open "path" for output as #x
-x is a number assigned to the file by you.
then you would have a loop where you take the list items and write them to the file using:

write #x, variablename, variablename2...

after the loop, you close it by typing

Close #x

God bless
 
after storing the contents of the listbox to the HDD, you might to need to reload it after the application restarts. to do this, you can use the following code:

open "filename" for input as #x

where x is the file number

do until eof(x)
line input #1, variablename
lstbox1.additem variablename
loop

to reference the contents of a listbox from another form, you can use this:

a) to reference a selected item in the listbox

form1.lstbox1.list(lstbox1.listindex)

b) to reference the entire contents of the listbox

for i = 0 to form1.lstbox1.listcount-1
form2listbox.additem form1.lstbox1.list(i)
next

arcanist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top