Code Problem 'confused' 'stuck'

Just starting out? Need help? Post your questions and find answers here.
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Code Problem 'confused' 'stuck'

Post 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
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

longs can only hold values up to 4,294,967,296, try changing all instances of '.l' to either '.d' or '.q'
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Post by TimeSurfer »

nope still doesnt work, now it doesnt return anything as to where before it would only work up until it tried gigabytes
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post 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
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
TimeSurfer
User
User
Posts: 22
Joined: Wed Jan 23, 2008 6:58 am

Post 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
oridan
Enthusiast
Enthusiast
Posts: 128
Joined: Tue Oct 12, 2004 12:14 am
Location: Italy
Contact:

Post by oridan »

Try my libraries: PureCONVERTER()

Download
Post Reply