"Version" is a type and cannot be resolved - vb.net

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.

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

Passing object as parametar in VB.NET

I am a beginner and please show me how to pass the parameter object Person to Button.Click event. I'm using vb.net. Here is my code:
Public Class Form1
Public Class MyPersonClass
Public Name As String
Public Age As Integer
Public Title As String
End Class
Public Sub DisplayPerson(ByVal person As MyPersonClass)
Label1.Text = person.Name
Label2.Text = person.Age.ToString()
Label3.Text = person.Title
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
You don’t – Button1_Click is an event handler, you’re not supposed to call it manually. It gets called, with predefined parameters, when a certain event occurs. You cannot really adapt these parameters, simply because it doesn’t make sense: the event would no longer know how to call the handler.
You can easily write your own method and pass any object to it, of course. And you’ve done exactly that with DisplayPerson.
Private ExamplePerson As MyPerson
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ExamplePerson = New MyPersonClass 'thanks Chris Dunaway for the correction
ExamplePerson.Name = "Test Name"
ExamplePerson.Age = 36
ExamplePerson.Title = "Title Name"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DisplayPerson(ExamplePerson)
End Sub

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

Object reference not set to an instance, public array with..Split(",")

i wonder what is wrong with the following vb.net code.
Public Class Form10
Public IDs() As String = TextBox1.Text.Split(",")
Private Sub Form10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each id In IDs
MsgBox(id)
Next
End Sub
End Class
when i do
Form10.show()
i get an error "Object reference not set to an instance"
You have declared a field in your class to be initialized with a value from a control on the corresponding form that does not yet exist. The control is not initialized and loaded by the time your initializer on your field member is accessed, thus causing the error.
To keep the public IDs declaration, you could remove the initialization from the field declaration, then move the assignment to the Button1_Click event, as follows:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
IDs=TextBox1.Text.Split(",")
' Do something interesting with IDs now...
End Sub
Public Class Form10
Private Sub Form10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim IDs() As String = TextBox1.Text.Split(",")
Form1.somefunction(IDs)
End Sub
and in Form1
Public Sub somefunction(ByVal IDs() As String)
For Each id In IDs
MsgBox(id)
Next
End Sub

Error in programming

Imports SpeechLib
Public Class Form1
Public vox = CreateObject("sapi.spvoice")
Private Sub cmdSpeak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSpeak.Click
Dim t As String = "Hello , This is a Text"
Say(t)
End Sub
Public Sub Say(ByVal text As String)
vox.Speak(text,SpeechVoiceSpeakFlags.SVSFlagsAsync)
End Sub
Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click
vox.pause()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
vox.AlertBoundary = SVEPhoneme
End Sub
End Class
I am getting an error
Name 'SVEPhoneme' is not declared.
How and where do I declare it ?
It is SpeechVoiceEvents.SVEPhoneme
This is all a lot easier if you make this code early bound:
Public vox as New SpVoice
Or better yet, use the .NET wrapper for the sapi, System.Speech assembly.
Imports System.Speech.Synthesis
Public Class Form1
Public vox As New SpeechSynthesizer
Public Sub Say(ByVal text As String)
vox.SpeakAsync(text)
End Sub
End Class
SVEPhoneme represents the Phoneme event, which occurs when the engine completes a phoneme while speaking.
Try setting SVEPhoneme to be the integer 64.
http://msdn.microsoft.com/en-us/library/ms720886(v=vs.85).asp