d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > What Are The Outputs Of These? > Visual Basic
Add Reply New Topic New Poll
Member
Posts: 6,175
Joined: Sep 4 2009
Gold: Locked
Trader: Scammer
Nov 16 2013 08:31pm
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim x, y, z As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
y = 0
x = CDbl(sr.ReadLine)
Do While x < 5
If x = 4 Then
sr.Close()
sr = IO.File.OpenText("DATA.TXT")
End If
z = x + y
x = CDbl(sr.ReadLine)
y = CDbl(sr.ReadLine)
Loop
txtBox.Text = CStr(z)
sr.Close()
End Sub
The nine lines of the file DATA.TXT contain the following data: 3, 4, 6, 8, 1, 2, 5, 9, 3.



Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim letter As String
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
Do While sr.Peek <> -1
letter = sr.ReadLine
txtBox.Text &= letter
Do While (sr.Peek <> -1) And (letter <> "*")
letter = sr.ReadLine
Loop
Loop
End Sub
Assume the 12 lines of the file DATA.TXT contain the following data: a, b, c, *, d, *, e, f, g, h, *, i.

This is my first time using visual basics so I am not familiar with some of these terms.
For instance, what is sr and the express "<>" ??
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2013 09:15pm
Quote (Chesse @ Nov 16 2013 10:31pm)
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
  Dim x, y, z As Double
  Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
  y = 0
  x = CDbl(sr.ReadLine)
  Do While x < 5
    If x = 4 Then
      sr.Close()
      sr = IO.File.OpenText("DATA.TXT")
    End If
    z = x + y
    x = CDbl(sr.ReadLine)
    y = CDbl(sr.ReadLine)
  Loop
  txtBox.Text = CStr(z)
  sr.Close()
End Sub
The nine lines of the file DATA.TXT contain the following data:3, 4, 6, 8, 1, 2, 5, 9, 3.



Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
  Dim letter As String
  Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
  Do While sr.Peek <> -1
    letter = sr.ReadLine
    txtBox.Text &= letter
    Do While (sr.Peek <> -1) And (letter <> "*")
      letter = sr.ReadLine
    Loop
  Loop
End Sub
Assume the 12 lines of the file DATA.TXT contain the following data: a, b, c, *, d, *, e, f, g, h, *, i.

This is my first time using visual basics so I am not familiar with some of these terms.
For instance, what is sr and the express "<>" ??


sr is just a variable you defined as an instance of StreamReader

<> is "not equal"

just run your program to see the output

This post was edited by carteblanche on Nov 16 2013 09:16pm
Member
Posts: 6,175
Joined: Sep 4 2009
Gold: Locked
Trader: Scammer
Nov 17 2013 03:49pm
Are the answers for
1) 13

2) c*, d*, h*
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 17 2013 05:47pm
Run your code to verify your answers.

use paper/pencil to calculate it by hand.

And don't pm me.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll