none
Show the Result in Line RRS feed

  • Question

  • The code bellow when run show like this,It continous

    Public Class Form1
    
        Private sectorA As New List(Of Integer)
        Private sectorB As New List(Of Integer)
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            'Toc = 6235,5507,0126,9753,0354,0423,0328,6185,8449,3424,1481,1861,3234,5928,3503,1966,0513,2306,2315,3750,0190,1510,0063
    1954,8691,7223,5869,2822,3609,3259,5081,4204,3116,5806,7052,2347,9977,5773,7416, 4605,0541,0548,2138,6627,172,0617
    5810,6757,9672,9587,0800,4651,0405,1858,5623,0622,7083,0164,9144,6334,5679,1137,9954,3780,4743,4995,1272,2094,7808
    3115,3012,4336,8243,0341,6248,9846,8755,9525,3661,3421,0846,0017,0019,3503,1719,9388,6342,5102,2153,2206,9485,6162
    9257,5419,3601,5498,1877,9587,2718,8766,4933,5433,7875,6809,9794,4071,0259,1824,3186,1108,8204,6570,8192,1087,7056
    5274,7811,2674,1564,6214,0049,3822,9578,0680,3241,6480,6202,0129,5526,7033,0040,1098,3037,3719,2626,2869,0769,8168
    1924,1404,0401,9510,2635,2921,7910,4727,7208,1068,8516,7509,1768,0965,4590,2686,4508,1554,4255,3273,9417,5135,2309
    5567,5954,2521,9983,3735,7676,3644,4784,1531,1359,4466,0677,7342,5862,3487,6167,2556,3712,2165,5822,2331,8263,0190
    8178,9369,6361,0822,2736,0793,8664,4362,2635,3298,5445,3956,6472,8994,2674,2227,0418,3168,5626,6875,6371,7168,6332
    1233,3887,5684,1724,8957,6750,4700,9903,9091,3816,6854,1031,0926,7105,6326,0888,4206,8019,6419,7047,3881,1602,6590
    2725,4611,0762,7898,3543,2440,0043,1354,0266,4400,0037,9724,8531,4607,8744,3289,1259,5823,5165,3564,4694,4538,6998
    8242,8732,3857,6954,7103,8131,7515,5423,6736,6383,5071,7529,6948,1165,5016,3272,1020,1447,0573,2743,6163,1412,4421
    
    
            Dim sr As New System.IO.StreamReader("C:\Users\family\Documents\Toc.txt")
    
            Do While sr.Peek <> -1
    
                sectorA.Clear()
                sectorB.Clear()
                Dim a As String = sr.ReadLine()
    
                For i As Integer = 0 To 9
                    Dim StringToFind As String = CStr(i)
                    sectorA.AddRange(New Integer() {CInt(i)})
                    sectorB.AddRange(New Integer() {CInt(a.Count(Function(c As Char) c = StringToFind).ToString)})
                Next
                Dim Counts(999) As Integer
                For IM As Integer = 0 To sectorB.Count - 1
                    Counts(sectorB(IM)) += 1
                Next
    
                For IK As Integer = 0 To 99
                    If Counts(IK) > 1 Then
                        TextBox1.AppendText("Count of " + IK.ToString & " = " & Counts(IK).ToString & " (")
                        For J As Integer = 0 To sectorB.Count - 1
                            If sectorB(J) = IK Then TextBox1.AppendText(J.ToString & " ")
                        Next J
                        TextBox1.AppendText(")")
    
                    End If
                Next
    
            Loop
    
    
        End Sub
    End Class

    What I want to show the result follow the line.

    Friday, June 30, 2017 11:41 AM

Answers

  • How the true way to get get like this

    Your sample result doesn't seem to match the data in your first post, but I think each line of output should correspond to one line of the input file. That is, you need a new line displayed each time you read a new line from the file.

    Do While sr.Peek <> -1
        ...
        TextBox1.AppendText(vbCrLf)
    Loop

    • Marked as answer by mipakteh Saturday, July 1, 2017 4:06 AM
    Saturday, July 1, 2017 3:25 AM

All replies

  • AppendText simply concatenates to the existing string example

    Dim values As String() = Enumerable.Range(1, 10) _
        .Select(Function(item, index) $"Line {index + 1}").ToArray
    For Each value In values
        TextBox1.AppendText($"{value}{Environment.NewLine}")
    Next


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, June 30, 2017 12:42 PM
    Moderator
  • Karen;

    I don't to match your example code with my code.

    The problem is the code ;

     TextBox1.AppendText("Count of " + IK.ToString & " = " & Counts(IK).ToString & " (")

     If you free , can you give example from my code.

    Thank.

    Friday, June 30, 2017 1:25 PM
  • Hi Acamar,

    Help me.

    for this code.

     TextBox2.AppendText("Count of " + IK.ToString & " = " & Counts(IK).ToString & " (")

    Thank.

    Friday, June 30, 2017 1:28 PM
  • Something like this (did this in notepad and is meant as a way to work with)

    textBox1.AppendText($"Count of {IK.ToString()} = {Counts(IK).ToString()} {Environment.NewLine} (")



    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Friday, June 30, 2017 1:42 PM
    Moderator
  • Error at "$" .
    Friday, June 30, 2017 1:56 PM
  • Error at "$" .
    Requires VS2015 or higher, use String.Format since you must have an out dated version of Visual Studio or targeting a lower version of the .NET framework.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, June 30, 2017 2:12 PM
    Moderator
  • still error karen.

     TextBox1.AppendText(String.Format("Count of" {+ IK.ToString()} = {Counts(IK).ToString()} {Environment.NewLine}))

    Error 1 Expression does not produce a value. C:\Users\family\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 38 21 WindowsApplication1

    Friday, June 30, 2017 2:25 PM
  • still error karen.

     TextBox1.AppendText(String.Format("Count of" {+ IK.ToString()} = {Counts(IK).ToString()} {Environment.NewLine}))

    Error 1 Expression does not produce a value. C:\Users\family\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 38 21 WindowsApplication1

    Learn how to properly use String.Format e.g.

    Dim firstName As String = "Karen"
    Dim lastName As String = "Payne"
    Dim age As Integer = 50
    Dim fullName As String = String.Format("My name is {0} {1}, I'm {2}", firstName, lastName, age)
    Console.WriteLine(fullName)

    Produces

    My name is Karen Payne, I'm 50


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, June 30, 2017 3:15 PM
    Moderator
  • Hi karen,

    Still can't get what I want....

    The result;

               Dim Counts(999) As Integer
                For IM As Integer = 0 To sectorB.Count - 1
                    Counts(sectorB(IM)) += 1
                Next
    
                For IK As Integer = 0 To 99
                    If Counts(IK) > 1 Then
                        Dim SameString As String = String.Format("Count of {0}={1} ( ", +CDbl(IK.ToString), Counts(IK).ToString)
                        TextBox2.AppendText(SameString)
                        For J As Integer = 0 To sectorB.Count - 1
                            If sectorB(J) = IK Then
                                Dim SameString_ As String = String.Format("{0}", J.ToString & " ")
                                TextBox2.AppendText(SameString_)
                            End If
                        Next J
                        Dim SameString_1 As String = String.Format(")   ", Environment.NewLine)
                        TextBox2.AppendText(SameString_1)
                    End If
                Next
    
            Loop

    How the true way to get get like this;

    Saturday, July 1, 2017 2:37 AM
  • for this code.

     TextBox2.AppendText("Count of " + IK.ToString & " = " & Counts(IK).ToString & " (")

    I don't know why you would use a count.  Use MOD like the reference I posted:

              TextBox1.AppendText(")")
              If (IK MOD 2) = 0 then TextBox1.AppendText VBCrLf
    
    You are making the problem much more complicated than it needs to be.
    Saturday, July 1, 2017 2:43 AM
  • How the true way to get get like this;

    That's different than you originally posted.

    To get that result, you need to identify what marks the end of the line. In other words, you need to identify which part of your code creates the items that make up a single line.  I think perhaps the way to do that is to temporarily add IK and J to the printout for each element as it is printed.  That will reveal what combination of those two values should trigger the appending of vbCrLf. 

                For IK As Integer = 0 To 99
                    If Counts(IK) > 1 Then
                        TextBox1.AppendText("Count of " + IK.ToString & " = " & Counts(IK).ToString & " (")
                        For J As Integer = 0 To sectorB.Count - 1
                            If sectorB(J) = IK Then TextBox1.AppendText(J.ToString & " " & "<" & IK.ToString & " " & J.ToString & ">")
                        Next J
                        TextBox1.AppendText(") <" & IK.ToString & ">")
                    End If
                Next

    You could do a similar thing by stepping through the code in the debugger and noting the values of IK and J when you believe a newline should be appended.  Or, just describe what each line is supposed to represent in terms of the input data.

    • Edited by Acamar Saturday, July 1, 2017 3:08 AM sp
    Saturday, July 1, 2017 3:03 AM
  • How the true way to get get like this

    Your sample result doesn't seem to match the data in your first post, but I think each line of output should correspond to one line of the input file. That is, you need a new line displayed each time you read a new line from the file.

    Do While sr.Peek <> -1
        ...
        TextBox1.AppendText(vbCrLf)
    Loop

    • Marked as answer by mipakteh Saturday, July 1, 2017 4:06 AM
    Saturday, July 1, 2017 3:25 AM
  • Thank you very much Acamar;

      Do While sr.Peek <> -1
    
                sectorA.Clear()
                sectorB.Clear()
                Dim a As String = sr.ReadLine()
    
                For i As Integer = 0 To 9
                    Dim StringToFind As String = CStr(i)
                    sectorA.AddRange(New Integer() {CInt(i)})
                    sectorB.AddRange(New Integer() {CInt(a.Count(Function(c As Char) c = StringToFind).ToString)})
                Next
                Dim Counts(999) As Integer
                For IM As Integer = 0 To sectorB.Count - 1
                    Counts(sectorB(IM)) += 1
                Next
                For IK As Integer = 0 To 99
                    If Counts(IK) > 1 Then
                        TextBox2.AppendText("Count of " + IK.ToString & " = " & Counts(IK).ToString & " (")
    
                        For J As Integer = 0 To sectorB.Count - 1
                            If sectorB(J) = IK Then TextBox2.AppendText(J.ToString & " ")
                        Next J
                        TextBox2.AppendText(")  ")
    
                    End If
    
                Next
    
                TextBox2.AppendText(vbCrLf)
            Loop

    Saturday, July 1, 2017 4:06 AM