Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. A looping Question

A looping Question

Scheduled Pinned Locked Moved Visual Basic
question
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Christian Graus

    StringReader is a strange name for a string ? Anyhow, you use a while loop. your string will return null ( Nothing in VB ) when the file is empty. Or you can use ReadAllText to get the strings out as a string array and use for each to iterate over that.

    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

    W Offline
    W Offline
    WestSideRailways
    wrote on last edited by
    #4

    Christian Graus wrote:

    StringReader is a strange name for a string ?

    It's name is what it does, so i think that the name is relevant.:-D

    C G 2 Replies Last reply
    0
    • W WestSideRailways

      Christian Graus wrote:

      StringReader is a strange name for a string ?

      It's name is what it does, so i think that the name is relevant.:-D

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #5

      It's also the name of a class, I believe. It threw me for a second, that's all.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      W 1 Reply Last reply
      0
      • T TwoFaced

        Do While Not FileReader.EndOfStream StringReader = FileReader.ReadLine Form2.Listview1.items.add(StringReader) Loop

        W Offline
        W Offline
        WestSideRailways
        wrote on last edited by
        #6

        TwoFaced wrote:

        Do While Not FileReader.EndOfStream StringReader = FileReader.ReadLine Form2.Listview1.items.add(StringReader) Loop

        This works like a charm :-D THANKS Now for another question... Is there any way to input horizonaly in a Listview box? Or is this just a matter of Formatting?. All my data is going down instead of across. I am viewing the Listview Box with Details set as true and Columns Headers ready and waiting.

        T 1 Reply Last reply
        0
        • C Christian Graus

          It's also the name of a class, I believe. It threw me for a second, that's all.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          W Offline
          W Offline
          WestSideRailways
          wrote on last edited by
          #7

          Christian Graus wrote:

          It's also the name of a class, I believe. It threw me for a second, that's all.

          Hmm, will have to check into that:) THANKS

          1 Reply Last reply
          0
          • W WestSideRailways

            TwoFaced wrote:

            Do While Not FileReader.EndOfStream StringReader = FileReader.ReadLine Form2.Listview1.items.add(StringReader) Loop

            This works like a charm :-D THANKS Now for another question... Is there any way to input horizonaly in a Listview box? Or is this just a matter of Formatting?. All my data is going down instead of across. I am viewing the Listview Box with Details set as true and Columns Headers ready and waiting.

            T Offline
            T Offline
            TwoFaced
            wrote on last edited by
            #8

            Yes, you would first add an item (the leftmost item). The 'Add' method returns a listviewitem so you can get a reference to it by writing this:

            Dim item As ListViewItem = ListView1.Items.Add(StringReader)

            Then to add an item to the next column you would use this:

            item.SubItems.Add(SubItem)

            That's basically what you need to know.

            W 1 Reply Last reply
            0
            • T TwoFaced

              Yes, you would first add an item (the leftmost item). The 'Add' method returns a listviewitem so you can get a reference to it by writing this:

              Dim item As ListViewItem = ListView1.Items.Add(StringReader)

              Then to add an item to the next column you would use this:

              item.SubItems.Add(SubItem)

              That's basically what you need to know.

              W Offline
              W Offline
              WestSideRailways
              wrote on last edited by
              #9

              TwoFaced wrote:

              Then to add an item to the next column you would use this: item.SubItems.Add(SubItem) That's basically what you need to know.

              THANKS Again:cool: Have just been doing some more reading about Listview Boxs and have just figured out that what you have said is what i need to do.;)

              W 1 Reply Last reply
              0
              • W WestSideRailways

                TwoFaced wrote:

                Then to add an item to the next column you would use this: item.SubItems.Add(SubItem) That's basically what you need to know.

                THANKS Again:cool: Have just been doing some more reading about Listview Boxs and have just figured out that what you have said is what i need to do.;)

                W Offline
                W Offline
                WestSideRailways
                wrote on last edited by
                #10

                This is my Code so far.....

                  Do While Not FileReader.EndOfStream
                        StringReader = FileReader.ReadLine
                        Form2.ListView1.Items.Add(StringReader)
                        'Adding Subitems
                        Dim item As ListViewItem = Form2.ListView1.Items.Add(StringReader)
                        Dim i As Integer
                        For i = 0 To 5
                            item.SubItems.Add(StringReader)
                        Next
                    Loop
                

                Just a little bit of fine tuning....:) What is happening is that the first item on the left is in the right spot, after that what should be the first sum-item it duplicated in the left column. Then in the 3rd row this same item is in all the sub-item columns. And the same thing happens to all the other sum-items, which then knoks out of wack all the other data. It is surprising how writing something out and then thinking about it , you can come up with an answer;):doh: AND THE ANSWER is :- move the Stringreader line into the for next loop and get rid of the line :- Form2.ListView1.Items.Add(StringReader) as you don't need it twice in the code. -- modified at 5:52 Monday 12th February, 2007

                1 Reply Last reply
                0
                • W WestSideRailways

                  Christian Graus wrote:

                  StringReader is a strange name for a string ?

                  It's name is what it does, so i think that the name is relevant.:-D

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #11

                  WestSideRailways wrote:

                  It's name is what it does

                  No, actually it's not. :) The string object doesn't read anything. It only contains data that was read. If you want to write less confusing code, you should name the variable after what it contains or what it's used for, not after what some part of the code does when it uses the variable. Also, variables are generally not named with the first letter in capital, to distinguish them from classes and methods, and using data types in variable names is generally discouraged.

                  --- single minded; short sighted; long gone;

                  W 1 Reply Last reply
                  0
                  • G Guffa

                    WestSideRailways wrote:

                    It's name is what it does

                    No, actually it's not. :) The string object doesn't read anything. It only contains data that was read. If you want to write less confusing code, you should name the variable after what it contains or what it's used for, not after what some part of the code does when it uses the variable. Also, variables are generally not named with the first letter in capital, to distinguish them from classes and methods, and using data types in variable names is generally discouraged.

                    --- single minded; short sighted; long gone;

                    W Offline
                    W Offline
                    WestSideRailways
                    wrote on last edited by
                    #12

                    Guffa wrote:

                    No, actually it's not. The string object doesn't read anything. It only contains data that was read.

                    Then maybe it should be called StringHolder or StringContainer:laugh::laugh::laugh: OPPS forgot to take the CAPS LOCK off:):)

                    G 1 Reply Last reply
                    0
                    • W WestSideRailways

                      Guffa wrote:

                      No, actually it's not. The string object doesn't read anything. It only contains data that was read.

                      Then maybe it should be called StringHolder or StringContainer:laugh::laugh::laugh: OPPS forgot to take the CAPS LOCK off:):)

                      G Offline
                      G Offline
                      Guffa
                      wrote on last edited by
                      #13

                      WestSideRailways wrote:

                      Then maybe it should be called StringHolder or StringContainer

                      It doesn't contain a string, it is a string. Well, actually it's a reference to a string, but that's implied as reference type variables always are references. It contains a line of text. What's wrong will calling it "line"? :)

                      --- single minded; short sighted; long gone;

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups