Results 1 to 11 of 11

Thread: Variable Types

  1. #1

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Variable Types

    As String would be a single line of text, what would be the variable type for multiple lines of text?
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Variable Types

    You can store many lines in a string
    "The dark side clouds everything. Impossible to see the future is."

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Variable Types

    Quote Originally Posted by smart_phil_dude1
    As String would be a single line of text, what would be the variable type for multiple lines of text?
    This isn't true... A string is a string, it doesn't matter how many lines it contains. You can add lines to a string by inserting Chr(10), Chr(13), ControlChars.NewLine... Some thing lke this:
    VB Code:
    1. Dim str As String = "This is 1st line" & Chr(10) & "This is 2nd line"

  4. #4
    Fanatic Member MetalKid's Avatar
    Join Date
    Aug 2005
    Location
    Green Bay, Wisconsin
    Posts
    534

    Re: Variable Types

    Well, a string is really just an array of chars and a new line is just a combination of chars, so thus you can have any number of "lines" in a string variable.

  5. #5

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: Variable Types

    well, i am programming an application that reads off multiple lines on a txt file, but it won't read multiple lines, it only works if one line is written.
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Variable Types

    Quote Originally Posted by smart_phil_dude1
    well, i am programming an application that reads off multiple lines on a txt file, but it won't read multiple lines, it only works if one line is written.
    How do you read the file? And what version of VB are you coding with?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Variable Types

    If you are reading one line at a time then you're only reading part of the string that the file contains at a time. You can read the whole file into a single string:
    VB Code:
    1. Dim contents As String = IO.File.ReadAllText("file path here")
    or you can read the contents of the file and break it up on the line breaks:
    VB Code:
    1. Dim lines As String() = IO.File.ReadAllLines("file path here")
    There are other ways to read the file too but they all amount to the same thing. You can read the whole file into a single string if you want. If you read a line at a time then it's YOU who are removing the line breaks and splitting the file contents into pieces. If you don't need the individual lines then don't break the file up into lines. If you do need the lines then you can either read and use one line at a time or do as I did above and use a String array.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: Variable Types

    i set it up into different lines, just like using your second example...
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Variable Types

    Sorry, I'm not sure whether that last post constituted a question or not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Lively Member smart_phil_dude1's Avatar
    Join Date
    Jun 2005
    Location
    Behind You!
    Posts
    125

    Re: Variable Types

    well i tried what you explained and i still get an error
    Please Help Us Save Ana or donate now by going to Oneana.com

    Visit my Website at http://www.therealfantasy.com

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Variable Types

    And how can we possibly help fix it if you don't tell us what it is?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width