Visual Basic How to compare 3 values in a label? - vb.net

I have tried every possible combination, but I just can't get it to work right. This game needs to test if all 3 dice are the same, and if so, the point value goes up by one and is displayed in lblPoints.
Here is the specific line of code that I need to change:
If (lblDice.Text = lblDice2.Text) And (lblDice2.Text = lblDice3.Text) Then
Points += 1
End If
Below is the whole game if that helps:
Dim randomObject As New Random()
Dim n, m, o, p As Integer
Dim RollNumber = 1
Dim TurnNumber As Integer
Dim Points As Integer
Private Sub btnRoll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRoll.Click
lblPoints.Text = Points
If (lblDice.Text = lblDice2.Text) And (lblDice2.Text = lblDice3.Text) Then
Points += 1
End If
If btnHold.Enabled = True Then
Timer1.Enabled = True
End If
If btnHold2.Enabled = True Then
Timer2.Enabled = True
End If
If btnHold3.Enabled = True Then
Timer3.Enabled = True
End If
TurnNumber += 1
lblTurns.Text = TurnNumber
If TurnNumber = 3 Then
RollNumber += 1
TurnNumber = 0
End If
lblRolls.Text = RollNumber
If RollNumber = 5 Then
btnRoll.Enabled = False
If Points = 0 Or 1 Then
lblPoints2.Text = "You have done poorly"
ElseIf Points = 2 Or 3 Then
lblPoints2.Text = "Mediocre at best"
ElseIf Points = 4 Then
lblPoints2.Text = "Almost perfect"
ElseIf Points = 5 Then
lblPoints2.Text = "Almost perfect"
picJackpot.Visible = True
End If
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
m = m + 1
If m < 10 Then
n = randomObject.Next(1, 7)
lblDice.Text = n
die1PictureBox.Image = ImageList1.Images(n - 1)
Else
Timer1.Enabled = False
m = 0
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
m = m + 1
If m < 10 Then
n = randomObject.Next(1, 7)
lblDice2.Text = n
die2PictureBox.Image = ImageList1.Images(n - 1)
Else
Timer2.Enabled = False
m = 0
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
m = m + 1
If m < 10 Then
n = randomObject.Next(1, 7)
lblDice3.Text = n
die3PictureBox.Image = ImageList1.Images(n - 1)
Else
Timer3.Enabled = False
m = 0
End If
End Sub
Private Sub btnHold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHold.Click
btnHold.Enabled = False
btnUnhold.Enabled = True
End Sub
Private Sub btnUnhold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnhold.Click
btnHold.Enabled = True
btnUnhold.Enabled = False
End Sub
Private Sub btnHold2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHold2.Click
btnHold2.Enabled = False
btnUnhold2.Enabled = True
End Sub
Private Sub btnUnhold2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnhold2.Click
btnHold2.Enabled = True
btnUnhold2.Enabled = False
End Sub
Private Sub btnHold3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHold3.Click
btnHold3.Enabled = False
btnUnhold3.Enabled = True
End Sub
Private Sub btnUnhold3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnhold3.Click
btnHold3.Enabled = True
btnUnhold3.Enabled = False
End Sub
Private Sub btnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestart.Click
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Are you sure you want to start a new game? If not, you can select 'No' to continue with your current game."
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "New Game"
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
Reset()
End If
End Sub
Private Sub ColorChangeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorChangeToolStripMenuItem.Click
'Notice the ... in the menu...that means a dialog box will come
Dim dialog As New ColorDialog ' Color Dialog
Dim result As DialogResult ' stores Button clicked
dialog.FullOpen = True ' show all colors
result = dialog.ShowDialog
' do nothing if user clicked dialog's Cancel Button
If result <> Windows.Forms.DialogResult.Cancel Then
' assign new color to Paint object
Label1.ForeColor = dialog.Color
End If
End Sub
Private Sub FontChangeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontChangeToolStripMenuItem.Click
'Notice the ... in the menu...that means a dialog box will come
Dim dialog As New FontDialog ' Font Dialog
Dim result As DialogResult ' stores Button clicked
' show dialog and get result
result = dialog.ShowDialog()
' do nothing if user clicked dialog's Cancel Button
If result <> Windows.Forms.DialogResult.Cancel Then
' assign new font value to TextBox
If Windows.Forms.DialogResult.OK = MessageBox.Show("Changing Font. Click Ok to Change,\n Cancel for no change to occur.", _
"Warning", MessageBoxButtons.OKCancel) Then
Label1.Font = dialog.Font
End If
End If
End Sub
Private Sub SelectAColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAColorToolStripMenuItem.Click
Dim dialog As New ColorDialog ' Color Dialog
Dim result As DialogResult ' stores Button clicked
dialog.FullOpen = True ' show all colors
result = dialog.ShowDialog()
' do nothing if user clicked dialog's Cancel Button
If result <> Windows.Forms.DialogResult.Cancel Then
Me.BackColor = dialog.Color
End If
End Sub
Private Sub SelectAnImageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAnImageToolStripMenuItem.Click
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Are you sure you want to see what happens when you get a perfect score without actually playing? That's cheating.. and will reset the game!"
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "New Game"
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
Dim FileChooser As New OpenFileDialog()
Dim result As DialogResult
result = DialogResult = FileChooser.ShowDialog()
If result <> Windows.Forms.DialogResult.Cancel Then
If FileChooser.FileName <> "" Then
Me.BackgroundImage = System.Drawing.Image.FromFile(FileChooser.FileName)
Reset()
Else
MessageBox.Show("No Change Made. File Not Selected!", "Warning", _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Exclamation)
End If
End If
End If
End Sub
Private Sub btnHow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHow.Click
MessageBox.Show(" You will have 5 rolls. In each roll you have up to 3 turns. Your object in each of the turns is to get three of a kind on the dice. You can hold some die and roll only some of the die, or you can reroll all the dice. If in a turn you get three of a kind, you get a point. At the end of 5 turns you could have a maximum of 5 points and you will get a special prize.")
End Sub
Sub Reset()
RollNumber = 1
lblRolls.Text = RollNumber
TurnNumber = 0
lblTurns.Text = TurnNumber
Points = 0
lblPoints.Text = Points
lblPoints2.Text = ""
btnRoll.Enabled = True
btnHold.Enabled = True
btnHold2.Enabled = True
btnHold3.Enabled = True
btnUnhold.Enabled = False
btnUnhold2.Enabled = False
btnUnhold3.Enabled = False
die1PictureBox.Image = Nothing
die2PictureBox.Image = Nothing
die3PictureBox.Image = Nothing
lblDice.Text = ""
lblDice2.Text = ""
lblDice3.Text = ""
End Sub
End Class

What is happening is you are getting a valid compare on "" after you run your Reset Subroutine and when you start your program, because your dice are initialized to the same value. Try using a Boolean value to represent a fresh game, that way when your dice are starting from scratch you will not get a match. Something like this.
add a Boolean variable to your declarations
Dim Restart as Boolean = True
In your BtnRoll_Click EventHandler
If Not restart Then
If (lblDice.Text = lblDice2.Text) And (lblDice2.Text = lblDice3.Text) Then
Points += 1
End If
End If
Restart = False
and add this to the end of your Reset Subroutine.
Restart = True

Try
If String.Compare(lblDice.Text, lblDice2.Text) = 0 And String.Compare(lblDice2.Text, lblDice3.Text) = 0 Then
Points += 1
Else

tente (val(text.text)) then
exemplo if text1 = (val(text2.text)) then
text1 =0
end if

Related

VB.Net Move an object[Error]

i just start create a project with this(To The Topic)
an error is start in here(maybe)
First Button Code
Private Sub DeimosButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeimosButton2.Click
State(i)
DeimosButton3.Visible = False
DeimosButton4.Visible = False
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
DeimosButton2.Top = DeimosButton2.Top - 1
If DeimosButton2.Location = New Point(22, 54) Then
Timer4.Stop()
DeimosButton2.Enabled = True
End If
End Sub
Private Sub State(ByVal Ref As Integer)
If Ref = 0 Then
Timer4.Start()
DeimosButton2.Enabled = False
i = 1
Else
Timer5.Start()
DeimosButton2.Enabled = False
i = 0
End If
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
DeimosButton2.Top = DeimosButton2.Top + 1
If DeimosButton2.Location = New Point(22, 85) Then
Timer5.Stop()
DeimosButton2.Enabled = True
DeimosButton3.Visible = True
DeimosButton4.Visible = True
End If
End Sub
This Second Button Code
Private Sub DeimosButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeimosButton3.Click
states(o)
DeimosButton2.Visible = False
DeimosButton4.Visible = False
End Sub
Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
DeimosButton3.Top = DeimosButton3.Top - 1
If DeimosButton3.Location = New Point(22, 54) Then
Timer6.Stop()
DeimosButton3.Enabled = True
End If
End Sub
Private Sub states(ByVal Def As Integer)
If Def = 0 Then
Timer6.Start()
DeimosButton3.Enabled = False
o = 1
Else
Timer7.Start()
DeimosButton3.Enabled = False
o = 0
End If
End Sub
Private Sub Timer7_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer7.Tick
DeimosButton3.Top = DeimosButton3.Top + 1
If DeimosButton3.Location = New Point(22, 116) Then
Timer7.Stop()
DeimosButton3.Enabled = True
DeimosButton2.Visible = True
DeimosButton4.Visible = True
End If
End Sub
The problem is when i click the second button
but when i click the first button, is no matter.
Problem : The button is still moving to top, although it is has reach the position.
there is a solution for this ?
You must change
DeimosButton3.Location = New Point(22, 116)
to
DeimosButton3.Location.y = 116
This is valid to all
for all your code

VB.Net Answer Checker in Quiz

Please help me solve my problem in quiz checker. I have 4 choices which display in Radio Button. So my problem is after i check my radio button and submit it gives me score on the corresponding question but after i click the submit button again it adds another score on the same question. how can i prevent my checker to add another score on the same question?
Here is my code.
Public Sub Check()
If Check1.Text < 2 And Check2.Text < 2 And Check3.Text < 2 And Check4.Text < 2 Then
If CorrectAns.Text = CoAnsDB.Text Then
score = score + 1
Else
score = score + 0
End If
Else
score = score + 0
End If
End Sub
Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
Call Check()
'Call CheckerB()
'Call CheckerC()
'Call CheckerD()
MyScore.Text = score.ToString
BtnSubmit.Enabled = False
AnsA.Enabled = False
AnsB.Enabled = False
AnsC.Enabled = False
AnsD.Enabled = False
End Sub
Private Sub AnsA_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnsA.CheckedChanged
CorrectAns.Text = "A"
If AnsA.Checked = True Then
Check1.Text = Check1.Text + 1
End If
BtnSubmit.Enabled = True
End Sub
Private Sub AnsD_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnsD.CheckedChanged
CorrectAns.Text = "D"
If AnsB.Checked = True Then
Check4.Text = Check4.Text + 1
End If
BtnSubmit.Enabled = True
End Sub
Private Sub AnsC_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnsC.CheckedChanged
CorrectAns.Text = "C"
If AnsC.Checked = True Then
Check3.Text = Check3.Text + 1
End If
BtnSubmit.Enabled = True
End Sub
Private Sub AnsB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnsB.CheckedChanged
CorrectAns.Text = "B"
If AnsB.Checked = True Then
Check2.Text = Check2.Text + 1
End If
BtnSubmit.Enabled = True
End Sub
Thank you.

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.

Windows Form won't pass a variable to another?

my problem is that is have 4 forms, 3 of these forms allow me to pass variables between them.. however one form the Booking form won't allow me to pass the txtTotal variable to the Confirmation Form.
All the other forms all me to do this, im not doing anything different i can see... im thinking that perhaps another part of the form is prohibiting me from passing that txtTotal to the Confirmatin form.
The following is for the Confirmation form, it should display the txtTotal in lblprice from the Booking form but shows nothing
Public Class Confirmation
Private Sub btnBack_Click(sender As System.Object, e As System.EventArgs) Handles btnBack.Click
Dim FrmPayment As New Payment
FrmPayment.Show()
Me.Hide()
End Sub
Private Sub btnHome_Click(sender As System.Object, e As System.EventArgs) Handles btnHome.Click
Dim FrmSelection As New Selection
FrmSelection.Show()
Me.Hide()
End Sub
Private Sub Label1_Click(sender As System.Object, e As System.EventArgs) Handles lblshow.Click, lbltime.Click, lbldate.Click, lblcust.Click, lblprice.Click
End Sub
Private Sub Confirmation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'lblprice displays nothing and the rest of the labels display the correct values
lblprice.Text = Booking.txtTotal.Text
lblshow.Text = Selection.cboShowSelect.Text
lbldate.Text = Selection.cboDateSelect.Text
lbltime.Text = Selection.cboTimeSelect.Text
End Sub
End Class
Here is all the code in the Booking form if it helps
Public Class Booking
Private Sub Booking_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'labels 1,4,6 display information from the comboboxes on the Selection Form
Label1.Text = Selection.cboShowSelect.Text
Label4.Text = Selection.cboDateSelect.Text
Label6.Text = Selection.cboTimeSelect.Text
Dim i As Integer
For i = 1 To 4
cboAdult.Items.Add(i)
cboChild.Items.Add(i)
cboSenior.Items.Add(i)
cboStudent.Items.Add(i)
Next i
End Sub
Public Sub ComboBoxes_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboAdult.SelectedIndexChanged, cboChild.SelectedIndexChanged, cboSenior.SelectedIndexChanged, cboStudent.SelectedIndexChanged
'Assigned an evet handler to all of the comboboxes then calculates the price and puts in total box
Dim Totalcombo1, Totalcombo2, Totalcombo3, Totalcombo4, Price As Decimal
Dim valuecombo1 = (cboAdult.SelectedIndex + 1) 'finds position of option selected & adds one to get number of tickets
Dim valuecombo2 = (cboChild.SelectedIndex + 1)
Dim valuecombo3 = (cboSenior.SelectedIndex + 1)
Dim valuecombo4 = (cboStudent.SelectedIndex + 1)
'if the submit button is selected without there being a value selected from any combobox then error should appear, saying at least 1 ticket should be purchased.
If (cboChild.SelectedIndex = -1) Then
Totalcombo2 = 0
Else
Price = 6.5
Totalcombo2 = valuecombo2 * Price
End If
'determines the ticketprice of combobox 1
If (cboAdult.SelectedIndex = -1) Then
Totalcombo1 = 0
Else
Price = 9
Totalcombo1 = valuecombo1 * Price
End If
'determines the ticketprice of combobox 2
If (cboSenior.SelectedIndex = -1) Then
Totalcombo3 = 0
Else
Price = 6.5
Totalcombo3 = valuecombo3 * Price
End If
'determines the ticketprice of combobox 3
If (cboStudent.SelectedIndex = -1) Then
Totalcombo4 = 0
Else
Price = 6.5
Totalcombo4 = valuecombo4 * Price
End If
'determines the ticketprice of combobox 4
If (cboAdult.SelectedIndex = -1 And cboChild.SelectedIndex = -1 And cboSenior.SelectedIndex = -1 And cboStudent.SelectedIndex = -1) Then
MessageBox.Show("Please make at least one ticket selection before continuing. ")
End If
txtTotal.Text = Totalcombo1 + Totalcombo2 + Totalcombo3 + Totalcombo4
'adds the totals of the ticketprices and then inserts into the Total label
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboChild.SelectedIndexChanged
End Sub
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
Dim FrmSelection As New Selection
FrmSelection.Show()
Me.Hide()
End Sub
Sub Form_OpenBooking(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If (cboChild.SelectedIndex >= 0 And (cboSenior.SelectedIndex = -1 And cboAdult.SelectedIndex = -1)) Then
MessageBox.Show("A child must be accompanied by at least one adult", "Invalid Selection")
ElseIf (txtTotal.Text > 0) Then 'if the total label is greater than zero then this means at least one ticket selection has been made
Dim Form3 As New Payment ' if above is true open Booking Form
Form3.Show()
Me.Hide()
End If
End Sub
Private Sub Resetbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
cboAdult.SelectedIndex = -1
cboChild.SelectedIndex = -1
cboSenior.SelectedIndex = -1
cboStudent.SelectedIndex = -1
txtTotal.Text = 0
End Sub
End Class
Thanks in advance!
Try this
Public frm as new frmBooking
frm.txtTotal.Text=
It should work
You need to use the actual instance of the Form that you created, not the Class name. You should also make sure that you turn on Option Strict.
Try frmBooking.txtTotal.Text instead of Booking.txtTotal.Text