Visual Basic dot NET
^^^^This is a nubbie FREE zone^^^^^
Practice Page -- share your suggestions or questions
coding conventions that are helpful when working with arrays & text files:
bubbleSort.txt SeqAccessFile.ppt
Pitt4 Assignment.doc submit 5/25 with documentation at end of period
Tips & Tricks of the Code Warriors
Ch7 Explained....
You are responsible for 2 items of content listed below they are to be posted by 1st name here (need to include key terms, syntax & example)
Structure:
For...Next,
Function:
Financial.pmt,
control & properties & events:
txt.SelectAll(), text changed event, combo box (cbo is prefix)
String Manipulations:
length, trim, remove, replace, pad, insert, startsWith/endsWith, contains, indexOf, substring, compare, like
scores -- wiki post ch 7 (3/30 as of start of class)
?--ricki: insert, contains
4--christian: for...Next, startsWith
4--Joe: length, trim
?--Sam: cbo, financial
4--laurel: txt change, selectAll
?--Jordan: remove & replace
?--corey: compare, like
?--jarrod: contains, insert
crobb
indexOf -- searches a str for a specific sequence of chars and returns the int that indicates the start position of said str sequence. If the str sequence desired is not found then it returns a value of -1.
intLoc = strGiven.IndexOf("desired sequence")
strName = txtName.text.toUpper
' strName is "Jordan"
intLoc=strName.IndexOf("A")
'so intLoc is 4
SamU
Financial.Pmt – used to calculate a periodic payment on a loan
-PMT = PayMenT
-returned as a dbl
Syntax: Financial.Pmt(Rate, Nper, PV)
Rate – interest rate per period
Nper – total number of payment periods (the term)
PV – present value of the load; in other words, the load amount
Example: Financial.Pmt(.12, 8, 3000000)
Calculates the yearly payment for a $3 Million loan over a period of eight years with %12 interest.
Combo Box - same as a list box, but the list of choices can be hidden, saving space on the GUI
abbreviated cbo (prefix)
Syntax: cboNameOfComboBox.Items.Add(item)
Example: cboOut.Items.Add("Sam is awesome!")
adds Sam is awesome! to the list box
cboOut.SelectedIndex = 0
cboOut.SelectedItem = "Sam is awesome!"
cboOut.Text = "Sam is awesome!"
all select the default item in the combo box
Rpeters
Insert
Joey P
Length property - Gets the number of characters in a string.
Syntax – string.Length
Example:
Dim intNumbers As Integer
Dim strName As String = “Joey Patricelli”
intNumbers = strName.Length
Trim method – string manipulation
TrimStart method to remove one or more characters from the start of a string
Syntax – string.TrimStart[(trimChars)]
Example:
Dim strAnimal As String = “Dog”
strAnimal.TrimStart
TrimEnd method to remove one or more characters from the end of a string
Syntax – string.TrimEnd[(trimChars)]
Example:
Dim strPercent as String
strPercent.TrimEnd("%")
Trim method to remove one or more characters from both the start and end of the character
Syntax – string.Trim[(trimChars)]
Example:
Dim strPrice As String
strPrice.Trim("$")
Laurel M
SelectAll method- Used to select all of the characters contained in a textbox
When the text is selected in a text box, the user can remove the text simply by pressing a key. The key selected replaces the selected text.
You enter this method in the textbox’s Enter event procedure.
Syntax: textbox.SelectAll( )
Ex: txtNum.SelectAll( )
Enter event- The existing text is selected (highlighted) when the control receives the focus.
Ex: txtNum.Enter
‘This selects the existing text when the textbox receives the focus.
TextChanged Event- occurs when a change is made to the contents of the control’s Text property.
This could happen as a result of the user entering data into the control, or the applications code assigning data to the control’s property.
Ex: txtNum.TextChanged
The TextChanged event helps prevent confusion because if something is entered in txtNum and displayed in the output label is the calculation performed and if the user changes the numbers entered in the txtNum, the number displayed in the label can be misleading because the original numbers are still listed in the label. You can clear the contents by coding the txtNum’s TextChanged event procedure. The txtNum’s TextChanged event procedure should clear the contents in the output label when the user changes the numbers in the textbox. The output label should also be cleared when the user selects a different choice, for example in a list box. You can do this by entering lblOut.Text = String.Empty in the listbox’s SelectedValueChanged event procedure.
Ex:
Private Sub lstChoice_SelectedValueChanged(ByVal sender As Object, ByVal e As Sysetm.EventArgs)_
Handles lstChoice.SelectedValueChanged
'clears the contents of the corresponding label
CHokaj
For…Next: A convenient way to code a loop whose instructions you want processed a precise number of times. Begins with the For clause and ends with the Next clause. You can declare the “counter” variable directly in the For…Next statement. This variable would then have block scope. It can also be declared in a Dim statement. The startvalue, endvalue, and stepvalue items determine how many times it is processed. All three of these must be numeric. StartValue tells when to begin counting. (beginning value for the counter variable). Endvalue tells when to stop counting. (ending value for the counter variable). Stepvalue tells how much to count by. (How much to incriment the counter variable by). Logically, the startvalue must be less than the endvalue if the stepvalue is positive.
For counter [As datatype] = startvalue To endvalue [Step stepvalue]
[Instructions]
Next counter
ex: For intcounter As Integer = 1 To 15
intNumber = intNumber + 1
lblOutput.Text = lblOutput.Text & intNumber.ToString & ControlChars.NewLine
Next intcounter
StartsWith Method- Determines whether a set of specific characters is found at the beginning of a string.
EndsWith Method- Determines whether a set of specific characters is found at the end of a string.
The substring is the characters that you want to search for. Both the StartsWith and EndsWith methods return Boolean values, either true or false.
String.StartsWith(substring)
String.EndsWith(substring)
ex: If txtCode.Text.ToUpper.StartsWith(“F”) Then
lblDiscount.Text = “25%”
End If
If txtCode.Text.ToUpper.EndsWith(“T5”) Then
lblDiscount.Text = “30%”
End If
ScipioH
Remove Method: allows the user to delet/remove characters from a string.
Syntax: string.Remove(startIndex, count)
Example:
Dim strName as String = Jordan Hartung
txtName.text = strName.Remove(0, 7)
assignsthe string "Jordan" to the txtName text property
Replace Method: allows you to replace a set of chacters in a string with another set of characters.
Syntax: string.Replace(oldvalue, newValue)
Example:
dim strPhone as string = “412-835-4821”
strPhone = strPhone.Replace(“412”, “410”)
Assigns the string “412-833-4871” to the word variable
Jarrod
Contains – searches a string to determine whether it contains a specific sequence of characters, and then returns a Boolean value that indicates whether the characters appear within the string.
Syntax –
string.Contains(substring)
Example:
Dim strName As String = “Jarrod”
Dim blnContains As Boolean
blnContains = strName.ToLower.Contains(“rod”)
Insert – inserts characters within a string. Begins insertion at the startIndex specified.
Syntax –
string.Insert(startIndex, value)
Example:
Dim strEmployee As String = “Mr. Schrute”
Dim strFormattedEmployee As String = “”
strFormattedEmployee = strEmployee.Insert(4, “Dwight K. ”)
CoreyB
String compare method: Compares two strings
Syntax
String.Compare(string1,string2[,ignoreCase])
Examples
Dim sngNum as single
sngNum = string.compare(“Pittsburgh”, “PITTSBURGH”)
assigns the number -1 to the sngNum variable, because the second character in string1 (i) is less than the second character in string2 (I)
Dim sngNum as single
sngNum = string.compare(“Pittsburgh”, “PITTSBURGH”, True)
assigns the number 0 to the sngNum Variable, because both strings are equal
String Like method: Compares two strings using pattern-matching characters
Pattern-matching characters Matching in string
? Any single character
* Zero or more characters
# any single digit (0-9)
[charList] any single character in chartList
[!charList] any single character not in the chartList
Syntax
String Like pattern
Example
isEqual=firstName.ToUpper like “B?LL”
Do you want access -- email Mrs. Robb and let her know you want to do your part!!
Back to Robb's Visual Basic Page
Class pages:
Quick Links
- Ubbi Dubbi -- If you thought Pig Latin was interesting check this out!
Comments (0)
You don't have permission to comment on this page.