|
-
Feb 4th, 2008, 12:51 AM
#1
Thread Starter
New Member
[2008] Coding Help
Okay, I have a problem, I'm trying to make a log in system using just windows forms, easy, now, I'm trying to add a create function, and I have a problem (By the way, I'm not using ANY other programs) This is the code I have on form 2 (Log in form):
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click <<NEWLINE>>
If ComboBox1.Text = "Jexah" And TextBox1.Text = "password" Then<<NEWLINE>>
MsgBox("Login successful!", MsgBoxStyle.OkOnly, Title:="Welcome!")<<NEWLINE>>
Me.Hide()<<NEWLINE>>
Form1.Show()<<NEWLINE>>
<<NEWLINE>>
End If<<NEWLINE>>
End Sub<<NEWLINE>>
Now, My problem is I want to use code from form 3 to ADD code to form 2 (Above) how do I do that?
How do I use code to add code?
Form 3 (Create form):
If textbox3.text = "12345" then
((textbox3 is just a confirmation code.) I don't know what to put here, but I want the textbox1.text and textbox2.text (Username and password on the create form) to end up in here:
If ComboBox1.Text = "Jexah" And TextBox1.Text = "password" then
Like this:
If ComboBox1.Text = "Jexah" And TextBox1.Text = "password" or combobox1.text = "Random" and textbox1.text = "password" then
Help please! And if you don't understand, please say the word, and I can help you understand, PLEASE HELP!
-
Feb 4th, 2008, 02:19 AM
#2
Junior Member
Re: [2008] Coding Help
Hi,
Not quite sure of what you are intending to do but if you wish to reference other forms form within a form etc you need to use the preceeding class (in this case Form) identifier.
eg If Form1 has the detail you require and you are working on Form2:
Me.Textbox2.text = Form1.Textbox1.text
Hope this helps,
Ozman
-
Feb 4th, 2008, 03:28 AM
#3
Thread Starter
New Member
Re: [2008] Coding Help
Yeah, I understand that, that is practically relating the forms and making them interact, but no, sorry it doesn't help, I know that, but thanks heaps for trying to help! What I'm trying to do is use the code from form 3 to add code to form 2.
-
Feb 4th, 2008, 04:05 AM
#4
Re: [2008] Coding Help
if you want to use the same code in more than one form, you need to store it in a module and call it from the forms. However it looks like you are wanting to know how to store users and passwords?
-
Feb 4th, 2008, 04:16 AM
#5
Hyperactive Member
Re: [2008] Coding Help
he wants to create the line
If ComboBox1.Text = "Jexah" And TextBox1.Text = "password" then
dynamically
he probably hopes that by doing so his code will be more secure because it won't exist until runtime (but i've been known to be wrong )
-
Feb 4th, 2008, 04:44 AM
#6
Re: [2008] Coding Help
You're barking up the waaaaaaaayyy wrong tree. You do not code your user names and passwords into the app. You store them somewhere appropriate, e.g. a database, then when the user enters a user name and password you look for a matching record. If you find one the login is successful, otherwise access is denied. If you want to display a list of user names in a ComboBox then you get the user name list first, populate the ComboBox and then you only need to test the password for that user name. Whatever the detail you would never, ever do what you're suggesting.
-
Feb 4th, 2008, 04:58 AM
#7
Re: [2008] Coding Help
 Originally Posted by OZMan
Hi,
Not quite sure of what you are intending to do but if you wish to reference other forms form within a form etc you need to use the preceeding class (in this case Form) identifier.
eg If Form1 has the detail you require and you are working on Form2:
Me.Textbox2.text = Form1.Textbox1.text
Hope this helps,
Ozman
http://www.vbforums.com/showpost.php...54&postcount=3
-
Feb 4th, 2008, 05:53 AM
#8
Thread Starter
New Member
Re: [2008] Coding Help
 Originally Posted by jmcilhinney
You're barking up the waaaaaaaayyy wrong tree. You do not code your user names and passwords into the app. You store them somewhere appropriate, e.g. a database, then when the user enters a user name and password you look for a matching record. If you find one the login is successful, otherwise access is denied. If you want to display a list of user names in a ComboBox then you get the user name list first, populate the ComboBox and then you only need to test the password for that user name. Whatever the detail you would never, ever do what you're suggesting.
You're right, it's the most LOGICAL way to approch it, and I SHOULD have done that, but I want to see what I can do in basic windows forms before I started any databasing and that, so sure, I COULD do it, but I don't WANT to yet, also, what I want to know will help me a LOT once I find out how to do it because there are lots of things you can do if you can use code to edit other code.
-
Feb 4th, 2008, 07:37 AM
#9
Re: [2008] Coding Help
You're taking something very simple and trying to make it as difficult as possible by using functionality that, after five years of working commercially with VB and C#, I've never come across a need to use. Compiling code at run time is a very advanced topic that even I would have to spend some time to get my head around properly. You'd never, ever use it for something like this either. What you're trying to do is a very bad idea and how you're trying to do it is something that the vast majority of .NET developers will never have use for. There are far more important topics that are fundamental to .NET development that you should be spending your time learning.
That said, if you're still determined to proceed then go to MSDN and search for CodeDOM.
-
Feb 4th, 2008, 07:54 AM
#10
Thread Starter
New Member
-
Mar 6th, 2008, 06:55 AM
#11
Lively Member
Re: [2008] Coding Help
Hey Ive written code for this although its not exactly how you described it.
My method looks through a database for user name and passwords and then authenticates the user so that he can access other forms
Heres the code
Code:
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = d:\AddressBook.mdb"
Dim sql As String
Dim ds As New DataSet
Dim userID As String
Dim da As New OleDb.OleDbDataAdapter
Dim password As String
Dim int1 As Integer
Dim maxrows As Integer
userID = UsernameText.Text
password = PasswordText.Text
con.Open()
int1 = 0
sql = "SELECT * FROM login"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "AddressBook")
maxrows = ds.Tables("AddressBook").Rows.Count
Do Until int1 = 4
If ds.Tables("AddressBook").Rows(int1).Item(0) = userID And ds.Tables("AddressBook").Rows(int1).Item(1) = password Then
Form1.Show()
Me.Hide()
Exit Sub
Else
End If
int1 = int1 + 1
Loop
Dim msg As String
msg = MsgBox("Username/password mismatch!", vbOKCancel)
If msg = 1 Then
Me.Show()
UsernameText.Text = ""
PasswordText.Text = ""
UsernameText.Focus()
Else
Me.Close()
End If
End Sub
.
Hope this helps!
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
|