storing data in listbox
storing data in listbox
storing data in listbox
storing data in listbox
storing data in listbox
storing data in listbox storing data in listbox storing data in listbox storing data in listbox storing data in listbox storing data in listbox storing data in listbox storing data in listbox
storing data in listbox storing data in listbox
storing data in listbox
Go Back  Xtreme Visual Basic Talk > > > storing data in listbox


Reply
 
Thread Tools Display Modes
  #1  
Old 05-17-2004, 08:19 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Default storing data in listbox


i will make this plain and simple. i am very new to this. i dont know anything but moving the forms around the designer box. i am trying to make a simple password organizer program, and i got the interface all ready, but now comes the coding. i want to know how to make it so that when i click the "add account" button, it pops up a window that says "please enter a user name and password" then there will the 2 text boxes, one for use name, and one for password. also, a ok and cancel button. then when u fill it out, and click ok, it adds what u just typed to the list box.

i dont know if thats hard to do or not, or if you need to make it write a text file (preferably not, cuz that would defeat the whole purpose of this app), but i would just like someone to point me in the write direction instead of telling me to get a book and read about code. i find that you learn better if you do things, than if you know things. because, anyone can say that they have read about how to ride a bike, but they dont really know how until they have done it.

well, i tried to make it short :\
any help is usefull, thx.

maTT.
Reply With Quote
  #2  
Old 05-17-2004, 09:26 PM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Well, first of all, have you created the new window that says "please enter a user name and password" and the 2 text boxes, one for use name, and one for password. also, a ok and cancel button.
If you go to File -> Add New Item, you can add another form to your project.
Once you have that, we'll keep going.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 05-18-2004, 01:11 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Default hmm

ok, i did that, now what....i think this is where the coding begins

Last edited by Spout; 05-18-2004 at 01:21 PM.
Reply With Quote
  #4  
Old 05-18-2004, 03:39 PM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Yup.
(Actually, I hope you have two listboxes if you are planning on storing the name and the password in a listbox).

First, in your old form, double-click on the "Add Account" button. That should take you to the code window.

In the add account button, you want to show the form and then get the information from the form (namely, the username and the password).
To show the form, you need to create it first:
Dim F2 As Form = New Form2 'Creates the form.
F2.ShowDialog() 'Shows the form. (Dialog means it is modal).

To get the information:
F2.Username
and F2.Password

You will use ListBox.Items.Add to add those to the listbox.

On Form2, double-click on the OK button...
assign the values in the textboxes to username password:
Username = TB.Text
Password = TB2.Text

Also, scroll up the code window to the Inherits System.Windows.Forms
and declare Public Username, Password As String so that you can access them from the other form.

That should be all you need.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 05-19-2004, 01:10 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Default

hmm i dont quite understand where to put the code. this is what i get when i double click the "add accoutn" button.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

End Class


__________________
-spouT
Reply With Quote
  #6  
Old 05-19-2004, 02:11 PM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Delete all of those subs and try it again.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #7  
Old 05-20-2004, 04:23 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Unhappy >=(

i think i need a bit more experience with the actual structure of the code...or how the program actually works...but right now i cant seem to figure anything out.

iv uploaded the project folder to my server, so if you want to help me out with some coding and then i can study from it, id really appriciate it.

thx again.

http://www.gauze-media.com/pass_org.zip
__________________
-spouT
Reply With Quote
  #8  
Old 05-20-2004, 09:25 PM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Hmm... didn't expect you to have four add account buttons . I assume they all do the same thing.

OK, I'm starting off from the .ZIP file that you attached...
When you are looking at the form, double-click on Add Account (either one is fine I guess... if not, then click the one you were intending this for).

I clicked on Add E-mail Account...

That should take you here in the code window for Form1:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
First, move the line that you have before that into this subroutine:

Dim F2 As Form = New Form2()

You can select it and then drag it into the subroutine.
Now, all you need to do is show it.
To show a form:
varname.ShowDialog()
where varname is the name of your form... in this case, substitute varname with F2, since that is the name of the form variable.

Now, when you run the project and click on Add Account, the new form should show up (and do nothing, but that's only for right now).

Let me know when you have that or if you have trouble there, or if you want me to go faster/slower.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #9  
Old 05-21-2004, 08:19 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Talking =d

Ah ic ic ic!

i get it now, each time you click another button in the designer, its automatically adds the code for you, so basically, the designer is there to help you "visualize" where the code will go, (hense the name vb)

its all coming together now haha!

ok, now that i have a basic understanding, and have gotten the form to open, (thx to you), how do i make it add the info the user type in into that box?
__________________
-spouT
Reply With Quote
  #10  
Old 05-22-2004, 05:33 PM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

OK. This method might not be as clear cut as the other one.

Actually, make this one minor change to this line:
Dim F2 As Form2 = New Form2()
This just means that we are going to access Form2 as a specific instance of Form2 instead of just a regular form.
Without Form2 and just form, we won't be able to view the contents of the controls in Form2.

So, if we want to access the contents of Form2... you can do something like this:
F2.TextBox1.Text
TextBox1 is the Username TextBox
TextBox2 is the Password TextBox.
So, to access the username:
F2.TextBox1.Text <-- this will turn into the username string that's in the box
F2.TextBox2.Text <-- this will be the password string.

I'm not sure what you want to add to the listbox, but to add an Item to the listbox.
ListBox1.Items.Add(...)
where you substitute the ... for what you want to add into the listbox.

ListBox1.Items.Add("abcdefg") <-- Adds abcdefg into the listbox.
ListBox1.Items.Add("Iceplug") <-- Adds my name to the listbox.
To add a variable, like a textbox.text or something, you don't use the "".
"" is for literal strings, something that you want the code to process like text.
Without the "", the program will look for a matching variable and put its contents into the listbox.

Notice that all of this is in Form1, nothing in Form2 yet.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #11  
Old 05-22-2004, 10:03 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Default

i understand what you mean by "going to access Form2 as a specific instance" but i dont get what u need to get data from form2 when there is none there. i would like it to add something like this:

--------------
spout
123456
--------------

^adds that inside the list box everytime a user registers something in both the fields.

how to i make it add once the user has typed something and clicked ok.

btw...whats F2, and what do periods do?

thx again, -spouT
__________________
-spouT
Reply With Quote
  #12  
Old 05-23-2004, 07:47 AM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

What do you mean, when there is none there?
F2 is the variable name of the form.
We can't use Form2 as the name... that's the variable name for the form... that's how we distinguish the type of form in our project. We could have several instances of Form2, so that's why I have to say:
Dim F2 As Form2 = New Form2
F2 is the name that I am using to refer to this instance.
(If I did Dim Doughnut As Form2 = New Form2, then Doughnut would refer to the instance I just created there, and F2 would refer to the first one, the one I have before I opened the parentheses.)

After you have set the form to a new instance, you show it like this:
F2.ShowDialog() 'Shows the form.
This will pause execution until the form is closed/hidden/minimized or, in general, not immediately on the screen.
(Similarly, Doughnut.ShowDialog() would show the other instance of Form2... even though they're identical at this point.)

Now, a Form2 is open, code execution has halted in Form1 until this Form2 is closed.
The user types in stuff into the textboxes: username "spout", password "123456"...

hits ok, but I haven't fixed that yet. Really, you can add Me.Close() to the ok button click event.
Where Me is referring to this instance of the form, hence Me.Close() closes me (the form).

Now, at this point, the form is closed, which means execution continues on Form1.

After the .ShowDialog, you read in the data from the F2 form.
To get the stuff that is in the TextBox, you'd do:
F2.TextBox1.Text

I suppose I should explain the periods now. The period means that you are accessing a member of something.
You have F2 ... in order to get the TextBox1 that is on F2, you do: F2.TextBox1
to get the text in that textbox, you do: F2.TextBox1.Text
The ShowDialog is a member procedure of F2, and you access it from F2 like:
F2.ShowDialog()
Like Me.Close(): Me is the current form class, and close is a method of this form class.

(FYI
You use it much like a directory storage: you have the Textfiles folder on your C: drive and you want to access the numbers.txt file in the Textfiles folder:
First: C:
To get the Textfiles folder: C:\TextFiles
To get the numbers.txt: C:\TextFiles\numbers.txt

To make some default data when there is none there, you can just check for the default text... so, after ShowDialog()

Code:
If F2.TextBox1.Text = "TextBox1" Then '^^^ this line means that the following code up to the End If 'will be executed if the data in the F2.TextBox1.Text says TextBox1, 'which is the default text that you see when you show the form. ListBox1.Items.Add("spout") 'Adds spout and 123456 to the listbox. ListBox1.Items.Add("123456") End If 'Anything after this end if will be executed normally.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #13  
Old 05-23-2004, 11:29 AM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Default

ah yes, it makes much more sense now that i understand some of the code, i didnt now that it stops the execution, i thought it did it all at once. ok, so i understand....but i am not quite sure that u get what i am trying to do.

i added your code, and no errors came up, but it didnt add "spout" or "123456" to the listbox in Form1. i also added me.close() to the ok button in form2.

i was thinking that maybe u need to save what the user types-in into a var and then when u get back to Form1 it takes those vars and uses them to add to the listbox in this format:

---------- <<adds that by default
spout <<what user typed in for username
hello52 <<what user typed in for password
--------- <<adds that by default
spouter <<what user typed in for username
goodbye63 <<what user typed in for password
--------- <<adds that by default

hmm this post is getting long, here is my email, so if you use msn, add me so we can talk quicker....im sorry if i am anoying, if you dont feel like helping me anymore, just recomend a good book =D

canadonian@hotmail.com
__________________
-spouT
Reply With Quote
  #14  
Old 05-23-2004, 07:06 PM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

No, I prefer talking here. Besides, the purpose of the forum is for us to share our knowledge with others (who may have similar problems and might like a read along)... harder to do over a chat medium. (And there are much longer posts than this .)

Anyway, you can add whatever you want to the listbox, just add it in order.
If you want to add some dashed lines:
ListBox1.Items.Add("----------")
If you want to add the username:
ListBox1.Items.Add(F2.TextBox1.Text)
If you want to add the password:
ListBox1.Items.Add(F2.TextBox2.Text)

If you are worried about what goes into the listbox. You can customize it however you like.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #15  
Old 05-23-2004, 08:31 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Default

haha! it works! weeeeeee

thanks ALOT!

now, how to make it save when u add new entries...
and also, how to make the entries editable/deletable...

i feel like im asking for so much, but hey, like u said, this is what forums are for right?
__________________
-spouT
Reply With Quote
  #16  
Old 05-23-2004, 08:45 PM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Sure, keep asking... .

What do you mean by 'save'? You mean to a text/dat file or something?
To make the entries editable/deletable, you are going to need buttons for that, but deletable is easy... you just use LBx.Items.Remove(???)
Editable us easy as well: Just LBx.Items.Item(???) = "???"
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #17  
Old 05-24-2004, 06:58 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Default

i mean by save as in, when i close the program, it saves what ever you typed in, in the listboxes. the program i want to make it a password organizer, something to organize all your different types of passwords. and when i want it to delete, i want it to deleted the item that is selected when u press the delete key.

what do i put inside the brackets to make it so that it deletes the one selected in LBx 1? and same for list box 2.

LisyBox1.Items.Remove( )
...............................^ here

thx,
__________________
-spouT
Reply With Quote
  #18  
Old 05-27-2004, 05:36 PM
Iceplug's Avatar
Iceplugstoring data in listbox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You want to remove the .SelectedItem from ListBox1, and similarly for ListBox2...
To remove, put ListBox1.SelectedItem in the parentheses.

To save to a file, you need to use the System.IO class to write to a file.
Dim SW As IO.StreamWriter = New IO.StreamWriter(filename)
Then, you need a For Loop to write all of the items in the listbox to file
For LV = 0 To ListBox1.Items.Count - 1
'LV goes from 0, the first index, to Count - 1, which is the last index.
SW.WriteLine(Convert.ToString(ListBox1.Items(LV)))
Next
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #19  
Old 05-29-2004, 09:37 PM
Spout Spout is offline
Newcomer
 
Join Date: May 2004
Location: Somehwere
Posts: 12
Default

ok, the edit script didnt work...same thing for the save file. but i got the delete script to work!

anyway here are the details:

thats what i have:
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
Dim SW As IO.StreamWriter = New IO.StreamWriter(test)
For LV = 0 To ListBox1.Items.Count - 1
SW.WriteLine(Convert.ToString(ListBox1.Items(LV)))
End Sub

its telling me i dont have LV declared, and i dont know what to declare it as, and same for the file name. there are many commands i dont know yet, but hopefully are learning haha.

thx again, spouT

btw, is there a way to group what the user inputs. so for example: user types in name, and pass, and it add those two to the LB, but then when i select either one, it will also select the one that goes with it?
__________________
-spouT
Reply With Quote
  #20  
Old 05-30-2004, 01:13 AM
Dennis DVR's Avatar
Dennis DVRstoring data in listbox Dennis DVR is offline
Back in the Game

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Manila Philippines
Posts: 3,576
Default

Code:
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click Dim LV As Integer Dim Test As String = "c:\temp\duane.txt" Dim SW As IO.StreamWriter = New IO.StreamWriter(test) For LV = 0 To ListBox1.Items.Count - 1 SW.WriteLine(Convert.ToString(ListBox1.Items(LV))) Next End Sub
__________________
Avatar by Lebb

[Posting Guidelines] [Standards & Practices Tutorial] [Participate here effectively]
Our knowledge can only be finite, while our ignorance must necessarily be infinite. Karl Popper

Last edited by duane; 05-30-2004 at 07:31 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help... pretty hard =( XxVegoxX Database and Reporting 5 04-12-2004 07:43 AM
Data from ListBox to rptTextBox? Knappe Database and Reporting 0 10-29-2003 03:19 PM
Storing data in exe rbulph File I/O and Registry 8 09-11-2003 10:13 AM
Specifying which columns data goes to in a listbox? Rick LV General 13 02-27-2003 12:57 PM
Exporting a data into a table & storing it dpdsouza Database and Reporting 3 11-08-2002 03:34 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
storing data in listbox
storing data in listbox
storing data in listbox storing data in listbox
storing data in listbox
storing data in listbox
storing data in listbox storing data in listbox storing data in listbox storing data in listbox storing data in listbox storing data in listbox storing data in listbox
storing data in listbox
storing data in listbox
 
storing data in listbox
storing data in listbox
 
-->