How to use numpad as input in vb calculator - vb.net

Basically I've been searching for weeks now but I cannot find a good example of using the numpad as an input for calculator.
Private Sub Form1_KeyPress(ByVal KeyAscii As _MSForms.ReturnInteger)
lblOutput.Text = lblOutput.Text & Chr(KeyAscii)
If KeyAscii >= vbKeyNumpad0() And KeyAscii <= vbKeyNumpad9() Then
lblOutput.Text = lblOutput.Text & Chr(KeyAscii)
End If
End Sub
Option Explicit On
Public Class Form1
Dim chrOperator As Char
Dim varFirstVal As Integer
Private Sub Form1_KeyPress(ByVal KeyAscii As _MSForms.ReturnInteger)
lblOutput.Text = lblOutput.Text & Chr(KeyAscii)
If KeyAscii >= vbKeyNumpad0() And KeyAscii <= vbKeyNumpad9() Then
lblOutput.Text = lblOutput.Text & Chr(KeyAscii)
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
KeyPreview = True
End Sub
Private Sub ButtonAppend(number As Integer)
If CInt(lblOutput.Text) = 0 Then
lblOutput.Text = CType(number, String)
Else
lblOutput.Text = lblOutput.Text & number
End If
End Sub
Private Sub operation(operand As String)
chrOperator = CChar(operand)
varFirstVal = CInt(lblOutput.Text)
lblOutput.Text = CType(0, String)
End Sub
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
ButtonAppend(1)
End Sub
Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
ButtonAppend(2)
End Sub
Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
ButtonAppend(3)
End Sub
Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click
ButtonAppend(4)
End Sub
Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click
ButtonAppend(5)
End Sub
Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click
ButtonAppend(6)
End Sub
Private Sub btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click
ButtonAppend(7)
End Sub
Private Sub btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click
ButtonAppend(8)
End Sub
Private Sub btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click
ButtonAppend(9)
End Sub
Private Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click
ButtonAppend(0)
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
lblOutput.Text = "0"
varFirstVal = 0
End Sub
Private Sub btnEquals_Click(sender As Object, e As EventArgs) Handles btnEquals.Click
Select Case chrOperator
Case CChar("A")
lblOutput.Text = CType(varFirstVal + CInt(lblOutput.Text), String)
Case CChar("S")
lblOutput.Text = CType(varFirstVal - CInt(lblOutput.Text), String)
Case CChar("M")
lblOutput.Text = CType(varFirstVal * CInt(lblOutput.Text), String)
Case CChar("D")
lblOutput.Text = CType(varFirstVal / CInt(lblOutput.Text), String)
End Select
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
operation("A")
End Sub
Private Sub btnSub_Click(sender As Object, e As EventArgs) Handles btnSub.Click
operation("S")
End Sub
Private Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click
operation("M")
End Sub
Private Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.Click
operation("S")
End Sub
End Class
What I want to get out of it is being able to use the numpad and never have to click anything on screen for the calculator to work.

Related

vb.net datagridview calculation based on category

How can I calculate the item price based on the category? Currently, I only can calculate the total value. What is the coding in order to do that?
Update:
Below is the code:
Public Class OrderCart
Private Sub OrderCart_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Dim Price As Double
Dim index As Integer
'calculate total price
For index = 0 To dgvCart.RowCount - 1
Price += dgvCart.Rows(index).Cells(5).Value
Next
lblTotalPriceOutput.Text = FormatCurrency(Price)
End Sub
Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBackToHome.Click
Home.Show()
End Sub
Private Sub btnCheckout_Click(sender As Object, e As EventArgs) Handles btnCheckout.Click
Payment.Show()
End Sub
Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
Dim i As Integer
'Dim index As Integer
If (dgvCart.RowCount <= 0) Then
MessageBox.Show("No item is selected!", "Remove Item",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
i = dgvCart.CurrentCell.RowIndex
dgvCart.Rows.RemoveAt(i)
End If
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
dgvCart.Rows.Clear()
End Sub
End Class

passing a parameter to fillby(vb.net)

I have problem passing a parameter to fillby
I made fill method call FillByA but there is problem!!
its said:
“too many arguments to ‘public override Overloads function fillbyA(data Table as ContactsDataSet.recordsDataTable) as integer’
This is my code:
Public Class Adminlogin
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text.Trim = "" Or TextBox2.Text.Trim = "" Then
MsgBox("you should complet ypur deails")
Else
//error happen here !
Me.AdminTableAdapter.FillByA(Me.UserDataSet1.Admin, Me.TextBox1.Text.Trim, Me.TextBox2.Text.Trim)
If Me.UserDataSet1.user.Count > 0 Then
Me.Close()
Test.Show()
Else
MsgBox("Logon failure, user name or password are incorrect!", MsgBoxStyle.Critical)
End If
End If
End Sub
Private Sub Ad_NameTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If IsNumeric(e.KeyChar.ToString()) Then
MessageBox.Show("Letters only!")
SendKeys.Send("{Backspace}")
End If
End Sub
Private Sub Ad_NameTextBox_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
admincon.Show()
End Sub
End Class

Setting a toggle key

I am currently making an autoclicker with human randomization.
The issue i am having is that i have no clue how to make a thing that you can bind a key and then make it run. This is my code so far, and also if you have any idea on how to improve the code then PLEASE share it, I mostly need to improve my randomization.
How can i make a thing so users can set their toggle key?
Public Class Form1
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Declare Function mouse_autoClicker Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean
Private Sub StartClick()
System.Windows.Forms.Cursor.Position = New System.Drawing.Point(System.Windows.Forms.Cursor.Position)
Call mouse_autoClicker(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call mouse_autoClicker(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
Private Sub TrackStart_Scroll(sender As Object, e As EventArgs) Handles TrackStart.Scroll
If TrackStart.Value > TrackEnd.Value Then
TrackStart.Value = TrackEnd.Value
End If
valstart.Text = trackstart.Value
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "ClickDevastator v.0.7"
End Sub
Private Sub TrackEnd_Scroll(sender As Object, e As EventArgs) Handles trackend.Scroll
If trackend.Value < trackstart.Value Then
trackend.Value = trackstart.Value
End If
ValEnd.Text = trackend.Value
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim rnd As New Random
Dim ClickString As Integer = rnd.Next(Val(valstart.Text), Val(ValEnd.Text))
txtRnd.Text = ClickString.ToString()
Timer2.Enabled = True
For i As Integer = 0 To Val(txtRnd.Text) - 1
StartClick()
Next
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnstart.Click
If btnstart.Text = "Start" Then
Timer1.Enabled = True
btnstart.Text = "Stop"
btnstart.ForeColor = Color.Red
ElseIf btnstart.Text = "Stop" Then
Timer1.Enabled = False
btnstart.Text = "Start"
btnstart.ForeColor = Color.LawnGreen
End If
End Sub
Private Sub btnClick_Click(sender As Object, e As EventArgs) Handles btnclick.Click
txtClick.Text = Val(txtClick.Text) + 1
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
valstart.Text = Date.Now.ToString("hh : mm : ss")
End Sub
Private Sub Timer1_Disposed(sender As Object, e As EventArgs) Handles Timer1.Disposed
Timer2.Enabled = False
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
If btnstart.Text = "Stop" Then
btnstart.PerformClick()
End If
End If
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btnstart.Click
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtRnd.TextChanged
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnclick.Click
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles ValEnd.Click
End Sub
Private Sub label1_Click_1(sender As Object, e As EventArgs) Handles valstart.Click
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Label1_Click_2(sender As Object, e As EventArgs)
End Sub
Private Sub trackstart_Scroll_1(sender As Object, e As EventArgs) Handles trackstart.Scroll
End Sub
Private Sub Label1_Click_3(sender As Object, e As EventArgs)
End Sub
Private Sub Label1_Click_4(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
End Class
A Toggle in code works on boolean values like this...
Button2.Enabled = Not (Button2.Enabled)

Do Process while Progress Bar is Running

I know that knowledge is expensive, but is there who want to help me
i want to run process when progress bar is running,
i try with this code
Public Class Form2
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call Prcss()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Progress.Value < 100 Then
Progress.Value += 2
ElseIf Progress.Value = 100 Then
Timer1.Stop()
Form1.Show()
Me.Hide()
End If
End Sub
Private Sub Prcss()
With Progress
.Value = 0
Threading.Thread.Sleep(450)
Label1.Text = "Renewing Custom Content"
.Value = 20
Threading.Thread.Sleep(450)
Label1.Text = "Getting Information"
.Value = 50
Threading.Thread.Sleep(450)
Label1.Text = "Downloading Udpdate"
.Value = 70
Threading.Thread.Sleep(450)
Label1.Text = "Ready to Start"
.Value = 100
End With
End Sub
i don't know where is my mistake, i read this on my book.
Try using a BackgroundWorker or a Thread:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For i As Integer = 1 To 1000
BackgroundWorker1.ReportProgress(CInt(i / 10))
Threading.Thread.Sleep(500)
Next
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MessageBox.Show("Finished!")
End Sub
This is the basic example and require you to add a BackgroundWorker to the form. You can see help here: https://msdn.microsoft.com/es-es/library/cc221403(v=vs.95).aspx

Vb.net Error then use form4.show

I have a little problem with my program. I just maked a little program. I have a problem with code "Form4.Show()".
I put this code on button and then press button I receive error:
An error occurred creating the form. See Exception.IneerException for details. The error is: Object reference not set to an instance of an object.
I don't know what code I put wrong ... this button have only form4.show.
PS: this error is from try catch.
This is button code.
Try
Form4.Show
Catch ex as Exception
MessageBox.Show(ex.Message)
End Try
edit: all form4 code
Public Class Form4
Dim txt As String = Textbox1.Text
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txt = "450IP-Gift"
Form5.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
txt = "450IP"
Form5.Show()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
txt = "1150IP-Gift"
Form5.Show()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
txt = "1150IP"
Form5.Show()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
txt = "3150IP-Gift"
Form5.Show()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
txt = "3150IP"
Form5.Show()
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
txt = "4800IP-Gift"
Form5.Show()
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
txt = "4800IP"
Form5.Show()
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
txt = "6300IP-Gift"
Form5.Show()
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
txt = "6300IP"
Form5.Show()
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
txt = "9600IP-Gift"
Form5.Show()
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
txt = "9600IP"
Form5.Show()
End Sub
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
Me.Close()
End Sub
End Class
You need to initialize form4
Try
Dim form4 = New Form4()
form4.Show()
Catch ex as Exception
MessageBox.Show(ex.Message)
End Try