Visual Basics Watermark passwordchar? - vb.net

I'm currently making a login form to my program where I have a watermark for the two textboxes Email and Password.
When a textbox is empty, its watermark text will appear in it like "Username" and "Password".
My code is:
Public Class frmLogin
Private Sub TextBox2_LostFocus(sender As Object, e As System.EventArgs)
If TextBox2.Text = "" Then
TextBox2.ForeColor = Color.DarkGray
TextBox2.Text = "Username"
End If
End Sub
Private Sub TextBox2_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox2.GotFocus
TextBox2.Text = ""
TextBox2.ForeColor = Color.Black
End Sub
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
If TextBox2.Text = "" Then
TextBox2.ForeColor = Color.DarkGray
TextBox2.Text = "Username"
End If
TextBox1.Text = ""
TextBox1.ForeColor = Color.Black
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As System.EventArgs) Handles TextBox1.LostFocus
If TextBox1.Text = "" Then
TextBox1.ForeColor = Color.DarkGray
TextBox1.Text = "Password"
End If
End Sub
End Class
But now my problem is that I want to use password characters for the password. But I still want the watermark text to be in regular text. When I check to use a password char it turns my watermark into "**" instead of "Password". How can I fix that?

This seems good:
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
Textbox1.PasswordChar = "*"
Textbox1.Clear()
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As System.EventArgs) Handles TextBox1.LostFocus
TextBox1.PasswordChar = ControlChars.NullChar
End Sub

Related

How to put many Textbox in one If else statement

This is the question
=If the FN button
will be click, then it will display a message base on the status of the textbox1 control. For the MN button, if
the event is click then it will display a message base on the status of the textbox2 control. The LN button
was clicked then it will display a message base on the status of the textbox3 control. Lastly, if the Clear
button control will be click and any of the textbox control is not empty then it will clear all the textbox
controls, but if all textbox controls are empty then it will show a message that all textbox controls are empty.
this is my code
Public Class Form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
Label1.Text = "First Name"
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
Label2.Text = "Middle Name"
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
Label3.Text = "Last Name"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Text = "FN"
If TextBox1.Text = vbNullString Then
MessageBox.Show("The First name is empty")
Else MessageBox.Show("The First name is " & TextBox1.Text)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button2.Text = "MN"
If TextBox2.Text = vbNullString Then
MessageBox.Show("The Middle name is empty")
Else : MessageBox.Show("The Middle name is " & TextBox2.Text)
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Button3.Text = "LN"
If TextBox3.Text = vbNullString Then
MessageBox.Show("The Last name is empty")
Else : MessageBox.Show("The Last name is " & TextBox3.Text)
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Button4.Text = "Clear"
If (TextBox1.Text) And (TextBox2.Text) = vbNullString Then
MessageBox.Show("Textbox control is empty")
Else : TextBox1.Clear()
End If
For Each txt As Control In Me.Controls.OfType(Of TextBox)()
txt.Text = ""
Next
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class
My question is , how to work on clear button because i cant do it in Textbox2 and Textbox3 thankyou
Try something like this
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is TextBox Then
CType(ctrl, TextBox).Text = String.Empty
End If
Next ctrl
Try to add Next txt to your For Each
So, you are asking about Button4_Click.
This is what I was about to suggest first, because clearing all text boxes whether they are empty or not, is faster than first checking and then clearing.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
' Button4.Text = "Clear"
' If (TextBox1.Text) And (TextBox2.Text) = vbNullString Then
' MessageBox.Show("Textbox control is empty")
' Else : TextBox1.Clear()
' End If
For Each txt As Control In Me.Controls.OfType(Of TextBox)()
txt.Text = ""
Next
MessageBox.Show("Textbox controls are empty")
End Sub
But then, if the intention is to a) just clear all textboxes, without any message if any one has some text. b) show the message only if all are empty.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
' Button4.Text = "Clear"
If (TextBox1.Text = vbNullString) And (TextBox2.Text = vbNullString) And (TextBox3.Text = vbNullString) Then
MessageBox.Show("Textbox controls are empty")
Else
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End If
or (if this works, VB6 is alien for me)
....
Else
For Each txt As Control In Me.Controls.OfType(Of TextBox)()
txt.Text = ""
Next
End If
End Sub
I'd use a List(Of TextBox) allowing you to leverage All and ForEach:
Public Class Form1
Private TBs As New List(Of TextBox)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TBs.AddRange({TextBox1, TextBox2, TextBox3})
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If TBs.All(Function(tb) tb.Text = "") Then
MessageBox.Show("All TextBoxes are empty!")
Else
TBs.ForEach(Sub(tb) tb.Clear())
End If
End Sub
End Class
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
' Button4.Text = "Clear"
If (TextBox1.Text = vbNullString) And (TextBox2.Text = vbNullString) And (TextBox3.Text = vbNullString) Then
MessageBox.Show("Textbox controls are empty")
Else
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End If
thanks sir Tom Brunberg, this code works for me :)

Handles clause requires a WithEvents variable defined in the containing type or one of its base type

So I'm very new to coding and especially Visual Basic, and after fidgeting around for a bit with open source code I only seem to have one recurring problem in my current Form1.vb file; Handles clause requires a WithEvents variable defined in the containing type or one of its base type. This is what is looks like:
Public Class Form1
Dim Firstnum As Decimal
Dim Secondnum As Decimal
Dim Operations As Integer
Dim Operator_selector As Boolean = False
Private lblHold As Object
Public Property TextBox1 As Object
WithEvents Btn1_click As Button
Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If
End Sub
Private Sub Btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "2"
Else
TextBox1.Text = "2"
End If
End Sub
Private Sub Btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "3"
Else
TextBox1.Text = "3"
End If
End Sub
Private Sub Btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "4"
Else
TextBox1.Text = "4"
End If
End Sub
Private Sub Btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "5"
Else
TextBox1.Text = "5"
End If
End Sub
Private Sub Btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "6"
Else
TextBox1.Text = "6"
End If
End Sub
Private Sub Btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "7"
Else
TextBox1.Text = "7"
End If
End Sub
Private Sub Btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "8"
Else
TextBox1.Text = "8"
End If
End Sub
Private Sub Btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "9"
Else
TextBox1.Text = "9"
End If
End Sub
Private Sub Btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "0"
End If
End Sub
Private Sub BtnPoint_Click(sender As Object, e As EventArgs) Handles btnPoint.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub
Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
TextBox1.Text = "0"
End Sub
Private Sub BtnPlus_Click(sender As Object, e As EventArgs) Handles btnPlus.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_selector = True
Operations = 1 'For addition
lblHold.Text = Firstnum.ToString + "+"
End Sub
Private Sub BtnMinus_Click(sender As Object, e As EventArgs) Handles btnMinus.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_selector = True
Operations = 2 'For subtraction
lblHold.Text = Firstnum.ToString + "-"
End Sub
Private Sub BtnMult_Click(sender As Object, e As EventArgs) Handles btnMult.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_selector = True
Operations = 3 'For multiplication
lblHold.Text = Firstnum.ToString + "*"
End Sub
Private Sub BtnDiv_Click(sender As Object, e As EventArgs) Handles btnDiv.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_selector = True
Operations = 4 'For division
lblHold.Text = Firstnum.ToString + "+"
End Sub
Private Sub BtnEqual_Click(sender As Object, e As EventArgs) Handles btnEqual.Click
If Operator_selector = True Then
Secondnum = TextBox1.Text
If Operations = 1 Then
TextBox1.Text = Firstnum + Secondnum
ElseIf Operations = 2 Then
TextBox1.Text = Firstnum - Secondnum
ElseIf Operations = 3 Then
TextBox1.Text = Firstnum * Secondnum
Else
If Secondnum = 0 Then
TextBox1.Text = "Error!"
Else
TextBox1.Text = Firstnum / Secondnum
End If
Operator_selector = False
End If
lblHold.Text = ""
End If
End Sub
End Class
Now I'm wondering what I have to do to get it right and make this error disappear. I tried using something around the lines of "WithEvents Btn1_click As Button" but it doesn't do anything. It also says "Btn1_click is already declared as 'Private WithEvents Btn1_click As Button' in this class." I'm truly a noob, so please don't throw hardcore coding terms at me but just the simple stuff :P
Many thanks in advance!
The Handles clause you see on those methods indicates that that method will be executed when the specified event of the object currently assigned to the specified variable is raised. For example:
Private Sub Btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
means that the Btn2_Click method will be executed when the object assigned to the btn2 variable raises its Click event. The error message flags this line:
Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
and it's telling you that you have no btn1 variable declared WithEvents.
When you add a control to your form in the designer, it automatically adds a variable with the specified name and declares it WithEvents. You can see that variable if you open the designer code file, which you can access via the Solution Explorer if you click the Show All Files button first. You can declare your own variables WithEvents but this:
WithEvents Btn1_click As Button
is not using the correct name for a start and it is also useless because it doesn;t have anything assigned to it. You'd need to create a Button object, assign it to the variable and add it to the form, which you haven't done.
The solution would be to simply add a Button to the form with that name.

DataSource No Longer Fills Data Calls VB 2010

I am using a DataSource in my form app, and it was working fine for calls made across the board, Fill, Add, Delete, etc... It suddenly stopped working. I get no errors on build, no data is added to any ComboBoxes, and no new Adds work either.
I created a new DataSource from the same database that works fine with the exact same connection. The location of the database never moved, no changes were made to any properties of the DataSource or any of the Adapters assigned to the source, it just stopped working. Here is some screen shots and code of my form.
I tried to do a Code Compare but since there are a bunch of Adapters assigned to the source I can't find any anomalies. What would kill a data connection so that the code still sees the connection, but nothing gets filled?
The following code no longer works, no Fill or Add to DCGDataSet;
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs)
'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
'comboClear()
End Sub
Private Sub btnAddNew_Click(sender As Object, e As System.EventArgs)
' Add new Job to the database
Dim newJobRow As New DCGDataSetTableAdapters.MainTableAdapter
Dim intInsert As Integer
Dim jobText = txtBoxAddNewJob.Text
intInsert = newJobRow.InsertJob(jobText)
If intInsert = 1 Then
MessageBox.Show("New Job Added")
' Update the comboBox values
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
txtBoxAddNewJob.Text = ""
clearTabOne()
Else
MessageBox.Show("Job Not Added")
End If
End Sub
The following call for a ComboBox works fine, this is the new DataSource;
Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
Me.MainTableAdapter1.Fill(Me.DCGDataSet1.Main)
End Sub
These pics are of the two DS I am working with, the top one is the non-working DS.
Entire .vb of Form1 Code;
Public Class MainForm
Dim strCurrency As String = ""
Dim acceptableKey As Boolean = False
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
comboClear()
End Sub
Private Sub btnAddNew_Click(sender As Object, e As System.EventArgs)
' Add new Job to the database
Dim newJobRow As New DCGDataSetTableAdapters.MainTableAdapter
Dim intInsert As Integer
Dim jobText = txtBoxAddNewJob.Text
intInsert = newJobRow.InsertJob(jobText)
If intInsert = 1 Then
MessageBox.Show("New Job Added")
' Update the comboBox values
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
txtBoxAddNewJob.Text = ""
clearTabOne()
Else
MessageBox.Show("Job Not Added")
End If
End Sub
Private Sub TabPage2_Enter(sender As Object, e As System.EventArgs)
Me.ActiveControl = txtBoxAddNewJob
clearTabOne()
End Sub
Public Sub comboClear()
ComboBox1.SelectedIndex = -1
ComboBox2.SelectedIndex = -1
End Sub
Private Sub TabPage1_Enter(sender As Object, e As System.EventArgs)
'comboClear()
ComboBox1.SelectedIndex = -1
'ComboBox1.SelectedText = ""
End Sub
Private Sub TabPage3_Enter(sender As Object, e As System.EventArgs)
'comboClear()
ComboBox2.SelectedIndex = -1
clearTabOne()
End Sub
Private Sub btnDeleteJob_Click(sender As Object, e As System.EventArgs)
Dim delJobID = ComboBox2.SelectedValue
Dim delJobRowAdpt As New DCGDataSetTableAdapters.MainTableAdapter
Dim delJobRow As DCGDataSet.MainRow
Dim intDelete As Integer
delJobRow = DCGDataSet.Main.FindByID(delJobID)
delJobRow.Delete()
intDelete = delJobRowAdpt.Update(DCGDataSet.Main)
If intDelete = 1 Then
MessageBox.Show("Job Deleted")
'comboClear()
clearTabOne()
'ComboBox2.SelectedValue = -1
Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
Else
MessageBox.Show("Job Failed to Delete")
End If
ComboBox2.SelectedValue = -1
End Sub
Private Sub FillSubCombo(ByVal subJob As String)
Dim selSubRow = DCGDataSet.SubBilling
Dim selSubValue As New DCGDataSetTableAdapters.SubBillingTableAdapter
Me.SubBillingTableAdapter.SubName(Me.DCGDataSet.SubBilling, subJob)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs)
Dim subJob As String = ComboBox1.Text
If subJob.Length > 1 Then
Label5.Visible = True
ComboBox3.Visible = True
FillSubCombo(subJob)
End If
End Sub
Public Sub clearTabOne()
Label5.Visible = False
ComboBox3.Visible = False
End Sub
Private Sub TabPage4_Enter(sender As Object, e As System.EventArgs)
clearTabOne()
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If (e.KeyCode >= Keys.D0 And e.KeyCode <= Keys.D9) OrElse (e.KeyCode >= Keys.NumPad0 And e.KeyCode <= Keys.NumPad9) OrElse e.KeyCode = Keys.Back Then
acceptableKey = True
Else
acceptableKey = False
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
' Check for the flag being set in the KeyDown event.
If acceptableKey = False Then
' Stop the character from being entered into the control since it is non-numerical.
e.Handled = True
Return
Else
If e.KeyChar = Convert.ToChar(Keys.Back) Then
If strCurrency.Length > 0 Then
strCurrency = strCurrency.Substring(0, strCurrency.Length - 1)
End If
Else
strCurrency = strCurrency & e.KeyChar
End If
If strCurrency.Length = 0 Then
TextBox1.Text = ""
ElseIf strCurrency.Length = 1 Then
TextBox1.Text = "0.0" & strCurrency
ElseIf strCurrency.Length = 2 Then
TextBox1.Text = "0." & strCurrency
ElseIf strCurrency.Length > 2 Then
TextBox1.Text = strCurrency.Substring(0, strCurrency.Length - 2) & "." & strCurrency.Substring(strCurrency.Length - 2)
End If
TextBox1.Select(TextBox1.Text.Length, 0)
End If
e.Handled = True
End Sub
Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
Me.MainTableAdapter1.Fill(Me.DCGDataSet1.Main)
End Sub
End Class
Your not-working code is missing the Handles clauses on Form1_Load and btnAddNew_Click. If you don't connect the event handler to the event (using either a Handles clause or an AddHandler statement), the event handler won't be run.

How to declare variables from a text file in Visual basic

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

How to store last button clicked and add to listbox

So I'm doing this calculator program and need the numbers, the operator used and the "=" sign to show up in the listbox so "1 + 1 = 2" should show up. I have the calculator working and can move items to the listbox, but can't figure out how to remember the button that was clicked to get the outcome and move it over also.
Option Explicit On
Option Strict On
Option Infer Off
Public Class Form1
Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click
Result.Text = CStr(Val(NumOne.Text) + Val(NumTwo.Text))
End Sub
Private Sub ButtonSub_Click(sender As Object, e As EventArgs) Handles ButtonSub.Click
Result.Text = CStr(Val(NumOne.Text) - Val(NumTwo.Text))
End Sub
Private Sub ButtonMul_Click(sender As Object, e As EventArgs) Handles ButtonMul.Click
Result.Text = CStr(Val(NumOne.Text) * Val(NumTwo.Text))
End Sub
Private Sub ButtonDiv_Click(sender As Object, e As EventArgs) Handles ButtonDiv.Click
Result.Text = CStr(Val(NumOne.Text) / Val(NumTwo.Text))
'outputs a message box telling the user to correct the division by 0, also displays a blank result box instead of NaN
If CDbl(NumTwo.Text) = Val(0) Then
Result.Text = ""
MessageBox.Show("You cannot divide by 0, please input another number")
End If
End Sub
Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
Me.Close()
End Sub
Private Sub ButtonSave_Click(sender As Object, e As EventArgs) Handles ButtonSave.Click
ListBox1.Items.Add(NumOne.Text & NumTwo.Text & Result.Text)
End Sub
End Class
As far as you just need to store one character, you can rely on the Tag property of ListBox1 (basically, a black box where you can store anything you want). Sample code:
Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click
Result.Text = CStr(Val(NumOne.Text) + Val(NumTwo.Text))
ListBox1.Tag = "+"
End Sub
Private Sub ButtonSub_Click(sender As Object, e As EventArgs) Handles ButtonSub.Click
Result.Text = CStr(Val(NumOne.Text) - Val(NumTwo.Text))
ListBox1.Tag = "-"
End Sub
Private Sub ButtonMul_Click(sender As Object, e As EventArgs) Handles ButtonMul.Click
Result.Text = CStr(Val(NumOne.Text) * Val(NumTwo.Text))
ListBox1.Tag = "x"
End Sub
Private Sub ButtonDiv_Click(sender As Object, e As EventArgs) Handles ButtonDiv.Click
Result.Text = CStr(Val(NumOne.Text) / Val(NumTwo.Text))
'outputs a message box telling the user to correct the division by 0, also displays a blank result box instead of NaN
If CDbl(NumTwo.Text) = Val(0) Then
Result.Text = ""
MessageBox.Show("You cannot divide by 0, please input another number")
End If
ListBox1.Tag = "/"
End Sub
Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
Me.Close()
End Sub
Private Sub ButtonSave_Click(sender As Object, e As EventArgs) Handles ButtonSave.Click
ListBox1.Items.Add(NumOne.Text & ListBox1.Tag.ToString() & NumTwo.Text & "=" & Result.Text)
End Sub