trying to create a gridview in vb.net and every time a new row is overwritten on the first row help me with this code plz - vb.net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dt.Columns.Add("LR No")
dt.Columns.Add("Description")
dt.Columns.Add("Article")
dt.Columns.Add("Quantity")
dt.Columns.Add("Net Weight")
dt.Columns.Add("Gross Weight")
dt.Columns.Add("Freight")
dt.Columns.Add("Remark")
GridLRData.DataSource = dt
End Sub
Protected Sub BtnAddLRData_Click(sender As Object, e As EventArgs) Handles BtnAddLRData.Click
dt.Rows.Add(TxtLRNo.Text, TxtDescription.Text, DlArticle.Text, TxtQuantity.Text, TxtNetWeight.Text, TxtGrossWeight.Text, TxtFreight.Text, TxtRemark.Text)
GridLRData.DataSource = dt
GridLRData.DataBind()
TxtDescription.Text = ""
DlArticle.Text = ""
TxtQuantity.Text = ""
TxtNetWeight.Text = ""
TxtGrossWeight.Text = ""
TxtFreight.Text = ""
TxtRemark.Text = ""
End Sub

The solution below works correctly!
Public Class Form1
Private dt As DataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dt = New DataTable
dt.Columns.Add("LR No")
dt.Columns.Add("Description")
dt.Columns.Add("Article")
dt.Columns.Add("Quantity")
dt.Columns.Add("Net Weight")
dt.Columns.Add("Gross Weight")
dt.Columns.Add("Freight")
dt.Columns.Add("Remark")
GridLRData.DataSource = dt
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
dt.Rows.Add(TxtLRNo.Text, TxtDescription.Text, DlArticle.Text, TxtQuantity.Text, TxtNetWeight.Text, TxtGrossWeight.Text, TxtFreight.Text, TxtRemark.Text)
GridLRData.Refresh()
TxtDescription.Text = ""
DlArticle.Text = ""
TxtQuantity.Text = ""
TxtNetWeight.Text = ""
TxtGrossWeight.Text = ""
TxtFreight.Text = ""
TxtRemark.Text = ""
End Sub
End Class

Related

How can I make a VB.NET MDAS Calculator?

I already have a code but I do not know how to add the MDAS function. Here is my code:
Public Class Form1
'variables-----------------------------------------------------------------------------
Dim inp As Double = 0
Dim oprtn As String
Dim expr As Boolean = False
'numbers and decimal input-----------------------------------------------------------------------------
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Number1.Click, Number9.Click, Number8.Click, Number7.Click, Number6.Click, Number5.Click, Number4.Click, Number3.Click, Number2.Click, Number0.Click, Period.Click
Dim num As Button = sender
If ((TextBox1.Text = "0") Or (expr)) Then
TextBox1.Clear()
TextBox1.Text = num.Text
expr = False
ElseIf (num.Text = ".") Then
If (Not TextBox1.Text.Contains(".")) Then
TextBox1.Text = TextBox1.Text + num.Text
End If
Else
TextBox1.Text = TextBox1.Text + num.Text
End If
End Sub
'operators button-----------------------------------------------------------------------------
Private Sub oprtrs(sender As Object, e As EventArgs) Handles PlusSign.Click, MinusSign.Click, MultiplySign.Click, DivideSign.Click
Dim operations As Button = sender
If (inp <> 0) Then
Equals.PerformClick()
expr = True
oprtn = operations.Text
Label1.Text = inp & " " & oprtn
Else
oprtn = operations.Text
inp = Double.Parse(TextBox1.Text)
expr = True
Label1.Text = inp & " " & oprtn
End If
End Sub
'equals button-----------------------------------------------------------------------------
Private Sub Equal_Click(sender As Object, e As EventArgs) Handles Equals.Click
Label1.Text = ""
Select Case oprtn
Case "+"
TextBox1.Text = (inp + Double.Parse(TextBox1.Text)).ToString()
Case "-"
TextBox1.Text = (inp - Double.Parse(TextBox1.Text)).ToString()
Case "*"
TextBox1.Text = (inp * Double.Parse(TextBox1.Text)).ToString()
Case "/"
TextBox1.Text = (inp / Double.Parse(TextBox1.Text)).ToString()
End Select
inp = Double.Parse(TextBox1.Text)
oprtn = ""
End Sub
'other buttons-----------------------------------------------------------------------------
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Backspace.Click
If TextBox1.Text < " " Then
TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1 + 1)
Else
TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1)
End If
End Sub
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Clear.Click
TextBox1.Text = "0"
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles ClearEverything.Click
TextBox1.Text = "0"
Label1.Text = ""
End Sub
Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Prcent.Click
Dim percent As Double
percent = Convert.ToDouble(TextBox1.Text) / Convert.ToDouble(100)
TextBox1.Text = System.Convert.ToString(percent)
End Sub
Private Sub Button21_Click(sender As Object, e As EventArgs) Handles SqrRoot.Click
Dim squared As Double
squared = Math.Sqrt(TextBox1.Text)
TextBox1.Text = System.Convert.ToString(squared)
Label1.Text = "Sqr(" & System.Convert.ToString(squared) & ")"
End Sub
Private Sub Button22_Click(sender As Object, e As EventArgs) Handles RaiseTwo.Click
Dim expo2 As Double
expo2 = Convert.ToDouble(TextBox1.Text) * Convert.ToDouble(TextBox1.Text)
TextBox1.Text = System.Convert.ToString(expo2)
End Sub
Private Sub Button23_Click(sender As Object, e As EventArgs) Handles RaiseThree.Click
Dim expo3 As Double
expo3 = Convert.ToDouble(TextBox1.Text) * Convert.ToDouble(TextBox1.Text) * Convert.ToDouble(TextBox1.Text)
TextBox1.Text = System.Convert.ToString(expo3)
End Sub
Private Sub Button24_Click(sender As Object, e As EventArgs) Handles OneOver.Click
Dim ov1 As Double
ov1 = Convert.ToDouble(1.0 / Convert.ToDouble(TextBox1.Text))
TextBox1.Text = System.Convert.ToString(ov1)
End Sub
End Class
Thats pretty much all I have done, it works as intended, BUT it does not follow MDAS which prioritizes Multiplication first followed by Division then Addition then Subtraction. My design goes like this:
I started with the interface first then code, I haven't really designed it yet. This is just to give you an idea what is already coded or included in the code. Every button functions as should be.
This is what David is talking about.
There is very little code needed.
Public Class ExpressionCalculator
Private Sub Buttons_Click(sender As Object, e As EventArgs) Handles ButtonPlus.Click, ButtonMultiply.Click, ButtonMinus.Click, ButtonDot.Click, ButtonDivide.Click, Button9.Click, Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, Button2.Click, Button10.Click, Button1.Click
Dim tb = DirectCast(sender, Button)
TextBox1.Text &= tb.Text
End Sub
Private Sub ButtonCalculate_Click(sender As Object, e As EventArgs) Handles ButtonCalculate.Click
Dim table = New DataTable()
Dim result = table.Compute(TextBox1.Text, Nothing)
TextBox1.Text = result.ToString
End Sub
End Class

Add items to listview after cleared

I am adding all the textboxes and labels to display in the listview. When I click the clear button everything on my form clears as it should, but when I then want to add more items to the listview, nothing displays in the listview, and my header information is also cleared. Can someone please assist?
Public Class Form2
Dim decTotalDue As Decimal
Dim intTotalItems As Integer
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles txtUnitPrice.TextChanged
End Sub
Private Sub btnAddItem_Click(sender As Object, e As EventArgs) Handles btnAddItem.Click
Dim decUnitPrice As Decimal
Dim intQuantity As Integer
Dim decTotal As Decimal
Dim decTotalPayable As Decimal
Dim item As New ListViewItem
Decimal.TryParse(txtUnitPrice.Text, decUnitPrice)
Integer.TryParse(txtQuantity.Text, intQuantity)
decTotal = decUnitPrice * intQuantity
lblTotal.Text = decTotal.ToString("C2")
decTotalDue = decTotal + decTotalDue
lblTotalDue.Text = decTotalDue.ToString("C2")
intTotalItems = intQuantity + intTotalItems
lblTotalItems.Text = intTotalItems.ToString
decTotalPayable = decTotalDue
lblTotalPayable.Text = decTotalPayable.ToString("C2")
lblTotalPayable.Hide()
lblTotalItems.Hide()
item = ListView1.Items.Add(cboItemName.Text)
item.SubItems.Add(txtUnitPrice.Text)
item.SubItems.Add(txtQuantity.Text)
item.SubItems.Add(lblTotal.Text)
ListView1.ForeColor = Color.White
txtUnitPrice.Text = decUnitPrice.ToString("C2")
End Sub
Private Sub btnPurchase_Click(sender As Object, e As EventArgs) Handles btnPurchase.Click
lblTotalItems.Show()
lblTotalPayable.Show()
cboItemName.Text = String.Empty
txtUnitPrice.Clear()
txtQuantity.Clear()
lblTotal.Text = ""
lblTotalDue.Text = ""
ListView1.Clear()
End Sub
Private Sub btnCalculateChange_Click(sender As Object, e As EventArgs) Handles btnCalculateChange.Click
Dim decCashTenderted As Decimal
Dim decChange As Decimal
Decimal.TryParse(txtCashTendered.Text, decCashTenderted)
txtCashTendered.Text = decCashTenderted.ToString("C2")
decChange = decCashTenderted - decTotalDue
lblChange.Text = decChange.ToString("C2")
If decCashTenderted < decTotalDue Then
MessageBox.Show("Cash Tendered is less than Total Due", "Invalid", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning)
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
cboItemName.Text = String.Empty
txtCashTendered.Clear()
txtUnitPrice.Clear()
txtQuantity.Clear()
lblTotalDue.Text = ""
lblTotalItems.Text = ""
lblTotalPayable.Text = ""
lblChange.Text = ""
ListView1.Clear()
End Sub
Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
End Sub
End Class
MSDN on the behaviour of the Clear function is:
You can use this method to remove all items and columns from the ListView control without having to call the individual Clear methods from the ListView.ColumnHeaderCollection and ListView.ListViewItemCollection classes.
From what you describe you want, you should be doing is calling:
ListView1.Items.Clear()
This will remove just the items that are displayed and not remove the column definitions.

MS Access Query In VB.NET 2008

The below code works in this way: When I enter data inside my textboxes, they go straight to my database and then if I click up button on the numeric up and down, it will give me empty textboxes to put data on again.
If I click on the down button in the numeric up and down, it will show me the previous data I entered in their respective textboxes. That's exactly what I have been wanting to do, but the problem is it only updates the database (obviously because of the UPDATE query) and overwrites the previously saved data.
Is there anyway that I can still achieve the same result (the one I mentioned about still being able to see the data I entered previously by the use of the numeric up and down) but the data previously stored in the database will not be overwritten?
Imports System.Data.OleDb
Public Class Form1
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim tables As DataTableCollection
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form2.ShowDialog()
Form2.Dispose()
End Sub
Private Sub RadioButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton1.Click
Label1.Text = "1"
Button1.PerformClick()
End Sub
Private Sub RadioButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton2.Click
Label1.Text = "2"
Button1.PerformClick()
End Sub
Private Sub RadioButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton3.Click
Label1.Text = "3"
Button1.PerformClick()
End Sub
Private Sub RadioButton4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton4.Click
Label1.Text = "4"
Button1.PerformClick()
End Sub
Public Sub clear()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
TextBox1.Select()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
NumericUpDown1.Value = ComboBox1.SelectedIndex
Dim dr As DataRow
Dim i As Integer
If Integer.TryParse(ComboBox1.SelectedValue.ToString, i) Then
i = ComboBox1.SelectedValue - 1
End If
dr = ds.Tables(0).Rows(i)
TextBox1.Text = dr("Question").ToString
TextBox2.Text = dr("Answer1").ToString
TextBox3.Text = dr("Answer2").ToString
TextBox4.Text = dr("Answer3").ToString
TextBox5.Text = dr("Answer4").ToString
Label1.Text = dr("RightAnswer").ToString
Label8.Text = ComboBox1.Text
If Label1.Text = "1" Then
RadioButton1.Checked = True
ElseIf Label1.Text = "2" Then
RadioButton2.Checked = True
ElseIf Label1.Text = "3" Then
RadioButton3.Checked = True
ElseIf Label1.Text = "4" Then
RadioButton4.Checked = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.Open()
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [Questions]", con)
da.Fill(ds, "Questions")
Dim view1 As New DataView(tables(0))
With ComboBox1
.DataSource = ds.Tables("Questions")
.ValueMember = "ID"
.DisplayMember = "ID"
.SelectedIndex = 0
End With
con.Close()
ComboBox1.SelectedIndex = NumericUpDown1.Value
NumericUpDown1.Value = ComboBox1.SelectedIndex
NumericUpDown1.Maximum = ComboBox1.Items.Count - 1
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
ComboBox1.SelectedIndex = NumericUpDown1.Value
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
con.Open()
Dim update_user As New Data.OleDb.OleDbCommand("UPDATE Questions SET [Question]= #Q, [Answer1]= #A1, [Answer2]= #A2, [Answer3]= #A3, [Answer4]= #A4, [RightAnswer]= #RA WHERE ID = #ID;", con)
update_user.Parameters.AddWithValue("#Q", TextBox1.Text)
update_user.Parameters.AddWithValue("#A1", TextBox2.Text)
update_user.Parameters.AddWithValue("#A2", TextBox3.Text)
update_user.Parameters.AddWithValue("#A3", TextBox4.Text)
update_user.Parameters.AddWithValue("#A4", TextBox5.Text)
update_user.Parameters.AddWithValue("#RA", Label1.Text)
update_user.Parameters.AddWithValue("#ID", Label8.Text)
update_user.ExecuteNonQuery()
update_user.Dispose()
con.Close()
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [Questions]", con)
da.Fill(ds, "Questions")
End Sub
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox5_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox5.KeyUp
Button1.PerformClick()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Enabled = True
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
NumericUpDown1.Enabled = False
If NumericUpDown1.Value = NumericUpDown1.Value + 1 Then
NumericUpDown1.Value = NumericUpDown1.Value - 1
End If
Else
NumericUpDown1.Enabled = True
End If
End Sub
End Class

VB.Net - Noncooperative decimal in string

I am writing a calculator WinForm in VB. I have a label used to display the output "Result". My problem comes when trying to add a "." to my label string. Example: I will type 355.5 and until the 5 is pressed after it, my string is showing up as .355 After the last 5 is pressed, it jumps into the correct location. I have exhausted my debugging skill and now am just going crazy. Anyone encounter this before?
Here's my entire code so far (ignore unfinished functions)
Public Class MyCalc
Private bDecFlag As Boolean
Private sMathOp As String
Private Sub ModeSel_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ModeSel.SelectedIndexChanged
If ModeSel.SelectedIndex = 3 Then
Me.Width = 360
ElseIf ModeSel.SelectedIndex > 2 Then
Me.Width = 590
Else
Me.Width = 250
End If
If ModeSel.SelectedIndex = 0 Then
For iCount As Integer = 0 To 9
Me.Controls("Digit" & iCount).Enabled = True
Next
End If
If ModeSel.SelectedIndex = 1 Then
For iCount As Integer = 2 To 9
Me.Controls("Digit" & iCount).Enabled = False
Next
End If
If ModeSel.SelectedIndex = 2 Then
For iCount As Integer = 0 To 7
Me.Controls("Digit" & iCount).Enabled = True
Next
Digit8.Enabled = False
Digit9.Enabled = False
End If
If ModeSel.SelectedIndex = 3 Then
For iCount As Integer = 0 To 9
Me.Controls("Digit" & iCount).Enabled = True
Next
For iCount As Integer = Asc("A") To Asc("F")
Me.Controls("Alpha" & Chr(iCount)).Enabled = True
Next
For iCount As Integer = Asc("G") To Asc("Z")
Me.Controls("Alpha" & Chr(iCount)).Enabled = False
Next
End If
If ModeSel.SelectedIndex = 4 Then
For iCount As Integer = 0 To 9
Me.Controls("Digit" & iCount).Enabled = True
Next
For iCount As Integer = Asc("A") To Asc("Z")
Me.Controls("Alpha" & Chr(iCount)).Enabled = True
Next
AlphaA.Enabled = False
AlphaE.Enabled = False
AlphaI.Enabled = False
AlphaO.Enabled = False
AlphaU.Enabled = False
End If
End Sub
Private Sub Digit0_Click(sender As System.Object, e As System.EventArgs) Handles Digit0.Click
UpdateResult(0)
End Sub
Private Sub Digit1_Click(sender As System.Object, e As System.EventArgs) Handles Digit1.Click
UpdateResult(1)
End Sub
Private Sub Digit2_Click(sender As System.Object, e As System.EventArgs) Handles Digit2.Click
UpdateResult(2)
End Sub
Private Sub Digit3_Click(sender As System.Object, e As System.EventArgs) Handles Digit3.Click
UpdateResult(3)
End Sub
Private Sub Digit4_Click(sender As System.Object, e As System.EventArgs) Handles Digit4.Click
UpdateResult(4)
End Sub
Private Sub Digit5_Click(sender As System.Object, e As System.EventArgs) Handles Digit5.Click
UpdateResult(5)
End Sub
Private Sub Digit6_Click(sender As System.Object, e As System.EventArgs) Handles Digit6.Click
UpdateResult(6)
End Sub
Private Sub Digit7_Click(sender As System.Object, e As System.EventArgs) Handles Digit7.Click
UpdateResult(7)
End Sub
Private Sub Digit8_Click(sender As System.Object, e As System.EventArgs) Handles Digit8.Click
UpdateResult(8)
End Sub
Private Sub Digit9_Click(sender As System.Object, e As System.EventArgs) Handles Digit9.Click
UpdateResult(9)
End Sub
Private Sub DecBut_Click(sender As System.Object, e As System.EventArgs) Handles DecBut.Click
If bDecFlag = False Then
If Result.Text = "0" Then
Result.Text = "0."
bDecFlag = True
Else
Result.Text = Result.Text + "."
bDecFlag = True
End If
End If
End Sub
Private Sub ClrBut_Click(sender As System.Object, e As System.EventArgs) Handles ClrBut.Click
Result.Text = 0
bDecFlag = False
End Sub
Private Sub DelBut_Click(sender As System.Object, e As System.EventArgs) Handles DelBut.Click
If Result.Text = "0" Then
ElseIf Result.Text.Substring(Result.Text.Length - 1) = "." Then
Result.Text = Result.Text.Substring(0, Result.Text.Length - 1)
bDecFlag = False
Else
Result.Text = Result.Text.Substring(0, Result.Text.Length - 1)
If Result.Text = "" Then
Result.Text = "0"
End If
End If
End Sub
Private Sub MyCalc_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.NumPad0
Digit0_Click(Digit0, New EventArgs)
Case Keys.NumPad1
Digit1_Click(Digit1, New EventArgs)
Case Keys.NumPad2
Digit2_Click(Digit2, New EventArgs)
Case Keys.NumPad3
Digit3_Click(Digit3, New EventArgs)
Case Keys.NumPad4
Digit4_Click(Digit4, New EventArgs)
Case Keys.NumPad5
Digit5_Click(Digit5, New EventArgs)
Case Keys.NumPad6
Digit6_Click(Digit6, New EventArgs)
Case Keys.NumPad7
Digit7_Click(Digit7, New EventArgs)
Case Keys.NumPad8
Digit8_Click(Digit8, New EventArgs)
Case Keys.NumPad9
Digit9_Click(Digit9, New EventArgs)
Case Keys.Back
DelBut_Click(DelBut, New EventArgs)
Case Keys.Decimal
DecBut_Click(DecBut, New EventArgs)
End Select
End Sub
Private Sub MyCalc_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
bDecFlag = False
End Sub
Public Sub UpdateResult(ByVal sNum As String)
If Result.Text = "0" Then
Result.Text = sNum
Else
Result.Text &= sNum
End If
End Sub
End Class
So after the long debugging, I found out that you are using the Label/Textbox RightToLeft property set to yes. Nothing is wrong with it really, but it can't handle special characters including decimal points, commas, etc. properly. The workaround for this is to reverse what we have expected - to reverse the string concatenation.
Result.Text = "." & Result.Text
Not seeing entire code I'm not exactly sure but I think there might be something wrong with string concatenation.
Try changing into this:
Result.Text = Result.Text & "."

VB.net Web Browser - Adding Bookmarks

I have a web browser that I am trying to keep to the minimal to keep it running fast (I have the firefox gecko browser engine even though that doesn't matter for this question I think.) but there is one thing I want to add and that is bookmarks. Right now I have a ton of messy code but I wasn't able to create a new tool strip button for each time I hit the bookmark button. So what I did is I added the appropriate settings and 6 toolstrip buttons. Now this limits me to 6 bookmarks. Which really sucks. My code is here:
Imports System.IO
Public Class tabForm
Dim ico As Image = Nothing
Private Sub goBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles goBack.Click
webBrowser.GoBack()
End Sub
Private Sub goForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles goForward.Click
webBrowser.GoForward()
End Sub
Private Sub Navigate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Navigate.Click
If urlBox.Text = "yt" Then
webBrowser.Navigate("http://www.youtube.com")
ElseIf urlBox.Text = "fb" Then
webBrowser.Navigate("http://www.facebook.com")
ElseIf urlBox.Text = "gm" Then
webBrowser.Navigate("http://www.gmail.com")
ElseIf urlBox.Text = "go" Then
webBrowser.Navigate("http://www.google.com")
Else
webBrowser.Navigate(urlBox.Text)
End If
End Sub
Private Sub webBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As System.EventArgs) Handles webBrowser.DocumentCompleted
Me.Text = webBrowser.DocumentTitle
geticon()
End Sub
Private Sub webBrowser_Navigated(ByVal sender As System.Object, ByVal e As Skybound.Gecko.GeckoNavigatedEventArgs) Handles webBrowser.Navigated
Try
urlBox.Text = webBrowser.Url.ToString
Catch ex As Exception
End Try
End Sub
Private Sub urlBox_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles urlBox.KeyDown
Try
If e.KeyCode = Keys.Enter Then
If urlBox.Text = "yt" Then
webBrowser.Navigate("http://www.youtube.com")
ElseIf urlBox.Text = "fb" Then
webBrowser.Navigate("http://www.facebook.com")
ElseIf urlBox.Text = "gm" Then
webBrowser.Navigate("http://www.gmail.com")
ElseIf urlBox.Text = "go" Then
webBrowser.Navigate("http://www.google.com")
Else
webBrowser.Navigate(urlBox.Text)
End If
e.SuppressKeyPress = True
End If
Catch ex As Exception
End Try
End Sub
Private Sub geticon()
Try
Dim url As Uri = New Uri(webBrowser.Url.ToString)
If url.HostNameType = UriHostNameType.Dns Then
' Get the URL of the favicon
' url.Host will return such string as www.google.com
Dim iconURL = "http://" & url.Host & "/favicon.ico"
' Download the favicon
Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(iconURL)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim stream As System.IO.Stream = response.GetResponseStream()
Dim favicon = Image.FromStream(stream)
' Display the favicon on ToolStripLabel1
Me.favicon.Image = favicon
End If
Catch ex As Exception
Me.favicon.Image = Nothing
End Try
End Sub
Private Sub favicon_timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles favicon_timer.Tick
Try
Catch ex As Exception
End Try
End Sub
Private Sub Reload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reload.Click
webBrowser.Reload()
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
webBrowser.Navigate(My.Settings.mark1)
End Sub
Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
webBrowser.Navigate(My.Settings.mark6)
End Sub
Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
webBrowser.Navigate(My.Settings.mark5)
End Sub
Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
webBrowser.Navigate(My.Settings.mark4)
End Sub
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
webBrowser.Navigate(My.Settings.mark3)
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
webBrowser.Navigate(My.Settings.mark2)
End Sub
Private Sub Fav_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ToolStripButton7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton7.Click
If ToolStripButton1.Text = webBrowser.DocumentTitle Then
ToolStripButton1.Text = ""
My.Settings.mark1 = ""
My.Settings.mark11 = ""
ToolStripButton1.Visible = False
End If
If ToolStripButton2.Text = webBrowser.DocumentTitle Then
ToolStripButton2.Text = ""
My.Settings.mark2 = ""
My.Settings.mark22 = ""
ToolStripButton2.Visible = False
End If
If ToolStripButton3.Text = webBrowser.DocumentTitle Then
ToolStripButton3.Text = ""
My.Settings.mark3 = ""
My.Settings.mark33 = ""
ToolStripButton3.Visible = False
End If
If ToolStripButton4.Text = webBrowser.DocumentTitle Then
ToolStripButton4.Text = ""
My.Settings.mark4 = ""
My.Settings.mark44 = ""
ToolStripButton4.Visible = False
End If
If ToolStripButton5.Text = webBrowser.DocumentTitle Then
ToolStripButton5.Text = ""
My.Settings.mark5 = ""
My.Settings.mark55 = ""
ToolStripButton5.Visible = False
End If
If ToolStripButton6.Text = webBrowser.DocumentTitle Then
ToolStripButton6.Text = ""
My.Settings.mark6 = ""
My.Settings.mark66 = ""
ToolStripButton6.Visible = False
End If
End Sub
Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
If ToolStripButton1.Text = "" Then
ToolStripButton1.Text = webBrowser.DocumentTitle
My.Settings.mark1 = webBrowser.Url.ToString
My.Settings.mark11 = webBrowser.DocumentTitle
ToolStripButton1.Visible = True
ElseIf ToolStripButton2.Text = "" Then
ToolStripButton2.Text = webBrowser.DocumentTitle
My.Settings.mark2 = webBrowser.Url.ToString
My.Settings.mark22 = webBrowser.DocumentTitle
ToolStripButton2.Visible = True
ElseIf ToolStripButton3.Text = "" Then
ToolStripButton3.Text = webBrowser.DocumentTitle
My.Settings.mark3 = webBrowser.Url.ToString
My.Settings.mark33 = webBrowser.DocumentTitle
ToolStripButton3.Visible = True
ElseIf ToolStripButton4.Text = "" Then
ToolStripButton4.Text = webBrowser.DocumentTitle
My.Settings.mark4 = webBrowser.Url.ToString
My.Settings.mark44 = webBrowser.DocumentTitle
ToolStripButton4.Visible = True
ElseIf ToolStripButton5.Text = "" Then
ToolStripButton5.Text = webBrowser.DocumentTitle
My.Settings.mark5 = webBrowser.Url.ToString
My.Settings.mark55 = webBrowser.DocumentTitle
ToolStripButton5.Visible = True
ElseIf ToolStripButton6.Text = "" Then
ToolStripButton6.Text = webBrowser.DocumentTitle
My.Settings.mark6 = webBrowser.Url.ToString
My.Settings.mark66 = webBrowser.DocumentTitle
ToolStripButton6.Visible = True
Else
End If
End Sub
Private Sub ToolStripButton9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton9.Click
Dim newFav As New ToolStripButton
newFav.Text = webBrowser.Url.ToString
newFav.PerformClick()
End Sub
Private Sub favClick()
End Sub
Private Sub tabForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Settings.mark1 <> "" And My.Settings.mark11 <> "" Then
ToolStripButton1.Text = My.Settings.mark11
ToolStripButton1.Visible = True
End If
If My.Settings.mark2 <> "" And My.Settings.mark22 <> "" Then
ToolStripButton2.Text = My.Settings.mark22
ToolStripButton2.Visible = True
End If
If My.Settings.mark3 <> "" And My.Settings.mark33 <> "" Then
ToolStripButton3.Text = My.Settings.mark33
ToolStripButton3.Visible = True
End If
If My.Settings.mark4 <> "" And My.Settings.mark44 <> "" Then
ToolStripButton4.Text = My.Settings.mark44
ToolStripButton4.Visible = True
End If
If My.Settings.mark5 <> "" And My.Settings.mark55 <> "" Then
ToolStripButton5.Text = My.Settings.mark55
ToolStripButton5.Visible = True
End If
If My.Settings.mark6 <> "" And My.Settings.mark66 <> "" Then
ToolStripButton6.Text = My.Settings.mark66
ToolStripButton6.Visible = True
End If
End Sub
End Class
That's all of it. But as I said earlier I could only add 6 bookmarks. Is there any way I can add an unlimited number of bookmarks. I tried something like this:
Private Sub Bookmark()
Dim mark As New ToolStripButton
mark.DisplayStyle = Text
mark.Parent = ToolStrip1 'This didn't work
End Sub
But if I did get that to work what would I put to make it navigate to that page? Please help.
I finally found the answer to this. If anybody wondering where here is the link:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/eebcf40a-dec9-41ae-8e8b-3d446cf93322/web-browser-bookmarks-bar
Have a nice day.
create a class called favorite and a setting called favorites of type system.collections.specialized.stringcollection
public class favorite
inherits toolstripsplitbutton
public mytitle as string
public myurl as string
public myimg as image
public mybrowser as webbrowser
public sub new(title as string, url as string, browser as webbrowser)
mybase.new()
mytitle = title
myurl = url
'create a getfavicon function - Google :)
myimg = GetFavicon(myurl)
mybrowser = browser
me.text = mytitle
me.tooltiptext = mytitle + " : " + myurl
me.image = myimg
end sub
private sub Favorite_Click(sender as object, e as eventargs) handles me.click
browser.navigate(myurl)
end sub
then in your form code add a sub
public sub AddFav() handles '>>the add favorite button<<.click
my.settings.favorites.add(webbrowser.documenttitle + "|" + webbrowser.url.tostring)
my.settings.save()
end sub
public sub RefreshFavs()
for each fav as string in my.settings.favorites
dim favarray as array = fav.split(new char() {"|"c})
dim x as new favorite(favarray(0), favarray(favarray.count - 1, webbrowser)
mytoolstrip.items.add(x)
next
end sub
simple explanation:
AddFav() - save favorites with page title and url
RefreshFavs() - splits each setting by the "|" which the title and url are seperated
Class Favorite() - allows you to add a splitbutton that navigates the linked browser to it's myurl variable.
hope this helps. sorry if its a little crude, I had to recall it from my memory.