Results 1 to 4 of 4

Thread: Padding Questions

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    11

    Padding Questions

    I am having an issue with padding and coding. Still early on in my visual basic understanding so please go easy on me.

    I am trying to get text to line up in columns of a few array variables and am having a few issues. First this code below is throwing an error Whenever I go to run it stating: "Object reference not set to an instance of an object." A few other questions though, are why I can not pad my integer and if I wanted to display my integer depending on a checkbox, how would I need to work that code so that I don't put an If statement that would end up stating everything below followed by an else that contains all but the integer statement below? I hope these questions make sense, other than this part I think I'm in good shape.

    txtList.Text &= intA(intForm) _
    & strA(intForm).PadRight(15) _
    & strB(intForm).PadRight(30) _
    & strC(intForm).PadRight(45) _
    & strD(intForm).PadRight(60) _
    & strE(intForm).PadRight(76) _
    & ControlChars.NewLine

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    11

    Re: Padding Questions

    Just a quick update I got the error taken care of my padding sizes were way to big, but I am still unsure as to how to pad the integer?

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

    Re: Padding Questions

    PadRight is fine for just one value but, in this situation, it's not appropriate. Follow the CodeBank link in my signature and check out my thread on Fixed-Width Columns. It shouws you how to use String.Format to make the whole thing much cleaner and handle any data type with more functionality.
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    11

    Re: Padding Questions

    Got it going, appreciate that

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