WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Sample Code

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Serial Scale and Postage computations

 Keywords: Serial Scale weight postage postal 

This example runs a scale with a serial port and display a screen showing postage to various parts of the world.
; IO and command language to various different scales
; may differ, so customization may berequired.
; This script is for a DORAN Model 300 scale  50lbs x .2 oz
; Postal tables current as of Feb 2001

testing=0
;ScaleMaster   Postal tables updated as of Feb 2001
AddExtender("wwser34i.dll")         
IntControl(12,1+4,0,0,0)
Decimals(2)

GOSUB INITTABLES
GOSUB INITCOUNTRY
GOSUB INITBOX

MyModemIsOn="COM1"
;BoxOpen("ScaleMaster","")
;WinPlace(100,300,600,900,"")

if testing==0 then port=pComOpen(MyModemIsOn,0,9600,"8N1","NONNON")  

if testing==0 then pTimeout(port,2000)      
                                                    
                         

;pPutCHAR(port,"Z")       
                         
oldresp=0
while 1      
   if IskeyDown(@shift) && testing!=0 then break            
if testing==0 
   resp=pGetLine(port,30)
else 
   rr=random(3)
   if rr==0 then resp=strcat(Num2Char(2)," 3 lb 11.9 oz")
   if rr==1 then resp=strcat(Num2Char(2)," 0 lb 0.0 oz")
   if rr==2 then resp=strcat(Num2Char(2)," 33 lb 11.9 oz")
   if rr==3 then resp=strcat(Num2Char(2)," 3 lb 15.9 oz")
   ;if rr==4 then resp=strcat(Num2Char(2)," 6 lb 15.9 oz")
   TimeDelay(1)
endif
   ;Is Data good
   resp=strsub(resp,strindex(resp,Num2Char(2),0,@backscan),-1)
   if strsub(resp,1,1) != Num2Char(2) then continue
   ;do we have lb and oz
   x=strindexnc(resp,"lb",0,@fwdscan)
   y=strindexnc(resp,"oz",0,@fwdscan)
   if x==0 || y==0
       ;BoxText("Changing units --- %resp%")
       if testing==0 then   pPutChar(port,"U")
       for z=1 to 5
          if testing==0 then   pGetLine(port,30)
       next
       continue
   endif


   if oldresp==resp then continue
   oldresp=resp


  if StrIndex(resp,"-",0,@fwdscan)!=0
      GOSUB DOZEROXXX
      continue
   endif
   ;BoxText("RAW = |%resp%|")
   parsedata(resp)
   pounds=param2
   origpounds=pounds
   origounces="%param4%"
   ounces=ceiling(origounces)
   if ounces==16
      ounces=0.0
      pounds=pounds+1
   endif
   nextpounds=pounds
   if ounces!=0 then nextpounds=nextpounds+1
   totalounces=pounds*16+ounces

   if totalounces==0.0
      gosub DOZERO
      continue
   endif

   GOSUB DOWEIGHTS
   
   ;Postage Computations
   ;USA
   gosub DoFirstClass
   Gosub DoPriorityMail
   Gosub DoExpressmail
  ;INTL
   ;dataline=strcat(dataline,@crlf,"                          LetPost    PclPost        Pty        Expr  ",@crlf)

    GOSUB DoCountries
   ;BoxText(dataline)
   ;if IsKeyDown(@CTRL) then pputchar(port,"U")
endwhile

  if testing==0 then pComClose(port,0)          

exit


;****************************************************************************
;****************************************************************************
:DOFIRSTCLASS
;First Class
   if totalounces<14
      firstclass=0.34 + (totalounces-1)*0.21
   else
      firstclass="---"
   endif
  ; dataline=strcat(@crlf,dataline,@crlf,"US First Class Letters = ",firstclass,@crlf)

    BoxTextFont(1,"",50,70,2+32)
    BoxDrawText(1,"150,300,350,360",firstclass,@TRUE,2)
    BoxTextFont(1,"",40,70,2+32)
    BoxDrawText(1,"360,310,800,360","US First Class Letters",@TRUE,0)


   return

;****************************************************************************
:DOPRIORITYMAIL
;Priority Mail
   if nextpounds <= 5
      prioritymail=0.0+ItemExtract(nextpounds,primailZ3," ")
      BoxTextFont(1,"",50,70,2+32)
      BoxDrawText(1,"0,360,350,420",prioritymail,@TRUE,2)
   else
      prioritymail=""
      for zz=3 to 8
          zz2=zz
          if zz==3 then zz2=123
          if zz==6 then prioritymail=strcat(prioritymail,@crlf)
          prioritymail=strcat(prioritymail,"     Z%zz2% = ",ItemExtract(nextpounds,primailZ%zz%," "))       
      next
      BoxTextFont(1,"",20,70,2+32)
      BoxDrawText(1,"0,360,350,420",prioritymail,@TRUE,0)

   endif

    BoxTextFont(1,"",40,70,2+32)
    BoxDrawText(1,"360,370,800,420","US Priority Mail",@TRUE,0)


   return
;****************************************************************************
:DOEXPRESSMAIL
;ExpressMail
   if totalounces <= 8
      expressmail=12.25
   else
      if nextpounds <=70
        expressmail=0.0+ItemExtract(nextpounds,expresstab," ")
      else
        expressmail="---"
      endif
  endif
    BoxTextFont(1,"",50,70,2+32)
    BoxDrawText(1,"150,420,350,480",expressmail,@TRUE,2)
    BoxTextFont(1,"",40,70,2+32)
    BoxDrawText(1,"360,430,800,480","US Express Mail",@TRUE,0)

  return
;*******************************************************************
:DOGPM
;Global Priority mail  4 pound max
    lprategroup=ItemExtract(7,tabledata," ")
    if totalounces<=64
       gpmdata=0.0+ItemExtract(ceiling(totalounces/8.0),gpmtab%lprategroup%," ")
    else
       gpmdata="---"
    endif



return

;******************************************************************
:DOLETTERPOST
    lprategroup=ItemExtract(7,tabledata," ")

    if totalounces<=8
        lpdata=0.0+ItemExtract(totalounces,lptab%lprategroup%a," ")
    else
        if totalounces<=64
           lpdata=0.0+ItemExtract(ceiling(totalounces/4.0),lptab%lprategroup%b," ")
        else
           lpdata="---"
        endif
    endif

return
;
;********************************************************************
;********************************************************************
:DOPARCELPOST
    pprategroup=ItemExtract(3,tabledata," ")

     if nextpounds > 10
        ppdata="Eeek"
     else
       ppdata=0.0+ItemExtract(nextpounds,pptab%pprategroup%," ")
     endif

 return
;********************************************************************
:DOEMS
    emsrategroup=ItemExtract(1,tabledata," ")

     if nextpounds > 10
        emsdata="Eeek"
     else
        if totalounces<=8
          emsdata=0.0+ItemExtract(1,emstab%pprategroup%," ")
        else
          emsdata=0.0+ItemExtract(nextpounds+1,emstab%pprategroup%," ")
        endif
     endif
return
;********************************************************************
:DOCOUNTRIES
    BoxTextFont(1,"",30,70,2+32)
    colspacing=180
    colwidth=160
    cola=50
    colb=cola+colspacing
    colc=colb+colspacing
    cold=colc+colspacing
    cole=cold+colspacing
    colaz=cola+colwidth
    colbz=colb+colwidth
    colcz=colc+colwidth
    coldz=cold+colwidth
    colez=cole+colwidth
    BoxDrawText(1,"%cola%,550,%colaz%,580","Country",@TRUE,0)
    BoxDrawText(1,"%colb%,550,%colbz%,580","LetterPost",@TRUE,2)
    BoxDrawText(1,"%colc%,550,%colcz%,580","ParcelPost",@TRUE,2)
    BoxDrawText(1,"%cold%,550,%coldz%,580","GPM Priority",@TRUE,2)
    BoxDrawText(1,"%cole%,550,%colez%,580","EMS Express",@TRUE,2)

    fsize=35
    fspace=0
    ftop=580
    BoxTextFont(1,"",fsize,70,2+32)

ccode=0
while 1
   if IsDefined(CountryData[ccode,0]) == 0 then break
   country=CountryData[ccode,0]
   tabledata=CountryData[ccode,1]
   ccode=ccode+1
   GOSUB DOLETTERPOST
   GOSUB DOPARCELPOST
   GOSUB DOEMS
   GOSUB DOGPM
   yoffset=ftop+ ccode*fsize
   yoffsetz=yoffset+fsize+fspace
   BoxDrawText(1,"%cola%,%yoffset%,%colaz%,%yoffsetz%",country,@true,0)
   BoxDrawText(1,"%colb%,%yoffset%,%colbz%,%yoffsetz%",lpdata,@true,2)
   BoxDrawText(1,"%colc%,%yoffset%,%colcz%,%yoffsetz%",ppdata,@true,2)
   BoxDrawText(1,"%cold%,%yoffset%,%coldz%,%yoffsetz%",gpmdata,@true,2)
   BoxDrawText(1,"%cole%,%yoffset%,%colez%,%yoffsetz%",emsdata,@true,2)
endwhile


return


;*********************************************************************
:INITCOUNTRY
CountryData=ArrDimension(20,2)
; dim 0 = Country name
; dim 1 = EMSRateGrp EMSMAXLBS 


CountryData[0,0]="Canada"
CountryData[0,1]="1 66 1 1 66 675 1 1"

CountryData[1,0]="Australia"
CountryData[1,1]="8 44 9 8 44 3370 4 4"

CountryData[2,0]="Denmark"
CountryData[2,1]="7 44 6 6 70 5000 3 6"

CountryData[3,0]="France"
CountryData[3,1]="6 66 6 6 66 5000 3 3"

CountryData[4,0]="England"
CountryData[4,1]="3 66 3 3 66 2020 3 3"

CountryData[5,0]="Germany"
CountryData[5,1]="7 44 6 6 70 5000 3 3"

CountryData[6,0]="Italy"
CountryData[6,1]="7 44 6 6 44 2200 3 3"

CountryData[7,0]="Netherlands"
CountryData[7,1]="7 44 6 6 44 4405 3 3"

CountryData[8,0]="Switzerland"
CountryData[8,1]="7 66 6 6 66 5000 3 6"

CountryData[9,0]="Sweden"
CountryData[9,1]="7 44 7 7 44 5000 3 6"


return
;*****************************************************************************
:INITBOX
BLACK="0,0,0"
WHITE="255,255,255"
RED="255,0,0"
GREEN="0,255,0"	
DKGRAY="128,128,128"
GRAY="192,192,192"
DKRED="128,0,0"
DKGREEN="0,128,0"
BLUE="0,0,255"
PURPLE="255,0,255"
YELLOW="255,255,0"
CYAN="0,255,255"	
DKBLUE="0,0,128"
DKPURPLE="128,0,128"
DKYELLOW="128,128,0"
DKCYAN="0,128,128"


BoxColor(1,CYAN,0)
BoxesUp("200,200,800,800", @normal)
BoxDrawRect(1,"",2) 
BoxCaption(1, "Post Master Pro 2001")
BoxTextFont(1,"",40,70,2+32)
BoxTextColor(1,BLACK)
BoxDrawText(1,"700,10,1000,60","Post Master 2001",@FALSE,0)
;                                                                BoxColor(1,YELLOW,0)
BoxDataTag(1,"MAIN")
REDRAWWEIGHTS=@FALSE
REDRAWZERO=@FALSE
REDRAWZEROXXX=@FALSE

return
;***************************************************************************
:DOZERO
 BoxDataClear(1,"MAIN")
if REDRAWZERO==@TRUE
    BoxUpdates(1,3)
    REDRAWZERO=@FALSE
endif
REDRAWWEIGHTS=@TRUE
REDRAWZEROXXX=@TRUE


BoxTextFont(1,"",400,70,2+32)
BoxDrawText(1,"100,300,900,900","-----",@TRUE,1)
return

;***************************************************************************
:DOZEROXXX
BoxDataClear(1,"MAIN")
if REDRAWZEROXXX==@TRUE
    BoxUpdates(1,3)
    REDRAWZEROXXX=@FALSE
endif
REDRAWWEIGHTS=@TRUE
REDRAWZERO=@TRUE



BoxTextFont(1,"",400,70,2+32)
BoxDrawText(1,"100,300,900,900","-NEG-",@TRUE,1)
return


;***************************************************************************
:DOWEIGHTS
 BoxDataClear(1,"MAIN")
if REDRAWWEIGHTS==@TRUE
    BoxUpdates(1,3)
    REDRAWWEIGHTS=@FALSE
endif
REDRAWZERO=@TRUE
REDRAWZEROXXX=@TRUE

Decimals(1)
BoxTextFont(1,"",100,70,2+32)
BoxDrawText(1,"40,10,200,110",origpounds,@TRUE,1+128)

BoxTextFont(1,"",75,70,2+32)
BoxDrawText(1,"210,35,370,110",origounces,@TRUE,1+128)

BoxTextFont(1,"",30,70,2+32)
BoxDrawText(1,"40,120,200,150","Pounds",@TRUE,1)
BoxDrawText(1,"210,120,370,150","Ounces",@TRUE,1)

BoxTextFont(1,"",20,70,2+32)
BoxDrawText(1,"700,100,810,120","Raw",@TRUE,0)
BoxDrawText(1,"700,130,810,150","Next lb.",@TRUE,0)
BoxDrawText(1,"700,160,810,180","Tot oz.",@TRUE,0)

BoxDrawText(1,"820,100,1000,120",strtrim(strsub(resp,2,-1)),@TRUE,0)
BoxDrawText(1,"820,130,1000,150",nextpounds,@TRUE,0)
BoxDrawText(1,"820,160,1000,180",totalounces,@TRUE,0)

Decimals(2)

BOXDATATAG(1,"WEIGHTS")

return
;*****************************************************************************
:INITTABLES
;US Express mail  Starting at 1 poound  8 oz is 12.25
expresstab="16 16 18.85 21.7 24.5 27.3 30 31.2 32.45 33.65 35.15 37.55 39.25 40.2 41.4 42.75 44.1 45.35 "
expresstab=strcat(expresstab,"46.65 48 49.25 50.55 51.9 53.15 54.45 55.75 57.05 58.35 59.65 61 62.25 63.6 ")
expresstab=strcat(expresstab,"64.85 66.2 67.45 68.8 70.3 71.9 73.5 75.1 76.7 78.35 79.9 81.5 82.9 84.15 85.6 86.9 88.2 89.5")


; Priority US mail by pounds
; Up to 4 pounds same for all zones
primailZ3="3.5 3.95 5.15 6.35 7.55 7.9 8.25 8.5 8.65 8.75 9 9.25 9.6 9.95 10.3 10.65 11 11.35 11.7 12.05 12.4 12.75 13.1 13.45 13.8 14.15 14.5 14.85 15.2 "
primailZ3=strcat(primailZ3,"15.55 15.9 16.25 16.6 16.95 17.3 17.65 18 18.35 18.7 19.05 19.4 19.75 20.1 20.45 20.8 21.15 21.5 21.85 22.2 22.55 22.9 23.25 23.6 23.95 24.3 24.65 25 25.35 ")
primailZ3=strcat(primailZ3,"25.7 26.05 26.4 26.75 27.1 27.45 27.8 28.15 28.5 28.85 29.2 29.55")

primailZ4="3.5 3.95 5.15 6.35 7.55 8.1 8.65 9.2 9.75 10.3 10.85 11.4 11.95 12.5 13.05 13.6 14.15 14.7 15.25 15.8 16.35 16.9 17.45 18 18.55 19.1 19.65 20.2 "
primailZ4=strcat(primailZ4,"20.75 21.3 21.85 22.4 22.95 23.5 24.05 24.6 25.15 25.7 26.25 26.8 27.35 27.9 28.45 29 29.55 30.1 30.65 31.2 31.75 32.3 32.85 33.4 33.95 34.5 35.05 35.6 36.15 ")
primailZ4=strcat(primailZ4,"36.7 37.25 37.8 38.35 38.9 39.45 40 40.55 41.1 41.65 42.2 42.75 43.3")


primailZ5="3.5 3.95 5.15 6.35 7.55 8.15 8.75 9.35 9.95 10.55 11.15 11.75 12.35 12.95 13.55 14.15 14.75 15.35 15.95 16.55 17.15 17.75 18.35 18.95 19.55 20.15 "
primailZ5=strcat(primailZ5,"20.75 21.35 21.95 22.55 23.15 23.75 24.35 24.95 25.55 26.15 26.75 27.35 27.95 28.55 29.15 29.75 30.35 30.95 31.55 32.15 32.75 33.35 33.95 34.55 35.15 35.75 ")
primailZ5=strcat(primailZ5,"36.35 36.95 37.55 38.15 38.75 39.35 39.95 40.55 41.15 41.75 42.35 42.95 43.55 44.15 44.75 45.35 45.95 46.55")

primailZ6="3.5 3.95 5.15 6.35 7.55 8.25 8.95 9.65 10.35 11.05 11.75 12.45 13.15 13.85 14.55 15.25 15.95 16.65 17.35 18.05 18.75 19.45 20.15 20.85 21.55 22.25 " 
primailZ6=strcat(primailZ6,"22.95 23.65 24.35 25.05 25.75 26.45 27.15 27.85 28.55 29.25 29.95 30.65 31.35 32.05 32.75 33.45 34.15 34.85 35.55 36.25 36.95 37.65 38.35 39.05 39.75 40.45 " )
primailZ6=strcat(primailZ6,"41.15 41.85 42.55 43.25 43.95 44.65 45.35 46.05 46.75 47.45 48.15 48.85 49.55 50.25 50.95 51.65 52.35 53.05")


primailZ7="3.5 3.95 5.15 6.35 7.55 9.5 10.45 11.4 12.35 13.3 14.25 15.2 16.15 17.1 18.05 19 19.95 20.9 21.85 22.8 23.75 24.7 25.65 26.6 27.55 28.5 29.45 30.4 " 
primailZ7=strcat(primailZ7,"31.35 32.3 33.25 34.2 35.15 36.1 37.05 38 38.95 39.9 40.85 41.8 42.75 43.7 44.65 45.6 46.55 47.5 48.45 49.4 50.35 51.3 52.25 53.2 54.15 55.1 56.05 57 57.95 " )
primailZ7=strcat(primailZ7,"58.9 59.85 60.8 61.75 62.7 63.65 64.6 65.55 66.5 67.45 68.4 69.35 70.3")


primailZ8="3.5 3.95 5.15 6.35 7.55 10.35 11.65 12.95 14.25 15.55 16.85 18.15 19.45 20.75 22.05 23.35 24.65 25.95 27.25 28.55 29.85 31.15 32.45 33.75 35.05 " 
primailZ8=strcat(primailZ8,"36.35 37.65 38.95 40.25 41.55 42.85 44.15 45.45 46.75 48.05 49.35 50.65 51.95 53.25 54.55 55.85 57.15 58.45 59.75 61.05 62.35 63.65 64.95 66.25 67.55 68.85 " )
primailZ8=strcat(primailZ8,"70.15 71.45 72.75 74.05 75.35 76.65 77.95 79.25 80.55 81.85 83.15 84.45 85.75 87.05 88.35 89.65 90.95 92.25 93.55")


;Intl Letter Post tables
lptab1a="0.60 0.85 1.10 1.35 1.60 1.85 2.10 2.35"
lptab1b="xxxx xxxx 3.10 3.75 4.40 5.05 5.70 6.35 7.00 7.65 8.30 8.95 9.65 10.35 11.05 11.75"

lptab2a="0.60 0.85 1.25 1.65 2.05 2.45 2.85 3.25"
lptab2b="xxxx xxxx 4.00 5.15 6.30 7.45 8.60 9.75 10.95 12.15 13.35 14.55 15.80 17.05 18.30 19.55"

lptab3a="0.80 1.60 2.40 3.20 4.00 4.80 5.60 6.40"
lptab3b="xxxx xxxx 7.55 8.70 9.85 11.00 12.15 13.30 14.50 15.70 16.90 18.10 19.35 20.60 21.85 23.10"


lptab4a="0.80 1.70 2.60 3.50 4.40 5.30 6.20 7.10"
lptab4b="xxxx xxxx 8.40 9.70 11.00 12.30 13.60 14.90 16.25 17.60 18.95 20.30 21.70 23.10 24.50 25.90"

lptab5a="0.80 1.55 2.30 3.05 3.80 4.55 5.30 6.05"
lptab5b="xxxx xxxx 7.65 9.25 10.85 12.45 14.04 15.65 17.35 19.05 20.75 22.45 24.20 25.95 27.70 29.45"

;Global Prioirty mail
gpmtab1="6.00 8.00 9.00 11.00 12.00 14.00 16.00 18.00"
gpmtab2="7.00 9.00 10.00 13.00 16.00 19.00 22.00 25.00"
gpmtab3="8.00 10.00 12.00 15.00 18.00 21.00 23.00 26.00"
gpmtab4="9.00 11.00 12.00 16.00 19.00 22.00 24.00 27.00"
gpmtab5="8.00 12.00 14.00 17.00 21.00 24.00 28.00 31.00"

;Global Express Email   EMS

emstab1 ="15.50 16.25 17.00 18.25 19.25 20.50 22.75 25.00 27.25 29.50 31.75"
emstab2 ="16.75 20.00 23.70 27.60 31.10 34.20 36.40 38.60 40.80 43.00 45.20"
emstab3 ="20.00 24.75 28.75 32.75 35.75 38.75 41.75 44.75 47.75 50.75 53.75"
emstab4 ="17.00 21.00 25.00 29.00 33.00 36.75 40.05 43.35 46.65 49.95 53.25"
emstab5 ="19.00 22.75 26.05 30.50 34.90 39.20 43.45 47.70 51.95 56.20 60.45"
emstab6 ="17.00 19.15 21.65 24.95 28.15 31.85 34.95 38.05 41.15 44.25 47.35"
emstab7 ="23.00 26.00 29.00 32.00 35.00 38.00 41.40 44.40 47.60 50.80 54.00"
emstab8 ="17.00 20.50 24.00 28.00 32.00 36.00 40.20 44.40 48.60 52.80 57.00"
emstab9 ="18.00 22.00 26.00 30.00 35.00 40.00 44.65 49.30 53.95 58.60 63.25"
emstab10="22.75 25.25 28.25 32.50 36.50 40.75 45.00 49.25 53.50 57.75 62.00"
emstab11="28.50 31.25 35.50 40.50 44.75 49.75 54.50 59.25 64.00 68.75 73.50"
emstab12="22.25 24.75 28.00 32.00 36.00 40.00 44.00 48.00 52.00 56.00 60.00"


pptab1 ="13.25 13.25 14.25 15.50 16.75 17.85 18.95 20.05 21.15 22.25"
pptab2 ="13.00 15.50 17.75 20.25 23.00 25.00 27.00 29.00 31.00 33.00"
pptab3 ="16.00 20.00 24.00 28.00 32.00 35.00 38.00 41.00 44.00 47.00"
pptab4 ="16.25 20.50 24.50 29.00 33.50 36.80 40.10 43.40 46.70 50.00"
pptab5 ="15.25 19.75 24.50 29.75 35.00 39.25 43.50 47.75 52.00 56.25"
pptab6 ="14.00 15.50 17.50 20.25 22.75 25.65 28.55 31.45 34.35 37.25"
pptab7 ="16.50 19.00 21.75 24.50 27.25 30.25 33.25 36.25 39.25 42.25"
pptab8 ="12.50 16.00 20.00 24.25 28.75 32.65 36.55 40.45 44.35 48.25"
pptab9 ="14.50 18.75 23.25 26.75 32.75 36.50 40.40 44.30 48.20 52.10"
pptab10="16.00 18.50 21.50 24.00 26.50 29.50 32.50 35.50 38.50 41.50"
pptab11="18.00 22.00 26.00 30.00 34.00 37.50 41.00 44.50 48.00 51.50"
pptab12="14.00 15.50 17.25 19.25 21.25 23.75 26.25 28.75 31.25 33.75"
pptab13="17.00 19.00 22.00 25.00 28.00 31.25 34.50 37.75 41.00 44.25"



return



Article ID:   W14797
File Created: 2001:11:08:12:40:02
Last Updated: 2001:11:08:12:40:02