[RESOLVED] Replacements for vbCrLf, vbTab, etc-VBForums
Results 1 to 11 of 11

Thread: [RESOLVED] Replacements for vbCrLf, vbTab, etc

  1. #1

    Thread Starter
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Resolved [RESOLVED] Replacements for vbCrLf, vbTab, etc

    Recently stummbled on the issue of using a '.NET' replacement for the constants 'vbCrLf, vbTab', etc.

    Figured out that vbCrLf = Environment.Newline, but others are not so easy. I have had a look at Wossnames' Char Initializer class (nice job! ), and it works well for creating other control characters.

    Was this an oversight on M$ part, not providing a .NET equivalent for the Chr and Asc functions, do you think? (Is it still the same in V2005?)
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,089

    Re: Replacements for vbCrLf, vbTab, etc

    You can use the Convert function.
    VB Code:
    1. MessageBox.Show("Test" & Convert.ToChar(13) & "Test")
    2. '"Test"
    3. '"Test"
    Edit: I think its more of a choice MS made to advance VB towards OOP and get away from the days of BASIC language.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  3. #3
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,089

    Re: Replacements for vbCrLf, vbTab, etc

    Hers the Tab equilivalent.
    VB Code:
    1. MessageBox.Show("Test" & Convert.ToChar(9) & "Test")
    2. '"Test    Test"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  4. #4

    Thread Starter
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: Replacements for vbCrLf, vbTab, etc

    Thanks Rob, I didn't know about the Convert function.

    I would have to say that I am totally new to all things VB, so am not burdened with any problems upgrading from VB6. It is all new to me!
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  5. #5
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,089

    Re: Replacements for vbCrLf, vbTab, etc

    I know its hard for VB6 programmers to convert to vb.net as it was and still is to a point for me too. Seems if you have no VB6 experience your better off because your not trying to convert old vb6 habits, which usually aren't the best, to new vb.net.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Replacements for vbCrLf, vbTab, etc

    ControlChars.Tab, ControlChars.NewLine, ControlChars.Quote

    These come from the VisualBasic namespace but not from the Compatibility namespace. NOTE: You can't unreference the VisualBasic namespace in a VB application nor is it bad.

    In C# you could use \r\n or \t.
    Last edited by Edneeis; Jul 31st, 2005 at 02:12 PM.

  7. #7
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,089

    Re: Replacements for vbCrLf, vbTab, etc

    Convert comes from the System namespace so I think its best to use those since it is more relative to .NET.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  8. #8
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,089

    Re: Replacements for vbCrLf, vbTab, etc

    Ed, isnt that the same as JavaScript? Makes sense ince C# is very similar to C++ and JavaScript.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,850

    Re: Replacements for vbCrLf, vbTab, etc

    The easiest way to create characters for things like Tab, etc. is to use ControlChars, as suggested in the VS help. If you don't like VB Runtime constants then the next easiest way is to combine Rob's suggestion with the Keys enumeration. The Keys enumeration gives a descriptive name to ASCII and Unicode codes so you don't need to remember the codes yourself. To get the Tab character you just use Convert.ToChar(Keys.Tab). Intellisense will give you a list of the members of the enumeration so if you aren't sure what you're looking for you can type "keys." and browse the listing.

    Quote Originally Posted by RobDog888
    Convert comes from the System namespace so I think its best to use those since it is more relative to .NET.
    I guarantee you that the overwhelming majority of C# developers will use the escaped C characters rather than using the Convert class, so ControlChars is no more language-specific than that.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: Replacements for vbCrLf, vbTab, etc

    To get the Tab character you just use Convert.ToChar(Keys.Tab).
    Thanks JM, that's cool.

    It appears there are many ways to skin many cats in .NET!
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,850

    Re: [RESOLVED] Replacements for vbCrLf, vbTab, etc

    Note that Convert.ToChar(Int32) and Convert.ToInt32(Char) work the same as ChrW() and AscW(). The Keys enumeration also has the Return (CR) and LineFeed (LF) members.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.