Expand|Select|Wrap|Line Numbers
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- ' Declarations
- Dim sw As StreamWriter
- Dim sr As StreamReader
- Dim path1 As String = "Showme.Txt"
- Dim longest As Integer
- Dim length1 As Integer
- Dim length2 As Integer
- Dim length3 As Integer
- Dim length4 As Integer
- Dim length5 As Integer
- Dim line1 As String = AddBox1.Text
- Dim line2 As String = AddBox2.Text
- Dim line3 As String = AddBox3.Text
- Dim line4 As String = AddBox4.Text
- Dim line5 As String = AddBox5.Text
- Dim AnsLine As String = "_"
- Dim Inta As Integer
- Dim Intb As Integer
- Dim Intc As Integer
- Dim Intd As Integer
- Dim Inte As Integer
- Dim intf As Integer
- length1 = line1.Length
- length2 = line2.Length
- length3 = line3.Length
- length4 = line4.Length
- length5 = line5.Length
- Dim addspace As String = " "
- ' Deletes file if exists then recreates a new file to write to
- If File.Exists(path1) Then
- File.Delete(path1)
- End If
- sw = File.CreateText(path1)
- sw.WriteLine("Welcome to Show Me")
- sw.WriteLine()
- sw.WriteLine("Here we will take the numbers you have entered and show")
- sw.WriteLine("you how to add them to get an answer.")
- sw.WriteLine()
- sw.WriteLine("First lets get the sumbers you entered")
- sw.WriteLine()
- 'Checks to see if an entry was made in each textbox and writes
- 'to file only if true. Does this for all 5 textboxes
- If length1 > 0 Then
- sw.WriteLine((Val(AddBox1.Text)))
- End If
- If length2 > 0 Then
- sw.WriteLine((Val(AddBox2.Text)))
- End If
- If length3 > 0 Then
- sw.WriteLine((Val(AddBox3.Text)))
- End If
- If length4 > 0 Then
- sw.WriteLine((Val(AddBox4.Text)))
- End If
- If length5 > 0 Then
- sw.WriteLine((Val(AddBox5.Text)))
- End If
- ' More text
- sw.WriteLine()
- sw.WriteLine("And line up the last digits.")
- sw.WriteLine()
- ' Checks the length of each string and sets "longest"
- ' to the length of the longest string
- If length1 >= length2 Then
- longest = length1
- Else
- longest = length2
- End If
- If longest >= length3 Then
- longest = longest
- Else
- longest = length3
- End If
- If longest >= length4 Then
- longest = longest
- Else
- longest = length4
- End If
- If longest >= length5 Then
- longest = longest
- Else
- longest = length5
- End If
- ' Insert a space at the beginning of the string for each
- ' instance of a string until all strings are the same length
- ' this will line up the last digits of each entry
- Do Until length1 = longest
- line1 = line1.Insert(0, addspace)
- length1 = line1.Length
- Loop
- 'Writes the new string if it is numeric
- If (IsNumeric(line1)) Then
- sw.WriteLine(line1)
- End If
- Do Until length2 = longest
- line2 = line2.Insert(0, addspace)
- length2 = line2.Length
- Loop
- If (IsNumeric(line2)) Then
- sw.WriteLine(line2)
- End If
- Do Until length3 = longest
- line3 = line3.Insert(0, addspace)
- length3 = line3.Length
- Loop
- If (IsNumeric(line3)) Then
- sw.WriteLine(line3)
- End If
- Do Until length4 = longest
- line4 = line4.Insert(0, addspace)
- length4 = line4.Length
- Loop
- If (IsNumeric(line4)) Then
- sw.WriteLine(line4)
- End If
- Do Until length5 = longest
- line5 = line5.Insert(0, addspace)
- length5 = line5.Length
- Loop
- If (IsNumeric(line5)) Then
- sw.WriteLine(line5)
- End If
- ' Creates a line of proper length to place under the math problem
- Do Until AnsLine.Length = longest
- AnsLine = AnsLine.Insert(0, "_")
- Loop
- ' More text
- sw.WriteLine(AnsLine)
- sw.WriteLine()
- sw.WriteLine("Now that we have lined up the last digit of each number")
- sw.WriteLine("we can begin to add our numbers together.")
- sw.WriteLine("First we'll the last numbers, or the numbers farthest right.")
- sw.WriteLine()
- If line1.Length > 0 And (IsNumeric(line1)) Then
- Inta = line1.Substring(line1.Length - 1, 1)
- sw.WriteLine((Val(Inta)))
- End If
- If line2.Length > 0 And (IsNumeric(line2)) Then
- Intb = line2.Substring(line2.Length - 1, 1)
- sw.WriteLine((Val(Intb)))
- End If
- If line3.Length > 0 And (IsNumeric(line3)) Then
- Intc = line3.Substring(line3.Length - 1, 1)
- sw.WriteLine((Val(Intc)))
- End If
- If line4.Length > 0 And (IsNumeric(line4)) Then
- Intd = line4.Substring(line4.Length - 1, 1)
- sw.WriteLine((Val(Intd)))
- End If
- If line5.Length > 0 And (IsNumeric(line5)) Then
- Inte = line5.Substring(line5.Length - 1, 1)
- sw.WriteLine((Val(Inte)))
- End If
- intf = ((Val(Inta)) + (Val(Intb)) + (Val(Intc)) + (Val(Intd)) + (Val(Inte)))
- sw.WriteLine()
- sw.WriteLine("Now let's add up the numbers and see what our answer is.")
- sw.WriteLine()
- sw.WriteLine((Val(intf)))
- If intf > 9 Then
- sw.WriteLine()
- sw.WriteLine("Since our answer is over 9 we cant simply write the answer")
- sw.WriteLine("Because if we did our final answer would be wrong.")
- sw.WriteLine("We will need to do what is called Carrying.")
- sw.WriteLine()
- sw.WriteLine("This means that we are going to take the first number of our")
- sw.WriteLine("answer and carry it over to the next row and place it on top")
- sw.WriteLine("of it like so.")
- Dim Carry As String = intf
- Dim CarryLen As Integer = Carry.Length
- Do Until CarryLen = longest
- Carry = Carry.Insert(0, addspace)
- CarryLen = Carry.Length
- Loop
- Dim carrydrop As String = Carry.Substring(longest - 1, 1)
- Dim droplen As Integer
- Do Until droplen = longest
- carrydrop = carrydrop.Insert(0, addspace)
- droplen = carrydrop.Length
- Loop
- Dim Carry1 As String = Carry.Substring(longest - 2, 1)
- Dim Carry1Len As Integer
- Do Until Carry1Len = (longest - 1)
- Carry1 = Carry1.Insert(0, addspace)
- Carry1Len = Carry1.Length
- Loop
- sw.WriteLine()
- sw.WriteLine(Carry1)
- sw.WriteLine(line1)
- sw.WriteLine(line2)
- sw.WriteLine(line3)
- sw.WriteLine(line4)
- sw.WriteLine(line5)
- sw.WriteLine(AnsLine)
- sw.WriteLine()
- sw.WriteLine("Next we'll place the second number under the row we added")
- sw.WriteLine()
- sw.WriteLine(Carry1)
- sw.WriteLine(line1)
- sw.WriteLine(line2)
- sw.WriteLine(line3)
- sw.WriteLine(line4)
- sw.WriteLine(line5)
- sw.WriteLine(AnsLine)
- sw.WriteLine(carrydrop)
- sw.WriteLine()
- sw.WriteLine("Now we need to add up the next line dont forget to add")
- sw.WriteLine("the number we carried over.")
- sw.WriteLine()
- If line1.Length > 0 And (IsNumeric(line1)) Then
- Inta = line1.Substring(line1.Length - 2, 1)
- sw.WriteLine((Val(Inta)))
- End If
- If line2.Length > 0 And (IsNumeric(line2)) Then
- Intb = line2.Substring(line2.Length - 2, 1)
- sw.WriteLine((Val(Intb)))
- End If
- If line3.Length > 0 And (IsNumeric(line3)) Then
- Intc = line3.Substring(line3.Length - 2, 1)
- sw.WriteLine((Val(Intc)))
- End If
- If line4.Length > 0 And (IsNumeric(line4)) Then
- Intd = line4.Substring(line4.Length - 2, 1)
- sw.WriteLine((Val(Intd)))
- End If
- If line5.Length > 0 And (IsNumeric(line5)) Then
- Inte = line5.Substring(line5.Length - 2, 1)
- sw.WriteLine((Val(Inte)))
- End If
- sw.WriteLine()
- sw.WriteLine("And our answer is")
- sw.WriteLine()
- intf = (Val(carry1)) + ((Val(Inta)) + (Val(Intb)) + (Val(Intc)) + (Val(Intd)) + (Val(Inte)))
- sw.WriteLine(intf)
- Else
- Dim Carry As String = intf
- Dim CarryLen As Integer = Carry.Length
- Do Until CarryLen = longest
- Carry = Carry.Insert(0, addspace)
- CarryLen = Carry.Length
- Loop
- Dim carrydrop As String = Carry.Substring(longest - 1, 1)
- Dim droplen As Integer
- Do Until droplen = longest
- carrydrop = carrydrop.Insert(0, addspace)
- droplen = carrydrop.Length
- Loop
- Dim Carry1 As String = Carry.Substring(longest - 2, 1)
- Dim Carry1Len As Integer
- Do Until Carry1Len = (longest - 1)
- Carry1 = Carry1.Insert(0, addspace)
- Carry1Len = Carry1.Length
- Loop
- sw.WriteLine("Since our answer is less than 10 we would write the answer")
- sw.WriteLine("below the numbers we just added")
- sw.WriteLine()
- sw.WriteLine(line1)
- sw.WriteLine(line2)
- sw.WriteLine(line3)
- sw.WriteLine(line4)
- sw.WriteLine(line5)
- sw.WriteLine(AnsLine)
- sw.WriteLine(carrydrop)
- sw.WriteLine()
- End If
- sw.Flush()
- sw.Close()
- Diagnostics.Process.Start(path1)
- End Sub
Thanks in advance,
James