Results 1 to 15 of 15

Thread: vb6 question on maxlenght

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    vb6 question on maxlenght

    Can Label also have the same property as Text in terms of MaxLength?I have this in my TextBox-> Text1.MaxLength=11.

    But when i type this ->Label1.MaxLength=11,i got this as error " Method or data member not found"..

    so basically what i am doing is i am trying to make my program read the size of the file through the label and its working fine but it displays too many chracters like 1.6342243 i want to make it maybe so it just displays 4 chars

    size.Caption = "Size of the file: " & Len(sSize) & " Bytes"

    So anybody know how to do this ?

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: vb6 question on maxlenght

    What is sSize? Is it a label?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    Re: vb6 question on maxlenght

    Dim sSize As String :-) my question is how can i just limit the label.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    Re: vb6 question on maxlenght

    size is the label ;-) so i suppose label1.Caption but thats not the case the thing is how can i limit the characters on the label ?

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: vb6 question on maxlenght

    Format what you want before you add it to the label. Example:
    Code:
    Label1.Caption = "Size of the file: " & FormatNumber(dblSize, 4) & " Bytes"
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    Re: vb6 question on maxlenght

    I tryed the code you gave me but that didnt output nothing..

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    Re: vb6 question on maxlenght

    It would still say the size of the file 1683456 Bytes i just want it to read 4 first numbers or so because i am gonna make it to read in MB not megabytes but this thing reads too many digits ;-)

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: vb6 question on maxlenght

    There are many ways to do what you ask. Here a few options

    1. Label1.Caption = Left$("1683456", 4)

    2. Divide bytes by 1024 to get KBs or by 1048576 (1024*1024) to get MBs, then display the result. If you only want 2 decimals displayed, for example: 1.61 MB, use FormatNumber and specify 2 decimals.
    Last edited by LaVolpe; Mar 15th, 2009 at 07:38 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    Re: vb6 question on maxlenght

    I know what you are saying i tryed to divide that by /1024 and works like a charm but i am not understanding how to use Format thing in a code..

    size.Caption = "Velicina fajla: " & FormatNumber(dblSize, 4) & Len(sSize) & " Bytes" .. ?

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: vb6 question on maxlenght

    what is sSize? Is that the variable containing size in bytes? If so replace dblSize with sSize and see if that works. Also what variable type is sSize? Is it a string, single, double?
    Code:
    size.Caption = "Velicina fajla: " & FormatNumber(dblSize, 4) & " Bytes"
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    Re: vb6 question on maxlenght

    its a string

    Private Sub Browse2_Click()
    Dim sSize As String
    ComDlg32.Filter = "Executable file (*.exe) | *.exe"
    ComDlg32.ShowOpen
    txtFile.Text = ComDlg32.Filename
    txtIcon.SetFocus
    Open txtFile.Text For Binary As #1
    sSize = Space(LOF(1))
    Get #1, , sSize
    Close #1
    size.Caption = "Size of the file: " & Len(sSize) & " Bytes"
    End Sub

  12. #12

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    Re: vb6 question on maxlenght

    so size.Caption = "Size of the file: " & Len(sSize) / 1048576 & " MB"
    works like the charm but i can not FormatNumber thing with 2 decimals i tryed different combinations.. help me if you can

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: vb6 question on maxlenght

    You don't need to read the file into a string to get its size in bytes:
    Code:
    Private Sub Browse2_Click()
    Dim lSize As LONG, dblSize As Double, sUnit as String
    ComDlg32.Filter = "Executable file (*.exe) | *.exe"
    ComDlg32.ShowOpen
    txtFile.Text = ComDlg32.Filename
    txtIcon.SetFocus
    lSize = FileLen(comDlg32.FileName)
    If lSize < 1024 Then ' use bytes
        dblSize = lSize
        sUnit = " Bytes"
    ElseIf lSize < 1048576 Then ' use KBs
         dblSize = lSize/1024
         sUnit = " KB"
    Else ' use MBs
         dblSize = lSize/1048576
         sUnit = " MB"
    End If
    size.Caption = "Size of the file: " & FormatNumber(dblSize, 2) & sUnit
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    9

    Re: vb6 question on maxlenght

    Thanks a lot worked like a charm.. i never used double and long that much.. can you tell me what is double and long for and when to use it.. and whats the difference

  15. #15
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: vb6 question on maxlenght

    You are welcome. As a new member, do not forget to mark your posts as resolved once they become resolved. Do this thru the Thread Tools menu near top of this page.

    Here is a link to help better understand the various data types
    http://en.wikibooks.org/wiki/Visual_Basic/Data_Types
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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