Invalid token in class struct interface - vb.net

I have a situation on visual studio 2015 .. i have the next code :
Private Sub TBwe.Text
Changed;(ByVal sender As System.Object, ByVal e As System.System.EventArgs) Handles TBWe.TextChanged
if Strings.Len(TBWe.Text) = 6 then
TBEt.Focus();
End Sub
i have invalid token in class , struct , or interface
Can any body help me ?

This should work:
Private Sub TBwe_TextChanged(sender As Object, e As EventArgs) Handles TBWe.TextChanged
If Strings.Len(TBWe.Text) = 6 Then
TBEt.Focus()
End If
End Sub

Related

update label.txt (live) when Vscroll bar is changing (vb2010)

EDITED:
I want to make my question more simple
check the code
Public Class Form1
Dim v1 As Double
Dim v2 As Double
Dim v3 As Double
Private Sub Form1_Load(By Val sender As System.Object, By Val e As System.Eventuates) Handles My Base.Load
label1.text=v1
label2.text=v2
label3.text=v3
end sub
Private Sub Button1_Click(By Val sender As System.Object, ByVal e As System.Eventuates) Handles Button1.Click
v1=v1+10
v2=v2+20
v3=v3+30
End Sub
end class
I want when push the button the label change directly in the form
how can I do that without load form in button sub ?
I don't quite understand your problem but calling Form1_Load is weird and settling label2 to an uninitialized value is also weird. I would suggest you put all of the display logic in a method instead.
Private Sub DisplayScrollValue(ByVal scrollValue As Double)
Label1.Text = scrollValue
label2.text = scrollValue
End Sub
Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
DisplayScrollValue((VScrollBar1.Value * -1 / 10).ToString())
End Sub
Private Sub Form11_Load(By Val sender As System.Object, By Val e As System.Eventuates) Handles My Base.Load
DisplayScrollValue(0)
end sub
I notice your edit and the solution is very similar to what I wrote. Just have a method that sets the labels and call it when you want to update them.
Public Class Form1
Dim v1 As Double
Dim v2 As Double
Dim v3 As Double
Private Sub UpdateLabels()
label1.text=v1
label2.text=v2
label3.text=v3
End Sub
Private Sub Form1_Load(By Val sender As System.Object, By Val e As System.Eventuates) Handles My Base.Load
UpdateLabels()
end sub
Private Sub Button1_Click(By Val sender As System.Object, ByVal e As System.Eventuates) Handles Button1.Click
UpdateLabels()
End Sub
end class

Where to add the code for the regular expression to ensure that only numbers are accepted [duplicate]

This question already has answers here:
How do I make a textbox that only accepts numbers?
(41 answers)
Closed 8 years ago.
I am trying to add regular expression to the code below to ensure that only numbers are accepted. The code is very basic it calculates the area of a square and put the result in a RichTextBox.Text
I am using VB Visual Studio 2012. Any help will be greatly appreciated.
------------------------------------------------------
Public Class SquareArea
Inherits ShapeArea
Public Overrides Function Area() As Double
Return (Me.Lengh ^ 2)
End Function
End Class
------------------------------------------------------------
Public Class Square
Private Sub Square_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub ResultButton_Click(sender As Object, e As EventArgs) Handles ResultButton.Click
Dim area = New SquareArea
area.Lengh = SideTextBox.Text
ResultRichTextBox.Text = area.Area()
End Sub
Private Sub CloseSquareButton_Click(sender As Object, e As EventArgs) Handles CloseSquareButton.Click
Me.Close()
End Sub
End Class
There are several ways of doing this. But the best would be to use the Validating Event of the SideTextBox textbox.
Private Sub SideTextBox_Validating (ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtSideTextBox.Validating
'your code here
End Sub
or
You could also use its KeyPress Event so the user is prompted whenever they enter a non-numeric character.
Private Sub SideTextBox_KeyPress (ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSideTextBox.KeyPress
'your code here
End Sub
Use this code...
Private Sub txtValue_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtValue.KeyPress
If Char.IsDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
End If
End Sub
I don't usually write in Visual Basic but you are looking to add RegularExpression to your class as a Class Member (System.Text.RegularExpressions namespace). Regular Expression Pattern shown below will allow only digits. Calling the Match method on regex returns a Match class which you can call Success on for a Boolean result (true/false)
You may have to make slight changes as I don't normally write in VB, but the expression and class are correct
'Declare Regular Expression Class, Compile once
Dim RegularExpression regex As RegularExpression = New RegularExpression("^[0-9]*$", RegExOptions.Compile)
Private Sub Square_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub ResultButton_Click(sender As Object, e As EventArgs) Handles ResultButton.Click
Dim area = New SquareArea
' Insert Magic Here
If regex.Match(SideTextBox.Text).Success=False Then
MessageBox.Show("Invalid entry")
Return
End If
area.Lengh = SideTextBox.Text
ResultRichTe...
Private Sub CloseSquareButton_Click(sender As Object, e As EventArgs) Handles CloseSquareButton.Click
Me.Close()
End Sub
End Class

WP7 - How to refer to the MainPage.xaml.vb from App.xaml.vb? (Passing data?)

so basically I have my MainPage.xaml.vb and App.xaml.vb and in the app.xmal.vb i added :
Private Sub Add_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Private Sub Save_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Private Sub EditAppBar_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Private Sub DeleteAppBar_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
This is because I added more than 1 ApplicationBars from looking at the MSDN Sample. The problem is that how do i refer to mainpage to make the code work? e.g. the "Add" will contain "pvt.SelectedIndex = 2" and when it's clicked it's meant to navigate the the 3'rd page but i can't seem to do it in here. If i take this code and add it to the "MainPage" it will work fine. The error i get is "'pvt' is not declared. It may be inaccessible due to its protection level." How do i fix this?
Any ideas?"
I got it solved by using: Dim mp = TryCast(DirectCast(Application.Current, App).RootFrame.Content, MainPage) mp.pvt.SelectedIndex = 2

"Version" is a type and cannot be resolved

Here is my code :
Public Class Form1
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.SelectedItem = "1.6.4 Vanilla Server" Then
Version = "164"
End If
If ComboBox1.SelectedItem = "1.6.2 Vanilla Server" Then
Version = "162"
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Version As Int16
End Sub
End Class
Then I get a blue line under Version saying : Version is a type and cannot be used as an expression
Thanks for any help :/
Aaak. here you go:
Public Class Form1
Private VersionNo As String
...
Private Sub Button1_Click...
VersionNo = "164"
....
End Sub
If you declare it in Form_Load it goes out of scope when the sub completes. you want a module level variable. When that happened, VB thought you were talking about the Version Type. If you want to use Version you may have to bracket it: [Version] to tel VB to use your var, not the NET Type.
Try changing the name of Version to VersionNo
Edit: declare the variable in the Form1 not the Form1_load
Use ME.VersionNo = "162", you have declared it as int16 and assigning string to it.

Call DataGridView User Deleting Row using ContextMenuStip

I'm facing a problem to call the event [dgv_clients_UserDeletingRow] using a [ContextMenuStrip].
It's giving me that error:
Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.DataGridViewRowCanelEventArgs'
And here is my code :
Private Sub dgv_clients_UserDeletingRow(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles dgv_clients.UserDeletingRow
deleteLine(e)
End Sub
Private Sub toolStripItem1_Click(ByVal sender As Object, ByVal args As EventArgs) Handles toolStripItem1.Click
If mouseLocation.RowIndex > 0 Then
dgv_clients.Rows(mouseLocation.RowIndex).Selected = True
dgv_clients.Rows(mouseLocation.RowIndex).DefaultCellStyle.SelectionBackColor = Color.Gray
DeleteToolStripMenuItem_Click(sender, args)
End If
End Sub
Public Sub DeleteToolStripMenuItem_Click(ByVal Sender As Object, ByVal e As EventArgs)
Call deleteLine(e)
End Sub
Thank your all
The Problem is your deleteLine method.
You are calling it with two different types. In the Sub dgv_clients_UserDeletingRow you pass e as DataGridViewRowCancelEventArgs and in the Sub DeleteToolStripMenuItem_Click you pass e as EventArgs. If you haven't overloaded your deleteLine method for these two types, the compiler will try to auto-parse the wrong type and it fails.