maximum length for string in VB6-VBForums
Results 1 to 17 of 17

Thread: maximum length for string in VB6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    South Africa
    Posts
    105

    maximum length for string in VB6

    Hi

    If I declare a string in vb6, and don't specify a maximum value, like this:

    VB Code:
    1. Dim strAString as string

    1. What is the maximum amount of characters which can be held in this string?
    2. If I do not specify a maximum - then does this waste memory?

    many thanks

    langals
    Share on Google+

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: maximum length for string in VB6

    1) approx 2 billion characters
    2) No.
    Share on Google+

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,531

    Re: maximum length for string in VB6

    (1) I read somewhere, it is 2GB
    (2) I think it will waste space only if you specify the maximum limit, otherwise not.

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...
    Share on Google+

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    South Africa
    Posts
    105

    Re: maximum length for string in VB6

    Hi guys

    thanks for the replies. It must be something else in my code with is causing problems then.

    langals
    Share on Google+

  5. #5
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: maximum length for string in VB6

    langals:

    Greeting to you there in South Africa.

    It might be easier for someone to help you if you posted some or all of your code.

    Then we could see just what is happening or not happening and probably find a solution for you.

    Good Luck
    Last edited by AIS4U; Mar 26th, 2006 at 01:39 PM.
    Share on Google+

  6. #6
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,511

    Re: maximum length for string in VB6

    A VB variable-length string can only in theory be 2GB in size, it's actual maximum size is depending on available virtual memory which is also limited to 2GB for the entire application. But since VB stores the string in unicode format it means that it can only contain 1GB of text.

    Also the string takes up 12 bytes apart from the actual text, so even an empty string takes up 12 bytes of memory.

    A fixed length string is limited to 64KB in length.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP
    Share on Google+

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

    Re: maximum length for string in VB6

    I thought virtual memory was maxed at 4095 kbs?
    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
    Share on Google+

  8. #8
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,511

    Re: maximum length for string in VB6

    4095 kbs? That's a transfer speed... . But you are correct Rob. All 32-bit applications runs in a separate virtual machine and each of those are assigned 4GB of virtual memory. However 2 of those 4GB are used by the OS itself and the other 2 can be freely used by the application.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP
    Share on Google+

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

    Re: maximum length for string in VB6

    Thanks for the confirmation JA. Windows wont let you enter in anything larger then 4095 so its 1 byte short of 4 GBs.

    I'll remember that 1/2 is used by Windows.
    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
    Share on Google+

  10. #10
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,511

    Re: maximum length for string in VB6

    Actually it's not 1 byte less it's just that the memory area is zero based.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP
    Share on Google+

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

    Re: maximum length for string in VB6

    Misleading but ok.
    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
    Share on Google+

  12. #12
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,511

    Re: maximum length for string in VB6

    Misleading? How?
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP
    Share on Google+

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

    Re: maximum length for string in VB6

    "Total paging size for all drives: 4095 MBs"

    If its zero based then you could display "0 MBs" but still actually have 1 MB. Although, I do know the minimum is 8 MBs.
    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
    Share on Google+

  14. #14
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,511

    Re: maximum length for string in VB6

    Oh, you're talking about the size of the paging file... Well, the paging on the drive is used for swapping of memory but it's not actually the same as the virtual memory. 4GB is given to every process you are running and if the physical memory is not enough then paging will occur (well, you know all of that).
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP
    Share on Google+

  15. #15
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    968

    Re: maximum length for string in VB6

    Maybe this thread can help..i had the same problem/doubt
    http://www.vbforums.com/showthread.php?t=372024
    With special attention to what Joacim Andersson wrote..
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.
    Share on Google+

  16. #16
    Junior Member Mehdi Jazini's Avatar
    Join Date
    Feb 2014
    Location
    Tehran
    Posts
    23

    Re: maximum length for string in VB6

    In my opinion you can easily test it:

    Code:
        Dim T As Long
        Dim BB As String
        
        For T = 1 To 2000000
            BB = BB + "x"
        Next T
        
        Debug.Print Len(BB)
        Stop
    Share on Google+

  17. #17
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,511

    Re: maximum length for string in VB6

    This thread is 8 years old. Thread closed!
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP
    Share on Google+

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.