Date: Mon, 30 Aug 2004 12:13:18 -0500 (CDT) From: Mark Jacobson To: 810-030-01@uni.edu Subject: MakeInitials code from Monday (class #4)... Hi Visual Basic (.NET) students, Here is the code from today's class. It is a modification of the code on your handout from last Friday, so you might want to compare the two versions. Notice that the classic program takes INPUT, PROCESSES it, and produces OUTPUT. I P O = INPUT, PROCESSING, OUTPUT - - - I and O are the WHAT. What are you given? INPUT data? ---- What is the goal? OUTPUT results? P is the HOW to convert the I to the O. HOW to get from Input to Output. In computer science --- and programming, the HOW is called an ALGORITHM. It just a recipe. ------ Private Sub cmdMakeInitials_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles cmdMakeInitials.Click Dim theInitials As String ' declare some variables Dim first, middle, last As String first = Mid(txtFirst.Text, 1, 1) ' obtain each initial middle = Mid(txtMiddle.Text, 1, 1) ' from the INPUT last = Mid(txtLast.Text, 1, 1) ' Mid() does the PROCESSING theInitials = first & " " & middle & " " & last ' concatenate ' and separate ' by spaces the ' M F J or J V A ' or whatever initials ' concatenation with & is PROCESSING, ' & is more processing of the INPUT for OUTPUT goal. lblInitials.Text = theInitials ' display them in the lblInitials ' label! This is OUTPUT! End Sub ' variables are chunks of memory. ' variables have a type, such as String or Integer or Single. ------ ------- ------ "UNI" 17 3.14159 "Panthers" 101 429.75 The concatenation operator is for Strings. It is the & symbol. & = ampersand symbol. The Mid() function takes THREE arguments. ----- Argument 1: What STRING literal or variable or .Text property string from a TextBox or a Label is the input data???? Argument 2: Where do you want to start in the MIDdle of that string? --- Argument 3: How many characters do you want, starting from there? Examples: Mid("UNI", 2, 1) gives "N" Mid("UNI", 2, 2) gives "NI" Dim str As String str = "Ghostbusters!" Mid(str, 6, 3) gives "bus" Mid(str, 10, 2) gives "er" Mid(str, 2, 10) gives "hostbuster" Mid("Panthers", 5, 3) gives "her" See you in class on Wednesday. There will be a group exercise on Wednesday that sees how well you can apply what you have learned in the last two classes and in the Initials Maker program handout and examples. Mark