Page 1 of 1

Code Problem 'confused' 'stuck'

Posted: Wed Jan 23, 2008 7:10 am
by TimeSurfer

Code: Select all

ProcedureDLL.s ConvertBytes(FSbytes.l)
  FileSize.l = FSbytes
  If FileSize < 1024
    sTEXT.s = "Bytes"
    FileSize.l = FSbytes
  ElseIf FileSize >= 1024 And FileSize < 1048576
    sTEXT.s = "Kilobytes"
    FileSize.l = FSbytes / 1024
  ElseIf FileSize >= 1048576 And FileSize < 1073741824
    sTEXT.s = "Megabytes"
    FileSize.l = FSbytes / 1048576
  ElseIf FileSize >= 1073741824 And FileSize < 1099511627776
    sTEXT.s = "Gigabytes"
    FileSize.l = FSbytes / 1073741824
  ElseIf FileSize >= 1099511627776
    sTEXT.s = "Terabytes"
    FileSize.l = FSbytes / 1099511627776
  EndIf
  ProcedureReturn StrD(FileSize,2) + " " + sText
EndProcedure
There seems to be a problem with my code I've looked it over time and time again and yet I still can't seem to find whats wrong. It doesnt seem to work for anything past kilobytes and i cant figure out why. if anyone can give me some insight id appreciate it.

thanks in advance

Posted: Wed Jan 23, 2008 7:34 am
by citystate
longs can only hold values up to 4,294,967,296, try changing all instances of '.l' to either '.d' or '.q'

Posted: Wed Jan 23, 2008 7:39 am
by TimeSurfer
nope still doesnt work, now it doesnt return anything as to where before it would only work up until it tried gigabytes

Posted: Wed Jan 23, 2008 8:14 am
by utopiomania
This works perfect for me :roll:

Code: Select all

enumeration
  #WIN
endEnumeration

declare.s ConvertBytes(FSbytes.d) 

;-program entry
openWindow(#WIN, 0, 0, 800, 600, "", $CF0001)
messageRequester("", convertbytes(10995116277770))

;-program event handler
repeat
  event = waitWindowEvent()
  select event
    case #PB_EVENT_MENU
      select eventMenu()
      endSelect
  
    case #PB_EVENT_GADGET
      select eventGadget()
      endSelect

    case #PB_EVENT_SIZEWINDOW
       winW = windowWidth(#WIN)
       winH = windowHeight(#WIN)

    case #PB_EVENT_CLOSEWINDOW
      break 1
  endSelect
forever

;-program exit
;-
end

ProcedureDLL.s ConvertBytes(FSbytes.d) 
  FileSize.d = FSbytes 
  If FileSize < 1024 
    sTEXT.s = "Bytes" 
    FileSize = FSbytes 
  ElseIf FileSize >= 1024 And FileSize < 1048576 
    sTEXT.s = "Kilobytes" 
    FileSize = FSbytes / 1024 
  ElseIf FileSize >= 1048576 And FileSize < 1073741824 
    sTEXT.s = "Megabytes" 
    FileSize = FSbytes / 1048576 
  ElseIf FileSize >= 1073741824 And FileSize < 1099511627776 
    sTEXT.s = "Gigabytes" 
    FileSize = FSbytes / 1073741824 
  ElseIf FileSize >= 1099511627776 
    sTEXT.s = "Terabytes" 
    FileSize = FSbytes / 1099511627776 
  EndIf 
  ProcedureReturn StrD(FileSize,2) + " " + sText 
EndProcedure

Posted: Wed Jan 23, 2008 9:07 am
by Inf0Byt3
If it doesn't work, maybe a

Code: Select all

Size & $FFFFFFFF
would do?

The code seems to work fine here too, as utopiomania said.

Posted: Thu Jan 24, 2008 10:04 pm
by TimeSurfer
not sure really im just now starting to learn pb but everything ive read and ppl tell is that this should work. its a dll for a program called autoplay media studio. yet when i call the dll no info is returned unless i use long but that doesnt solve my problem as you all stated that long can only hold so much data. ive tried using double and quad and they both make the dll not function at all it just returns nothing. im very confused as to why.

dll for ams are byval if that helps at all

Posted: Fri Jan 25, 2008 1:30 am
by oridan
Try my libraries: PureCONVERTER()

Download