|
Post by carlos45 on Apr 14, 2024 2:00:01 GMT
Attachments:
|
|
Aaditya Parashar
Junior Member
Just somebody with an abnormal coding routine.
Posts: 95
|
Post by Aaditya Parashar on Apr 14, 2024 7:57:21 GMT
The output size of this Code is 92 bytes. If you wanted this code to be:
Tamanho de a: 2 1 Tamanho de b: 4 1 Tamanho de c: 4 1 Tamanho de d: 8 1
which is 80 bytes, then why are you using str$? You could have done this:
Print "Tamanho de a:"; Len(a); a Print "Tamanho de b:"; Len(b); b Print "Tamanho de c:"; Len(c); c Print "Tamanho de d:"; Len(d); d
Well, how much file size do you expect?
|
|
|
Post by bplus on Apr 14, 2024 12:27:33 GMT
to save numbers in binary files these are sizes in bytes qb64phoenix.com/qb64wiki/index.php/Variable_Typesif you need really small files with uniform byte size number use binary or random access files. to save numbers in string form as in text file don't forget the space at start of postive numbers, so 1 digit number takes 2 spaces 3 digit number 4 spaces like the negative # -333 = 4 chars [ opps I count string lengths by number of spaces they take up ] You can remove the extra space with _TRIM$() function. a = 1: b = 22 c = 333 d = 4444 Print "Tamanho de a: "; Len(Str$(a)); " "; a Print "Tamanho de b: "; Len(Str$(b)); " "; b Print "Tamanho de c: "; Len(Str$(c)); " "; c Print "Tamanho de d: "; Len(Str$(d)); " "; d
|
|
|
Post by bplus on Apr 14, 2024 16:42:10 GMT
demo of tiny integer files -
Open "b in ary.bin" For Binary As #1 Dim i As Integer, a As Integer For i = 1 To 10 a = i * 7 Put #1, 2 * i - 1, a Next
Close Open "b in ary.bin" For Binary As #1 Print "file size = "; LOF(1) For i = 1 To 10 Get #1, 2 * i - 1, a Print a Next Close
lof(#1) was 21; 2 bytes for 10 integers = 20 plus an eof marker i suspect.
|
|
|
Post by carlos45 on Apr 14, 2024 21:07:40 GMT
Attachments:
|
|
|
Post by bplus on Apr 14, 2024 22:27:22 GMT
hi carlos, glad you got it figured out. i use a quick little function called ts$(), ts stands for Trim String of any integer or long number
function ts$(n as long) ' so can do long or integers ts$ = _trim$(str$(n)) end function
it saves you from allot of tedious typing
|
|
|
Post by carlos45 on Apr 15, 2024 0:17:40 GMT
Yes, I understand, but thanks again, Bplus
Cheers
Carlos
Function TS1$ (nn As Long) TS1$ = _trim$(Str$(nn)) End Function
|
|