Public Class Form1
Public Class Form1
Dim nChar As Integer
Dim nWord As Integer
Dim nSpace As Integer
Dim nSentence As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim c As String = txtPhrase.Text
nChar = textLength(c)
nWord = CountWords(c)
nSentence = sentenceCount(c)
nSpace = wordSpace(c)
updateChar()
End Sub
Private Sub updateChar()
TextBox1.Text = nChar
TextBox2.Text = nWord
TextBox3.Text = nSentence
TextBox4.Text = nSpace
End Sub
Private Function textLength(ByVal str As String) As String
Return str.Length
End Function
Public Function CountWords(ByVal value As String) As Integer
Return value.Split(" ").Count()
End Function
Public Function wordSpace(ByVal space As String) As String
Dim y As Integer
y = space.Split(" ").Count
y -= 1
Return y
End Function
Public Function sentenceCount(ByVal sentence As String) As String
Dim x As Integer
x = sentence.Split(".").Count()
x -= 1
Return x
End Function
End Class
Showing posts with label Code Writing. Show all posts
Showing posts with label Code Writing. Show all posts
Monday, May 9, 2011
Methods
Here is how Methods are done using different Functions .
Tuesday, March 8, 2011
In this post I will show how to set different variables types.
This is code show how to set integer, decimal,and string data types:
1: Dim Apples As Integer 2: Dim bible As Decimal 3: Dim corral As String
Monday, February 14, 2011
Selecting items in a listbox
This code will show how to select items in a listbox
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim shirt, pants, shoes As String shirt = "shirt" pants = "pants" shoes = "shoes" Me.Close() End Sub ClassMe.lstTotalItems.Items.Add(shirt)Me.lstTotalItems.Items.Add(pants)Me.lstTotalItems.Items.Add(shoes)Me.lstTotalItems.ScrollAlwaysVisible = TrueEnd Sub lstTotalItems.SelectedItem = Private Sub btnItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem1.Click"shirt"End Sub lstTotalItems.SelectedItem = Private Sub btnItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem2.Click"pants"End Sub lstTotalItems.SelectedItem = Private Sub btnItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItem3.Click"shoes"End Sub EndPrivate Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Monday, February 7, 2011
How to add a button, and a textbox to a page programmatically.
I will demonstrate how to add a textbox to a program programatically.
Dim textbox1 As New TextBoxtextbox1.Size =
TextBox8.ReadOnly = True 'makes the text box Read-onlytextbox1.Name = "TextBox1" 'Creates a name for the textboxTextBox1.Location =
TextBox8.Width = AutoSize
TextBox8.Height = AutoSize
'These lines of code Place a button of code Dim button As New Button 'adds a button to the formbutton.AutoSize = Truebutton.Text = "Exit" 'Places a name on the button
button.Location =
'This code adds a list box to the form
Dim lstShoes As New ListBoxMe.Controls.Add(button) 'Adds button to controlsNew Point(5, 239) ' Places the button in a specific area on the form.
Me.Controls.Add(textbox1) 'Adds textbox1 to the controlNew Point(60, 185)'this operation sets the location of the new textboxesNew Size(150, 20)' sets size
Dim textbox1 As New TextBoxtextbox1.Size =
TextBox8.ReadOnly = True 'makes the text box Read-onlytextbox1.Name = "TextBox1" 'Creates a name for the textboxTextBox1.Location =
TextBox8.Width = AutoSize
TextBox8.Height = AutoSize
'These lines of code Place a button of code Dim button As New Button 'adds a button to the formbutton.AutoSize = Truebutton.Text = "Exit" 'Places a name on the button
button.Location =
'This code adds a list box to the form
Dim lstShoes As New ListBoxMe.Controls.Add(button) 'Adds button to controlsNew Point(5, 239) ' Places the button in a specific area on the form.
Me.Controls.Add(textbox1) 'Adds textbox1 to the controlNew Point(60, 185)'this operation sets the location of the new textboxesNew Size(150, 20)' sets size
Monday, January 31, 2011
Case statements
Here is an example of how to effectively write a Case statement. This Code is very useful in a prgram multiple outcomes to a problem.
Dim fries As String
Dim DietState As String
fries = TextBox1.Text
Select Case creamcake
Case "Eaten"
DietState = "Diet Ruined"
Case "Not Eaten"
DietState = "Diet Not Ruined"
Case Else
DietState = "Didn't check"
End Select
MsgBox DietState
If statement that makes one decision
In this code i will show an if statement that makes only one decision. This would be helpful when making a program or application that would have to make one or more decisions.
Dim scriptEngine as String
If scriptEngine = "VB" Then
runningVB = True
End If
messageBox.Show(runningVB)
In this code many decisions are made.
Dim intW As Integer = 10
If intW > 11 Then
MessageBox.Show("intX > 11")
ElseIf intW < 5 Then MessageBox.Show("intW < 5")
Else
MessageBox.Show("Fallback code block")
End If
How to convert a number variable into a string
This code describes how to convert a number variable to a string:
- Convert number to string
- CStr
- IntVar.ToString
Dim eggs As Decimal = 62
Dim Charles As Integer = eggs.ToString
MessageBox.Show(Charles)
Wednesday, January 26, 2011
Converting Integers to decimal
In this code I will show how to convert an integer to a decimal.
Converts an decimal to a Integer
Dim milk AS Decimal
Dim Charles as Integer
Eggs = 24
charles =CInt(eggs) or Decimal.ToInt32(eggs)
MessageBox.Show(charles.GetType.ToString)
Join a string to another string, also known as string concatenation.
This code joins two strings and is known as concatenation
Dim FirstName As String
Dim LastName As String
Dim FullName As String
FirstName = “Vincent”
LastName= “Webb”
FullName = FirtName & LastName
MessageBox.Show(FullName)
Dim FirstName As String
Dim LastName As String
Dim FullName As String
FirstName = “Vincent”
LastName= “Webb”
FullName = FirtName & LastName
MessageBox.Show(FullName)
Subscribe to:
Posts (Atom)