PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
vb.format-VBForums
Results 1 to 12 of 12

Thread: vb.format

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    vb.format

    Hi

    How to create own function vb.format,vb.day in Vb.net. For reverse i have created like this

    Public Shared Function Reverse(ByVal strParam As String) As String
    If strParam.Length = 1 Then
    Return strParam
    Else
    Return Reverse(strParam.Substring(1)) + strParam.Substring(0, 1)
    End If
    End Function

    Thanks

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,596

    Re: vb.format

    You should really rewrite your code, learn the VB.Net syntax.
    Instead of trying to mimic every intrinsic VB6 method.

  3. #3
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    168

    Re: vb.format

    I agree with Arnoutdv.

    In .Net you can take things one step futher. You can create your own extension functions.

    https://docs.microsoft.com/en-us/dot...tension-method
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  4. #4
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    168

    Re: vb.format

    Jagjit, i have been reading your posts... and ik have to wonder.... Do you have access to Google or not?
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    Re: vb.format

    Hi

    Inbuilt function are there but if custom function to be created how it can be done
    Thanks

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,947

    Re: vb.format

    Why would you want to do such a thing? If you really want to use the VB6 Format function in VB.NET then you can. Just type 'Format' and away you go. Of course, the vast majority of VB Runtime functions have equivalent and possibly superior versions in the .NET Framework. In the case of Format, that would be the String.Format method, which is what you should be using to do composite formatting in VB.NET. It works in pretty much exactly the same way as Format.

    As for reversing a String, I'd do it like this:
    vb.net Code:
    1. Imports System.Runtime.CompilerServices
    2.  
    3. Public Module StringExtensions
    4.  
    5.     <Extension>
    6.     Public Function Reverse(source As String) As String
    7.         Dim chars = source.ToCharArray()
    8.  
    9.         Array.Reverse(chars)
    10.  
    11.         Return New String(chars)
    12.     End Function
    13.  
    14. End Module
    Because it's an extension method, you can call it like an instance method, e.g.
    vb.net Code:
    1. Dim text = "Hello World"
    2.  
    3. Console.WriteLine(text.Reverse())

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,947

    Re: vb.format

    For anything to do with dates and/or times, use the DateTime and/or TimeSpan types. If you want to know the day of the week for a date, you can use the DayOfWeek property, e.g.
    vb.net Code:
    1. Dim today = Date.Today.DayOfWeek

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    Re: vb.format

    Hi jm

    I want to get day from the date using own function . Is that can be done.

    Thanks

  9. #9
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,092

    Re: vb.format

    Quote Originally Posted by Jagjit View Post
    Hi jm

    I want to get day from the date using own function . Is that can be done.

    Thanks
    It could, but why? I suppose you could just wrap jmc's one line into a function if you are that desperate to make it look like you are avoiding the built-in functionality.

    However, why?

  10. #10
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,947

    Re: vb.format

    Quote Originally Posted by Jagjit View Post
    Hi jm

    I want to get day from the date using own function . Is that can be done.

    Thanks
    Any function you write would have to use members from the DateTime type inside it anyway, so what do you think it would achieve? If you have a DateTime value then it has a Day property for the numerical day of the month, a DayOfWeek property and you can call ToString to get the day as text in various formats. What exactly do you think your method could do that those don't already do and not using those members internally? You could, for instance, write a more specific method if you need to use it a lot, e.g.
    vb.net Code:
    1. Imports System.Runtime.CompilerServices
    2.  
    3. Public Module DateTimeExtensions
    4.  
    5.     <Extension>
    6.     Public Function GetDayName(source As DateTime) As String
    7.         Return source.ToString("dddd")
    8.     End Function
    9.  
    10.     <Extension>
    11.     Public Function GetDayAbbreviation(source As DateTime) As String
    12.         Return source.ToString("ddd")
    13.     End Function
    14.  
    15. End Module
    vb.net Code:
    1. Console.WriteLine(Date.Now.GetDayName()) 'Displays Thursday
    2. Console.WriteLine(Date.Now.GetDayAbbreviation()) 'Displays Thu

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,437

    Re: vb.format

    Perhaps he wants to rewrite VB6 in VB.Net to create a 64-bit VB6. I think that would go over like a lead balloon in the VB6 community.

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,452

    Re: vb.format

    Based on another thread, I think he's trying to upgrade a VB6 project to .NET with the least amount of effort and code changes... which I get... but by the time you research what the changes should be and implement a replacement, you probably could have just re-written the app from the ground up.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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