VB.net RGB color sensor "Integer is not valid" - vb.net

I'm trying to make VB.net show the data "colors" from my Arduino,
My serial port working great but I have this massage every-time I press connect & weird data show's up
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string " = " to type 'Integer' is not valid.
Can someone help me in this?
this is my code
Public Class Form1
Private _msg As String
Dim R As String
Dim G As String
Dim B As String
Dim iR As String
Dim iG As String
Dim iB As String
Private indata As String
Dim IsConnected As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each str As String In IO.Ports.SerialPort.GetPortNames()
Ports.Items.Add(str)
Next
If (Ports.Items.Count > 0) Then
Ports.SelectedIndex = 0
End If
IsConnected = False
Status.Text = "Disconnected"
Status.BackColor = Color.MistyRose
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (SerialPort1.IsOpen()) Then
Try
SerialPort1.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
IsConnected = False
Status.Text = "Disconnected"
Status.BackColor = Color.MistyRose
Button1.Enabled = True
Button2.Enabled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (SerialPort1.IsOpen = False) Then
SerialPort1.PortName = Ports.SelectedItem
SerialPort1.Open()
IsConnected = True
Status.Text = "Connected"
Status.BackColor = Color.LightGreen
Button1.Enabled = False
Button2.Enabled = True
End If
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
'user chose string
'read data waiting in the buffer
Try
Dim msg As String = SerialPort1.ReadExisting()
indata = indata + msg
'Dim where As Integer = InStr(indata, ControlChars.Lf)
Dim where As Integer = InStr(indata, "R=")
If (indata.Length > where + 18) Then
R = indata.Substring(where + 1, 3)
G = indata.Substring(where + 7, 3)
B = indata.Substring(where + 13, 3)
indata = ""
End If
'display the data to the user
_msg = msg
_msg = _msg.Replace(ControlChars.Cr, "")
: DisplayData(msg)
Catch ex As Exception
End Try
End Sub
#Region "DisplayData"
''' <summary>
''' Method to display the data to and
''' from the port on the screen
''' </summary>
''' <remarks></remarks>
<STAThread()> _
Private Sub DisplayData(ByVal msg As String)
DisplayWindow.BeginInvoke(New EventHandler(AddressOf DoDisplay))
End Sub
#End Region
#Region "DoDisplay"
Private Sub DoDisplay(ByVal sender As Object, ByVal e As EventArgs)
'DisplayWindow.SelectedText = String.Empty
'DisplayWindow.SelectionFont = New Font(_DisplayWindow.SelectionFont, FontStyle.Bold)
'DisplayWindow.SelectionColor = MessageColor(CType(_type, Integer))
DisplayWindow.AppendText(_msg)
DisplayWindow.ScrollToCaret()
End Sub
#End Region
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
RL.Text = R
GL.Text = G
BL.Text = B
iR = CInt(R) * CInt(RM.Text)
iG = CInt(G) * CInt(GM.Text)
iB = CInt(B) * CInt(BM.Text)
RF.Text = iR
GF.Text = iG
BF.Text = iB
Try
Label6.BackColor = Color.FromArgb(CType(iR, Byte), CType(iG, Byte), CType(iB, Byte))
Catch ex As Exception
End Try
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
System.Diagnostics.Process.Start("http://www.narzan.weebly.com/p-1049.html")
End Sub
Private Sub LinkLabel1_LinkClicked_1(sender As Object, e As LinkLabelLinkClickedEventArgs)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
picOn.Visible = True
SerialPort1.Open()
SerialPort1.Write("^")
SerialPort1.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
picOn.Visible = False
SerialPort1.Open()
SerialPort1.Write("<")
SerialPort1.Close()
End Sub
Private Sub picOn_Click(sender As Object, e As EventArgs) Handles picOn.Click
End Sub
Private Sub RL_Click(sender As Object, e As EventArgs) Handles RL.Click
End Sub
Private Sub RM_TextChanged(sender As Object, e As EventArgs) Handles RM.TextChanged
End Sub
End Class

My problem was from my Arduino code not from VB.net
the solution is to remove "=" from R,G,B
void printColour(){
Serial.print("R = ");
Serial.println(int(colourArray[0]));
Serial.print("G = ");
Serial.println(int(colourArray[1]));
Serial.print("B = ");
Serial.println(int(colourArray[2]));
//delay(2000);
}
so the code will look like that
void printColour(){
Serial.print("");
Serial.println(int(colourArray[0]));
Serial.print("");
Serial.println(int(colourArray[1]));
Serial.print("");
Serial.println(int(colourArray[2]));
//delay(2000);
}
Thanks everyone, everything work great now

Related

Only does two files instead of 100

Basically I have this file creator program which is helping me to make a bunch of files and for some reason, it only does 2 instead of 100 files specified.
Code:
Imports System.IO
Public Class Main
Dim CURRENT_NUM As Integer
Dim CONTENT_STRING As String
Dim PATH_STRING As String
Dim FROM_NUM As Integer
Dim TO_NUM As Integer
Public Sub SetupVar()
Try
CONTENT_STRING = tbContent.Text
PATH_STRING = tbPath.Text
FROM_NUM = Integer.Parse(tbFrom.Text)
TO_NUM = Integer.Parse(tbTo.Text)
Catch ex As Exception
End Try
End Sub
Private Sub Make()
tmrMake.Enabled = True
End Sub
Private Sub btnMake_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMake.Click
SetupVar()
Make()
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub tmrMake_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMake.Tick
'disable quit
'and control box
Me.ControlBox = False
btnQuit.Enabled = False
CURRENT_NUM = FROM_NUM
CURRENT_NUM = CURRENT_NUM + 1
Using sw As New StreamWriter(PATH_STRING & CURRENT_NUM & ".txt")
sw.Write(CONTENT_STRING)
End Using
If CURRENT_NUM = TO_NUM Then
btnQuit.Enabled = True
Me.ControlBox = True
tmrMake.Enabled = False
End If
End Sub
End Class
The result is c1 and c2 in the folder. Instead of 1-100 As i specified in the two tb.
You need to move some of your code around and then you should be good. See the code below...
Imports System.IO
Public Class Main
Dim CURRENT_NUM As Integer
Dim CONTENT_STRING As String
Dim PATH_STRING As String
Dim FROM_NUM As Integer
Dim TO_NUM As Integer
Public Sub SetupVar()
Try
CONTENT_STRING = tbContent.Text
PATH_STRING = tbPath.Text
FROM_NUM = Integer.Parse(tbFrom.Text)
TO_NUM = Integer.Parse(tbTo.Text)
' Moved code from tmrMake_Tick to here
'disable quit
'and control box
Me.ControlBox = False
btnQuit.Enabled = False
CURRENT_NUM = FROM_NUM
Catch ex As Exception
End Try
End Sub
Private Sub Make()
tmrMake.Enabled = True
End Sub
Private Sub btnMake_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMake.Click
SetupVar()
Make()
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub tmrMake_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMake.Tick
Using sw As New StreamWriter(PATH_STRING & CURRENT_NUM & ".txt")
sw.Write(CONTENT_STRING)
End Using
' Increment your CURRENT_NUM after you've written the file
CURRENT_NUM = CURRENT_NUM + 1
If CURRENT_NUM = TO_NUM Then
btnQuit.Enabled = True
Me.ControlBox = True
tmrMake.Enabled = False
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.

vb For loop repeat a certain number of times

So I am making a port scanner and have a min and max port, but can't get the port scanner to stop scanning when it reaches the maximum port?
I have tried doing an Exit For when port reaches portmax.
Here is the code:
Public Class Form1
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim counter As Integer
Button2.Enabled = False
'set counter explained before to 0
counter = 0
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Dim host As String
Dim counter As Integer
Dim portmin As Integer = TextBox3.Text
Dim portmax As Integer = TextBox2.Text
'Set the host and port and counter
counter = counter + 1 'counter is for the timer
host = TextBox1.Text
For port As Integer = portmin To portmax
' Next part creates a socket to try and connect
' on with the given user information.
Dim hostadd As System.Net.IPAddress = _
System.Net.Dns.GetHostEntry(host).AddressList(0)
Dim EPhost As New System.Net.IPEndPoint(hostadd, port)
Dim s As New System.Net.Sockets.Socket( _
System.Net.Sockets.AddressFamily.InterNetwork, _
System.Net.Sockets.SocketType.Stream, _
System.Net.Sockets.ProtocolType.Tcp)
Try
s.Connect(EPhost)
Catch
End Try
If Not s.Connected Then
ListBox1.Items.Add("Port " + port.ToString + " is not open")
Else
ListBox1.Items.Add("Port " + port.ToString + " is open")
ListBox2.Items.Add(port.ToString)
End If
Label3.Text = "Open Ports: " + ListBox2.Items.Count.ToString
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
'stop button
Timer1.Stop()
Timer1.Enabled = False
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add("Scanning: " + TextBox1.Text)
ListBox1.Items.Add("-------------------")
Button2.Enabled = True
Button1.Enabled = False
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub ListBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox2.SelectedIndexChanged
End Sub
End Class
I would really appreciate any help
thanks,
Try to stop the Timer while in the scanning.
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
'Your code
Timer1.Enabled = True
End Sub
If thats the problem, and looks like it, you should consider using a Try/Catch block:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Timer1.Enabled = False
'Your code
Catch ex As Exception
'Manage the error
Finally
Timer1.Enabled = True
End Try
End Sub
Try this
For port As Integer = portmin To portmax - 1

Get InvalidOperatorException was unhandled upon compiling

Everything was compiling just fine until validation for text fields was implemented.
Why won't it compile?
An error occurred creating the form.
See Exception.InnerException for
details. The error is: External
component has thrown an exception.
The source:
Public Class frmAddStudent
Dim aryData(6) As String
Public Shared newStudentRecord As String
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.DialogResult = DialogResult.Cancel
End Sub
Private Sub btnAddStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStudent.Click
'place all the student field data into the array of elements
aryData(0) = txtFirstName.Text
aryData(1) = txtLastName.Text
aryData(2) = txtMajor.Text
aryData(3) = txtPhone.Text
aryData(4) = txtEmail.Text
aryData(5) = txtGPA.Text
'join the array elements and place the result into a string variable
newStudentRecord = Join(aryData, " ")
'create a link between the form and the file with streamwriter and write to the text file
If System.IO.File.Exists(frmMain.FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(frmMain.FILE_NAME, True)
objWriter.WriteLine(newStudentRecord)
objWriter.Close()
End If
Me.DialogResult = DialogResult.OK
End Sub
Private Sub txtFirstName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFirstName.Validating
If txtFirstName.Text.Contains(" ") Or txtFirstName.Text.Length = 0 Or Not System.Text.RegularExpressions.Regex.IsMatch(txtFirstName.Text, "[a-z|A-Z]+$") Then
ErrorProvider1.SetError(txtFirstName, "First Name can't contain spaces or be of zero length and must consist of only letters")
e.Cancel = True
Else
ErrorProvider1.SetError(txtFirstName, "")
End If
End Sub
Private Sub frmAddStudent_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ErrorProvider1.BlinkStyle = ErrorBlinkStyle.NeverBlink
End Sub
Private Sub txtLastName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtLastName.Validating
If txtLastName.Text.Contains(" ") Or txtLastName.Text.Length = 0 Or Not System.Text.RegularExpressions.Regex.IsMatch(txtLastName.Text, "[a-z|A-Z]+$") Then
ErrorProvider1.SetError(txtLastName, "Last Name can't contain spaces or be of zero length and must consist of only letters")
e.Cancel = True
Else
ErrorProvider1.SetError(txtLastName, "")
End If
End Sub
Private Sub txtMajor_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMajor.Validating
If txtMajor.Text.Length > 0 Then
If Not System.Text.RegularExpressions.Regex.IsMatch(Strings.Left(txtMajor.Text, 1), "[a-z|A-Z]+$") Then
ErrorProvider1.SetError(txtMajor, "Major course code is incorrect")
Else
ErrorProvider1.SetError(txtMajor, "")
End If
Else
ErrorProvider1.SetError(txtMajor, "Major cant' be zero length")
End If
End Sub
End Class
EDIT: Here's also a link to a PrtSc of the problem: http://img88.imageshack.us/i/imageqc.gif/