Wednesday, November 24, 2010

Reading Data from a Notepad file

Reading Data from a text file and then placing it in a Listbox

Dim x As Integer
Dim r As Integer
Dim guess As String
Dim animal(5) As String
Dim inFile As IO.StreamReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
inFile = IO.File.OpenText("h:\programming2010\animals.txt")
Do Until inFile.Peek = -1
x = x + 1
animal(x) = inFile.ReadLine
listData.Items.Add(animal(x))
Loop
inFile.Close()

Tuesday, November 23, 2010

Chapter 13 Assignments

This is the code for an input statement:
strInputSales = inputbox(strPrompt, strTITLE, "0.0")


Car Solution 1 on page 274
Car Solution 2 on page 278
Sales Express Solution on Page 280-86
Exercise on Page 292 (Pick 3 of the following)
#4- Average Sales Solution
#5- Weekly Pay Solution
#6- Raise Solution
#7- Sum Even Solution

Do While and Do Until Loops

'A loop goes around and around until the condition is met

'Example of a Do While Loop- NOTE: intNum must be dimensioned

intNum =1 'If you don't set intNum to 1 then intNum = 0
Do While IntNum <=3
MessageBox.Show (intNum.ToString)
intNum= intNum +1
Loop
-------------------------------------------------------------------
'Example of a Do Until Loop:

intNum = 1
Do Until IntNum > 3
MessageBox.Show (intNum.ToString)
intNum= intNum +1
Loop

In the comment section, tell the output of each program for 5 points

Monday, November 22, 2010

Converting data from a textbox to lower or upper case

Dim strCowBiscuit as String
'Let's say the textbox is txtCowBiscuit

strCowBiscuit = txtCowBiscuit.text.ToUpper

or

strCowBiscuit = txtCowBiscuit.Text.ToLower

This assignes a string variable (strCowBiscuit) to what's inside the textbox (txtCowBiscuit) and changes it to upper or lower case

Chapter 12 Exercises

Chapter 12- (use the methods learned from Shady Hollow)
Page 262- Exercise 3
for a point of extra credit, change the MaxLength of the Texbox to 1
Exercise 4- Open Department Solution
Change the textbox MaxLength to 1
Change the case to Upper
Make it so the textbox on accepts A, a, B, b
If user clicks the display button without entering a code,
display the text "not available"
Exercise 7- Open ABC Solutions
Modify the code so that it only accepts only numbers and backspace key

Thursday, November 18, 2010

Programming code for using on the s, d, S, D or backspace

NOTE: to see if you do this right and you are successful, you should be able to put anything in the textbox except s, S, d, D or the backspace key
'First of all you need to go to the code and choose the name of the text box. The name should be something like: txtType and choose KEYPRESS
It will generate this code:
Private Sub txtType_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtType.KeyPress

'This is the code you put in the Keypress sub
' allows the text box to accept only the letters
' S, s, D, and d and the Backspace key for editing.
If e.KeyChar <> "S" AndAlso e.KeyChar <> "s" AndAlso e.KeyChar <> "D" AndAlso e.KeyChar <> "d" AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If