|
-
Mar 15th, 2009, 05:33 PM
#1
Thread Starter
New Member
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 ?
-
Mar 15th, 2009, 05:53 PM
#2
Re: vb6 question on maxlenght
What is sSize? Is it a label?
-
Mar 15th, 2009, 06:04 PM
#3
Thread Starter
New Member
Re: vb6 question on maxlenght
Dim sSize As String :-) my question is how can i just limit the label.
-
Mar 15th, 2009, 06:09 PM
#4
Thread Starter
New Member
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 ?
-
Mar 15th, 2009, 06:46 PM
#5
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"
-
Mar 15th, 2009, 07:22 PM
#6
Thread Starter
New Member
Re: vb6 question on maxlenght
I tryed the code you gave me but that didnt output nothing..
-
Mar 15th, 2009, 07:24 PM
#7
Thread Starter
New Member
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 ;-)
-
Mar 15th, 2009, 07:33 PM
#8
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.
-
Mar 15th, 2009, 08:53 PM
#9
Thread Starter
New Member
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" .. ?
-
Mar 15th, 2009, 09:04 PM
#10
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"
-
Mar 15th, 2009, 09:07 PM
#11
Thread Starter
New Member
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
-
Mar 15th, 2009, 09:13 PM
#12
Thread Starter
New Member
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
-
Mar 15th, 2009, 09:22 PM
#13
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
-
Mar 15th, 2009, 09:33 PM
#14
Thread Starter
New Member
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
-
Mar 15th, 2009, 09:41 PM
#15
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|