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. Read from text file

Read from text file

Scheduled Pinned Locked Moved Visual Basic
visual-studiographicstutorialquestioncareer
7 Posts 3 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.
  • M Offline
    M Offline
    mr jets
    wrote on last edited by
    #1

    heloo guys.. u really doing agreat job ..any way i have created strings for each shape (lines,polygons,..) each string contains informations about the shape( x1,y1,x2,y2,R,G,B,pen width) ..Now how can i make my prog read from the text and draw the shapes ..as example the line string : public void AddSv(Line l , ref string str) { if(drawwhat==1)// as one means lines str +="1"+"\n"+l.First.X.ToString()+"\n"+ l.First.Y.ToString()+"\n"+ l.Second.X.ToString()+"\n"+ l.Second.Y.ToString()+"\n"+ l.Pen.Color.R.ToString()+"\n"+ l.Pen.Color.G.ToString()+"\n"+ l.Pen.Color.B.ToString()+"\n"+ l.Pen.Width.ToString()+"\n\n"; after i draw the line i click on save to send the informations to the text : private void button1_Click(object sender, System.EventArgs e) { //save System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); streamWriter.WriteLine(LineSv); streamWriter.Flush(); streamWriter.Close(); fs.Close(); }as u can see i dealing vs 2003 . Regards;;)

    C 1 Reply Last reply
    0
    • M mr jets

      heloo guys.. u really doing agreat job ..any way i have created strings for each shape (lines,polygons,..) each string contains informations about the shape( x1,y1,x2,y2,R,G,B,pen width) ..Now how can i make my prog read from the text and draw the shapes ..as example the line string : public void AddSv(Line l , ref string str) { if(drawwhat==1)// as one means lines str +="1"+"\n"+l.First.X.ToString()+"\n"+ l.First.Y.ToString()+"\n"+ l.Second.X.ToString()+"\n"+ l.Second.Y.ToString()+"\n"+ l.Pen.Color.R.ToString()+"\n"+ l.Pen.Color.G.ToString()+"\n"+ l.Pen.Color.B.ToString()+"\n"+ l.Pen.Width.ToString()+"\n\n"; after i draw the line i click on save to send the informations to the text : private void button1_Click(object sender, System.EventArgs e) { //save System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); streamWriter.WriteLine(LineSv); streamWriter.Flush(); streamWriter.Close(); fs.Close(); }as u can see i dealing vs 2003 . Regards;;)

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

      you need to read the string, then you need to parse it. It would make more sense to put commas between data items, so each shape is a line of text. They read the file as a string[] and call string.Split on each line to turn 1,2,34,5, into an array of strings, which you can then turn into numbers with int.TryParse. You can read the first number and use it to decide which function to send the array to, so that it can be parsed and objects added back to your array. It would make more sense for the Line,Square,Triangle,Circle,whatever classes to offer a method that returns the string, so you can just iterate over your collection of base objects and call it.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      D M 2 Replies Last reply
      0
      • C Christian Graus

        you need to read the string, then you need to parse it. It would make more sense to put commas between data items, so each shape is a line of text. They read the file as a string[] and call string.Split on each line to turn 1,2,34,5, into an array of strings, which you can then turn into numbers with int.TryParse. You can read the first number and use it to decide which function to send the array to, so that it can be parsed and objects added back to your array. It would make more sense for the Line,Square,Triangle,Circle,whatever classes to offer a method that returns the string, so you can just iterate over your collection of base objects and call it.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        I may have hit myself in the head, but didn't we have an XmlSerializer class laying around somewhere? :-D

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        1 Reply Last reply
        0
        • C Christian Graus

          you need to read the string, then you need to parse it. It would make more sense to put commas between data items, so each shape is a line of text. They read the file as a string[] and call string.Split on each line to turn 1,2,34,5, into an array of strings, which you can then turn into numbers with int.TryParse. You can read the first number and use it to decide which function to send the array to, so that it can be parsed and objects added back to your array. It would make more sense for the Line,Square,Triangle,Circle,whatever classes to offer a method that returns the string, so you can just iterate over your collection of base objects and call it.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          M Offline
          M Offline
          mr jets
          wrote on last edited by
          #4

          do u mean like that : if(openFileDialog1.ShowDialog()==DialogResult.OK) { StreamReader streamReader=new StreamReader(openFileDialog1.FileName); string m=streamReader.ReadToEnd(); string []x= m.Split(); MessageBox.Show(m); streamReader.Close(); } but this displays all the data in the file even after putting commas between data like 1 23 38 0 0 0 1 ,2.... iam lost !:confused:

          C 1 Reply Last reply
          0
          • M mr jets

            do u mean like that : if(openFileDialog1.ShowDialog()==DialogResult.OK) { StreamReader streamReader=new StreamReader(openFileDialog1.FileName); string m=streamReader.ReadToEnd(); string []x= m.Split(); MessageBox.Show(m); streamReader.Close(); } but this displays all the data in the file even after putting commas between data like 1 23 38 0 0 0 1 ,2.... iam lost !:confused:

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

            I think I've suggested several times now that you abandon this project, it is obviously beyond you. What else did you expect it to do ? You've done one part of what I said, although not quite how I said it, and shown the strings on the screen, what else could happen without more code to do it ?

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            M 1 Reply Last reply
            0
            • C Christian Graus

              I think I've suggested several times now that you abandon this project, it is obviously beyond you. What else did you expect it to do ? You've done one part of what I said, although not quite how I said it, and shown the strings on the screen, what else could happen without more code to do it ?

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              M Offline
              M Offline
              mr jets
              wrote on last edited by
              #6

              u are right mr Graus ..i just wanna to thank u specially for ur effort with me ..god bless u my brother ; its the last time to ask about this project ..i swear . cheers;);

              C 1 Reply Last reply
              0
              • M mr jets

                u are right mr Graus ..i just wanna to thank u specially for ur effort with me ..god bless u my brother ; its the last time to ask about this project ..i swear . cheers;);

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

                Well, don't give up entirely. Just work through some other stuff so you're better able to understand the advice you're being given. I'm still trying to help, not to shoot you down in flames.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                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