Results 1 to 8 of 8

Thread: [RESOLVED] list box help!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Resolved [RESOLVED] list box help!

    if you look at the picture below, i have a listbox which is connected to a database, the database stores a name and an ip address.
    Is there another way of doing this without using the database as it wont work. i need to be able to add workstations and remove them.
    I would also like the code so that when a name from the list box is selected it will show the ip adress in the IP textbox.
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: list box help!

    Rather than a database, why not save the list in a file?

    And rather than a listbox, why not use a listVIEW? You could have a column for the name and another for the IP address
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: list box help!

    I would store it in a flat text file. No need for a database with something like this.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: list box help!

    pls could you explain how to do this as i have never used a listVIEW or written to a text file

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: list box help!

    Quote Originally Posted by chris1990
    pls could you explain how to do this as i have never used a listVIEW or written to a text file
    I'm writing an example for you.

  6. #6
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: list box help!

    I'll let someone else explain listview, I've still not got my head around them...they're a lot more flexible than listboxes though :-)

    Loading and saving to a text file is a simple matter, firstly you need to open the file
    VB Code:
    1. Open "filename" for Input as #1
    Replace the Input with Output if you want to save rather than load (Input is load). Also, some people (me included) suggest not using a static value for the file number (in this case, 1)...I've kept it simple for you. When you're used to loading/saving ask for a better way and we'll give it :-)

    Now you need to input/write something
    VB Code:
    1. Input #1, datastring
    Obviously "datastring" is the variable...this inputs a part of the textfile to the variable "datastring". Change Input to Print to write to the file.
    VB Code:
    1. Close 1
    This closes the file and ensures that it is saved properly (if you're saving) or available for use (if loading)

    If you need to load/save multiple parts, you just enclose it in a loop of some sort (your choice, for/next, do/loop whatever). Most people put a "Do" before and a "Loop while not EOF(1)" after...EOF is End Of File and this basically loops until the file is at the end then closes...it's up to you to make sure each loaded/saved item is different each time it loops (put a variable number in there somewhere and increment it :-))

    For instance, if you're saving address(1) to address(10) to "addresses.txt" you'd do:
    VB Code:
    1. fre = FreeFile 'Note I added this...this is the trick I told you about
    2. Open "addresses.txt" for Output as #fre
    3. For b = 1 to 10
    4. Print #fre, address(b)
    5. Next b
    6. Close 1
    Now loading it back
    VB Code:
    1. fre = FreeFile 'Note I added this...this is the trick I told you about
    2. Open "addresses.txt" for Input as #fre
    3. b=0
    4. Do
    5. b=b+1
    6. Input #fre, address(b)
    7. Loop while not EOF(fre)
    8. Close fre

    Edit: This has been bugging me for AGES...I *knew* I made the mistake of putting "Close 1" in the load back where it should be "Close fre"...corrected :-)
    Last edited by smUX; Jan 12th, 2007 at 11:59 AM.
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  7. #7
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: list box help!

    Store it in a textfile with delimiters a new line or tab.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: list box help!

    Quote Originally Posted by chris1990
    Is there another way of doing this without using the database as it wont work.
    This is exactly what I would do. Why won't it work?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width