i have a form in which their is a two text boxes
text box1=username
text box2=password
when i execute then i have to enter the username and password
when i cancel the execution it will close every thing ok

But i need the same username which has been used at the time of previous execution

by default the text box1 should show the previous username when ever it is executed

Recommended Answers

All 13 Replies

First you need to set up the Settings you want to save. A Step by Step guide is here => http://msdn.microsoft.com/en-us/library/25zf0ze8.aspx

Then in your code:

Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
		txtUsername.Text = My.Settings.UserName
	End Sub

	Private Sub Close_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		My.Settings.UserName = txtUsername.Text
		My.Settings.Save()
	End Sub

First you need to set up the Settings you want to save. A Step by Step guide is here => http://msdn.microsoft.com/en-us/library/25zf0ze8.aspx

Then in your code:

Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
		txtUsername.Text = My.Settings.UserName
	End Sub

	Private Sub Close_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		My.Settings.UserName = txtUsername.Text
		My.Settings.Save()
	End Sub

just execute this code once and see
the form1 should contain two buttons

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Button1 : .Text = ".open" : End With : With Button2 : .Text = ".fileName" : .Width += 123 : End With '// FOR TESTING.

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

        Me.Hide()
        Dim frm As New Form2()
        frm.ShowDialog(Me)

        With New OpenFileDialog
            .Title = "Select a Cool File to load..."
            ' .Filter = ""
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                Button2.Text = IO.Path.GetFileName(.FileName) '// only FileName and .ext.
                Button2.Tag = .FileName '// FullPath of .File, to load .File from.
            End If
        End With


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        With Button2
            If Not .Tag Is Nothing Then Process.Start(.Tag.ToString) '// check if it has a .FullPath and load in/as default.
        End With

    End Sub

and the form2 will be asking password
when the password is entered and the password matched then the below rest of the code should get executed
if the password is not matched then it should come to form1 with out doing any thing

First you need to set up the Settings you want to save. A Step by Step guide is here => http://msdn.microsoft.com/en-us/library/25zf0ze8.aspx

Then in your code:

Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
		txtUsername.Text = My.Settings.UserName
	End Sub

	Private Sub Close_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		My.Settings.UserName = txtUsername.Text
		My.Settings.Save()
	End Sub

please do reply

easy tiger...

on Form2 when you check your login data ...
If login is correct then set

Me.DialogResult = DialogResult.Yes

else set

Me.DialogResult = DialogResult.Cancel

in Form1 instead of

frm.ShowDialog(Me)

do:

If frm.ShowDialog(Me) <> DialogResult.Yes Then
			MsgBox("Wrong login")
			Exit Sub
		End If
                'here the rest of your code

easy tiger...

on Form2 when you check your login data ...
If login is correct then set

Me.DialogResult = DialogResult.Yes

else set

Me.DialogResult = DialogResult.Cancel

in Form1 instead of

frm.ShowDialog(Me)

do:

If frm.ShowDialog(Me) <> DialogResult.Yes Then
			MsgBox("Wrong login")
			Exit Sub
		End If
                'here the rest of your code

thank you i got

have you executed that code what i have given you

no, didn't see a reason to do that.
Is it working now?

no, didn't see a reason to do that.
Is it working now?

when we select a .exe file from the button1 then it will print the name on the button2 right

so when we stop execution every thing will get closed ok

when we again execute, the button should be having the same .exe file name on it, which we printed in the previous execution

how to do this

I am sorry but at some point you have to start thinking for yourself. If you REALLY stick then open a new thread and ask for assistance. But do not expect us to write your whole application.

I am sorry but at some point you have to start thinking for yourself. If you REALLY stick then open a new thread and ask for assistance. But do not expect us to write your whole application.

this will be my last thread please

I am sorry but at some point you have to start thinking for yourself. If you REALLY stick then open a new thread and ask for assistance. But do not expect us to write your whole application.

i won't do so from the next time please just let me know please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.