I'm trying to connect to a database (mdb file of my choice) in a login screen and i want to save it for faster logon next times i boot the software.
I click on choose database button, opendialog lets me choose the file, i click OK and the db location shows in a textbox.
there's a checkbox beneath to save it before i connect to it.
But i can't manage to keep the checkbox checked, nor the textbox filled after i restart te program.
here's my current code:
Public Class LoginScreen
Private Sub Loginscreen_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ProgressBar2.Minimum = 0
ProgressBar2.Maximum = 100
ProgressBar2.Visible = False
Panel1.Visible = False
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Application.Exit()
End Sub
Private Sub btnExit2_Click(sender As Object, e As EventArgs) Handles btnExit2.Click
Application.Exit()
End Sub
Private Sub tmrLogin_Tick(sender As Object, e As EventArgs) Handles tmrLogin.Tick
ProgressBar2.Value = ProgressBar2.Value + 20
lblLoginMessages.Text = ProgressBar2.Value & "%" & " Completed"
If ProgressBar2.Value >= 100 Then
tmrLogin.Enabled = False
If txtUser.Text = "azert" And txtPassword.Text = "azert" Then
ProgressBar2.Value = 0
Else
lblLoginMessages.Text = "Wrong credentials, Try again!"
pboxClosed.Visible = True
PboxOpen.Visible = False
ProgressBar2.Value = 0
txtPassword.Text = ""
txtUser.Text = ""
End If
End If
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
ProgressBar2.Visible = True
tmrLogin.Enabled = True
pboxClosed.Visible = False
PboxOpen.Visible = True
''navraag doen om dit correct in te stellen! ! ! ! !!
'If ProgressBar2.Value = 100 Then
'lblLoginMessages.Text = "Logging in..."
Me.Hide()
Mainscreen.Show()
'End If
If chkSavePassword.Checked = True Then
My.Settings.databaselocation = txtDatabaselocationshow.Text
My.Settings.SaveLocation = True
End If
End Sub
Private Sub btnDBConnect_Click(sender As Object, e As EventArgs) Handles btnDBConnect.Click
If Panel1.Visible = False Then
Panel1.Visible = True
Else
Application.Exit()
End If
End Sub
Private Sub btnChoose_Click(sender As Object, e As EventArgs) Handles btnChoose.Click
Dim strtext As String
OpenFileDialog1.Filter = "Database Files | *.mdb"
OpenFileDialog1.InitialDirectory = "F:\GoogleDrive\EINDWERK VBNET"
OpenFileDialog1.Title = "Choose your Database"
OpenFileDialog1.ShowDialog()
strtext = OpenFileDialog1.FileName
txtDatabaselocationshow.Text = strtext
'If OpenFileDialog1.ShowDialog = DialogResult.OK Then
' strtext = OpenFileDialog1.FileName
' txtDatabaselocationshow.Text = strtext
'Else
' MsgBox("Error: the database file could not be read, try again.")
'End If
End Sub
Private Sub tmrshowloginpanel_Tick(sender As Object, e As EventArgs) Handles tmrshowloginpanel.Tick
Panel1.Width += 5
If Panel1.Width >= 700 Then
tmrshowloginpanel.Stop()
End If
End Sub
End Class
i've scoured the net but can't really find what to do?
if you need more information, shoot!
Walk through this with me:
Make a new project, one form, add a textbox and a combobox.
Click the textbox:
In the properties grid at the top click (Application Settings), then the 3 dots next to Property Binding. Scroll to Text. Drop down the setting and choose New at the bottom.
Give it a name of ChosenDatabasePath or something useful and descriptive like that
Repeat from "Click the textbox" for the checkbox instead, and this time bind the Checked property not the Text property.. Call the checkbox's Checked binding SavePassword or similar
Close all the dialogs so you're back at the form
Click anywhere on the background of the form when switch to Events in the property grid, find FormClosing and double click it
Put My.Settings.Save() in the FormClosing event handler
Run the app, write something in the textbox, close the form (by the X, not by stopping debugging), then immediately open the app again (run it)
Related
first I'm new in this, and I have this code that shows a prompt to restart or postpone the restart for a while, the issue is that i want to hide the message and bring it back after the time specified by the user.
I'm using a "visual basic form" and the time that restart will be postponed it's selected from a "ComboBox"
My code is as follows.
Imports System.Management
Imports System.Security.Permissions
Imports System
Imports System.IO
Imports System.Collections
Imports System.SerializableAttribute
Public Class Form2
Dim PostponeReboot As Integer = 50
Private Const CP_NOCLOSE_BUTTON As Integer = &H200
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim myCp As CreateParams = MyBase.CreateParams
myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
Return myCp
End Get
End Property
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Hide()
Label4.Text = SystemInformation.UserName
Button1.Enabled = False
ComboBox1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
CheckBox2.Enabled = False
Button1.Enabled = True
ComboBox1.Enabled = False
ElseIf CheckBox1.Checked = 0 Then
CheckBox2.Enabled = True
Button1.Enabled = False
ComboBox1.Enabled = False
End If
End Sub
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked Then
CheckBox1.Enabled = False
ComboBox1.Enabled = True
Button1.Enabled = True
ElseIf CheckBox2.Checked = 0 Then
CheckBox1.Enabled = True
ComboBox1.Enabled = False
Button1.Enabled = False
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = "1 Hora" Then
PostponeReboot = 10
ElseIf ComboBox1.Text = "2 Horas" Then
PostponeReboot = 20
ElseIf ComboBox1.Text = "4 Horas" Then
PostponeReboot = 40
ElseIf ComboBox1.Text = "Seleccione" Then
Button1.Enabled = False
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If CheckBox1.Checked Then
MessageBox.Show("Rebooting")
'Shell("shutdown -r -f -t 60")
Form1.Close()
End
ElseIf CheckBox2.Checked Then
MessageBox.Show(PostponeReboot)
Timer1.Start()
Me.Hide()
End If
If PostponeReboot = 0 Then
Me.Show()
Else
Me.Hide()
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PostponeReboot = PostponeReboot - 1
'Label5.Text = PostponeReboot
End Sub
End Class
In the first "If" sentence of below I want to start the timer and hide the form, and in the second "If" i want to bring it back the form, but the form remains hidden.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If CheckBox1.Checked Then
MessageBox.Show("Rebooting")
'Shell("shutdown -r -f -t 60")
Form1.Close()
End
ElseIf CheckBox2.Checked Then
MessageBox.Show(PostponeReboot)
Timer1.Start()
Me.Hide()
End If
If PostponeReboot = 0 Then
Me.Show()
Else
Me.Hide()
End If
End Sub
I've tried putting the second "If" sentence in another place but don't work, what I'm doing wrong.
I assume here that your Timer1 class raises the Timer1.Tick event every x time after Timer1.Start() is called. The fact that the form can hide tells me Timer1.Start() isn't a blocking method. As such, your second if statement will be verified right after you hide the form, without waiting for the PostponeReboot variable to reach zero. This particular button handler would then exit and your form would remain hidden. What I see is that you already have an event handler for each tick of your timer. Why not use this handler to verify the state of your PostponeReboot variable?
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PostponeReboot = PostponeReboot - 1
If PostponeReboot = 0 Then
Timer1.Stop() 'I would assume
Me.Show()
End If
End Sub
Although, I would recommend you to try other solutions, like having your timer raise an event only when it reaches the elapsed time (so you don't have to handle each ticks unnecessarily). I would also recommend looking into an Universal Windows App with Toast Notifications as you could set a Notification to appear at a set time (handled by Windows) so that you don't have to have a thread running in the background for this.
I'm trying to make it so when the button is pressed, it disables the button and allows you to select the mouse coordinates. (With right click) then enable back the button. How do you detect if button1 was pressed for the if statement while keeping the timer?
If Button1.clicked Then
This is where I need the If statement to detect button1 being pressed.
Private Sub Timer2_Tick(sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Button1.clicked Then
Button1.Enabled = False
If GetAsyncKeyState(2) Then
TextBox1.Text = Cursor.Position.X
TextBox2.Text = Cursor.Position.Y
Button1.Enabled = True
End If
End If
End Sub
Thanks with the help of #the_lotus I found a way around the timer/button issue.
Instead of looking for the button press within the timer statement, you control if the timer is on or off.
Lotus also asked for the reasoning behind the timer. The timer is so the form always looks for a input, not just when the button is pressed.
Private Sub Button1_Click(sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Timer2.Interval = 5
Timer2.Enabled = True
Me.Button1.Text = "Set Posistion 1"
End Sub
Sub Timer2_Tick() Handles Timer2.Tick
If GetAsyncKeyState(2) Then
TextBox1.Text = Cursor.Position.X
TextBox2.Text = Cursor.Position.Y
Button1.Enabled = True
Timer2.Enabled = False
Me.Button1.Text = "Reset Position"
End If
End Sub
I would like to load string from a text file as a variable. For example a insecure login screen which the user enters their credentials into a textbox which the program will read what has been entered into the textbox and will load the next form when the credentials are the same stored in the text file.
Update:Solved it over 1 and half hours of googling
Public Class Form1
Public pass As String = String.Empty
Public user As String = String.Empty
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox2.Text = (user) And TextBox1.Text = (pass) Then
Login.Show()
Me.Close()
Else
MessageBox.Show("Wrong Password or User Name")
End If
TextBox2.Text = ""
TextBox1.Text = ""
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
If TextBox2.Text = "" And TextBox1.Text = "" Then
Button1.Enabled = False
Else
Button1.Enabled = True
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pass = IO.File.ReadAllText("pass.txt")
user = IO.File.ReadAllText("user.txt")
End Sub
End Class
just used IO.File.ReadAllText("user.txt") Which will read all the string in the text file and store them into the empty variable not the best method but works for this application
I have a script that logs into a website and can autoclick something very fast for the given interval. Now ever since I added my newest detail in, everything in the script works, except the autoclicker. Once I click the button to start the autoclicker it doesn't even click once.
Here is the code I just added
With WebBrowser1
Do Until Not (.IsBusy)
Application.DoEvents()
Loop
Do Until .ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
End With
Dim htmlText As String
If Not (WebBrowser1.Document.Body.InnerHtml) Is Nothing Then
htmlText = WebBrowser1.Document.Body.InnerHtml
If InStr(htmlText, "Microsoft account") Then
MessageBox.Show("You have entered in a wrong password or the account doesn't exist.")
'code to go here if it is true
Else
MessageBox.Show("Sign in successful. Proceed on...")
'code to go here if it is false
End If
End If
what the code does is it tells you if you used the correct login credentials or the wrong ones. But i don't understand how that would affect my autoclicking button?
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
Timer1.Interval = 40
ElseIf RadioButton2.Checked = True Then
Timer1.Interval = 100
Else
Timer1.Interval = 500
End If
Timer1.Start()
WebBrowser1.Document.GetElementById("NewGamertag").SetAttribute("value", txtTurbo.Text)
WebBrowser1.Document.GetElementById("claimIt").InvokeMember("Click")
End Sub
Where timer1 =
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
WebBrowser1.Document.GetElementById("claimIt").InvokeMember("Click")
End Sub
Make your timer1.enable = true, else it wont be work.
How can I tell the code to not to write the word to textbox for every click on the button?
When both checkboxes are clicked both, text must be written in adding order but when I click the button again text shouldn't be doubled or multiplied.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True Then
TextBox1.Text += ("hello ")
End If
If CheckBox2.Checked = True Then
TextBox1.Text += ("please help")
End If
End Sub
End Class
Use a Boolean variable for each if statement, i.e. each check box. Set them to false initially and change your code to look something like this
If CheckBox1.Checked = True And CheckBox1Bool = False Then
TextBox1.Text += ("hello ")
CheckBox1Bool = True
End If
If CheckBox2.Checked = True And CheckBox2Bool = False Then
TextBox1.Text += ("please help")
CheckBox2Bool = True
End If
EDIT:
Public Class Form1
Dim Bool1 As Boolean
Dim Bool2 As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True And Not Bool1 Then
TextBox1.Text += ("hello ")
Bool1 = True
End If
If CheckBox2.Checked = True And Not Bool2 Then
TextBox1.Text += ("please help")
Bool2 = True
End If
End Sub
End Class
This works and as you can see I haven't changed the code only added in what I suggested to you.
Just reset your Checkbox.Checked event in your Button Click event. That way it will not send the text again till you reselect it.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True Then
CheckBox1.Checked = False
TextBox1.Text += ("hello ")
End If
If CheckBox2.Checked = True Then
CheckBox2.Checked = False
TextBox1.Text += ("please help")
End If
End Sub
Thank you very much for your concern about my problem. after i checked your solutions i went to bed. i released stg just i was going to sleep and opened pc again and solved my silly problem with this thing.. this works perfect for me :)
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Textbox1.Text= ("")
If CheckBox1.Checked = True Then
TextBox1.Text += ("hello ")
End If
If CheckBox2.Checked = True Then
TextBox1.Text += ("please help")
End If
End Sub
End Class