Conversion from string "0-1" to type 'Double' is not valid error : VB.net - vb.net

Im trying to create a web browser is Visual Studio 2013 but i keep getting the error:
An exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll but was not handled in user code
Additional information: Conversion from string "0-1" to type 'Double' is not valid.
when I run the program.
The error occurred after i added a progress bar.
My Code:
Public Class Form1
Dim MyTemp As String = My.Settings.homepage
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click
MsgBox("Created by Lachlan Johnson" & vbCrLf & " (2016)", 0, "About")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
WebBrowser1.Navigate(TextBox1.Text)
e.Handled = True
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
WebBrowser1.Navigate("https://www.google.com.au/webhp#q=" + TextBox2.Text)
End Sub
Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
WebBrowser1.Navigate("https://www.google.com.au/webhp#q=" + TextBox2.Text)
e.Handled = True
End If
End Sub
Private Sub WebBrowser1_Navigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
ToolStripStatusLabel1.Text = "Loading..."
End Sub
Private Sub WebBrowser1_Navigated(sender As Object, e As WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
ToolStripStatusLabel1.Text = "Complete"
End Sub
Private Sub SetAsHomepageToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SetAsHomepageToolStripMenuItem.Click
My.Settings.homepage = WebBrowser1.Url.ToString
My.Settings.Save()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate(MyTemp)
End Sub
Private Sub WebBrowser1_ProgressChanged(sender As Object, e As WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
If Int(e.MaximumProgress > 0 & e.CurrentProgress > 0) Then
ToolStripProgressBar1.ProgressBar.Value = e.CurrentProgress * 100 / e.MaximumProgress
End If
End Sub
End Class
The error occured after i added this:
Private Sub WebBrowser1_ProgressChanged(sender As Object, e As WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
If Int(e.MaximumProgress > 0 & e.CurrentProgress > 0) Then
ToolStripProgressBar1.ProgressBar.Value = e.CurrentProgress * 100 / e.MaximumProgress
End If
End Sub
I cant seem to find the issue,
Any help is greatly appreciated.
Lachlan

The issue is that you're using a string concatenation operator here:
If Int(e.MaximumProgress > 0 & e.CurrentProgress > 0) Then
That should be:
If e.MaximumProgress > 0.0 AndAlso e.CurrentProgress > 0.0 Then

This
Int(e.MaximumProgress > 0 & e.CurrentProgress > 0)
Does a string concatenation of MaximumProgress and CurrentProgress. If CurrentProgress is -1 (indicating completion) and MaximumProgress is 0 (indicating the total number of bytes to be transferred is 0) then e.MaximumProgress > 0 & e.CurrentProgress > 0 will result in the string "0-1". Then the Int() function converts it's parameter, "0-1" into a double so it can truncate the decimal part and return just the integral part. The problem is, "0-1" isn't a valid double.

Related

VB Calculator add some functions

I have programmed a calculator with Visual Basic, but I would like to add a few more functions. But I can't figure out how to solve the following problems in my code:
if more than one zero is entered in the input field, it should simply delete the leading zeros.(example 0000111 -----> 111 or 0002345 ----> 2345)
likewise, a decimal number should not have several zeros before the decimal point (example 000.176 ----> 0.176)
furthermore, it should not be possible to enter two commas (Example 0.187.56 -----> should not be Possible -------------> 0.18756)
Could somebody help me ?
Public Class Form1
Public LCD As Single
Public OPZ As String
Private Sub LCDfuellen(sender As Object, e As EventArgs) Handles btn3.Click, btn2.Click, btn1.Click, btn9.Click, btn8.Click, btn7.Click, btn6.Click, btn5.Click, btn4.Click
txtLCD.Text &= ActiveControl.Tag
Replace(LTrim(Replace(txtLCD.Text, "0", " ")), " ", "0")
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtLCD.Clear()
End Sub
Private Sub btnCE_Click(sender As Object, e As EventArgs) Handles btnCE.Click
'txtLCD.Text = txtLCD.Text.Remove(txtLCD.TextLength - 1, 1)
txtLCD.Text = LSet(txtLCD.Text, txtLCD.TextLength - 1)
End Sub
Private Sub OPZlesen(sender As Object, e As EventArgs) Handles btnPlus.Click, btnMinus.Click, btnMal.Click, btnDurch.Click
LCD = CSng(txtLCD.Text)
txtLCD.Clear()
OPZ = ActiveControl.Tag
End Sub
Private Sub btnGleich_Click(sender As Object, e As EventArgs) Handles btnGleich.Click
Dim activeLCD As Single
activeLCD = CSng(txtLCD.Text)
Select Case OPZ
Case "+" : txtLCD.Text = CStr(LCD + activeLCD)
Case "-" : txtLCD.Text = CStr(LCD - activeLCD)
Case "*" : txtLCD.Text = CStr(LCD * activeLCD)
Case "/" : txtLCD.Text = CStr(LCD / activeLCD)
End Select
End Sub
Private Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click
txtLCD.Text &= ActiveControl.Tag
End Sub
Private Sub btnPunkt_Click(sender As Object, e As EventArgs) Handles btnPunkt.Click
txtLCD.Text &= ActiveControl.Tag
End Sub
End Class

How to use numpad as input in vb calculator

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.

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

I'm trying to open a form and getting this error

Okay, here is my code.
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 1000
ProgressBar1.Value = 1000
Timer1.Interval = 1750
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Form3.Show()
Me.Close()
End Sub
End Class
On the line Form3.Show() I get
InvalidOperationException was unhandled.
An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
What I have on Form3:
Public Class Form3
Public IPAddress As String = TextBox1.Text
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form4.Show()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Form4.varible1 = True Then
Label1.Text = "IP: " + IPAddress
End If
End Sub
End Class
Any help?
Change on form3
Public IPAddress As String = TextBox1.Text ...."TextBox1.Text is "" thats why you get the error"
To
Public IPAddress As String
End then add IPAddress = TextBox1.Text in you timer
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Form4.varible1 = True Then
IPAddress = TextBox1.Text
Label1.Text = "IP: " + IPAddress
End If
End Sub

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