• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

format single variable and write to sequential file

Can someone please help me with this.  I am trying to format a single so that it is in the format of ##.00

My code gives me ##

No decimal point and no zeros to the right.  If I use a string variable it works, but I need the field to not have a text qualifier eg. "".

Here is my code:
    'omitted all other fields that are being written to text file.

    strActual_Weight = (mrsSathExport!Actual_Weight) & ""
    sngActual_Weight = Format(Val(strActual_Weight), "standard")

    Write #1, strPO_Number, lngDate, strTrack_Number, strShipping_Cost, _
        strShip_Method, sngActual_Weight, strPKGID

0
nicas113000
Asked:
nicas113000
1 Solution
 
spauljosephCommented:
Use this in code

sngActual_Weight = Format(Val(strActual_Weight), "##.0#")
0
 
nicas113000Author Commented:
This is still giving me the same results.

"6506148",0,"087467260000000","2671","R02",38,"1560170"

The field with the 38 should be 38.00

I don't understand why this is not working, either one of the above should work, right?
0
 
Sankar_VCommented:
use this!

Format$(val(strActual_weight),"0.00")

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
VBtomCommented:
I suppose you declared sngActual_Weight as single, since I see no quotes around it in the resulting line of text in the file.

Then after the formatting it's reconverted to numeric so the formatting has no effect at all.

So declare it as string, or don't use it at all and do the formatting in the write-instruction:

strActual_Weight = (mrsSathExport!Actual_Weight) & ""

Write #1, strPO_Number, lngDate, strTrack_Number, strShipping_Cost, _
       strShip_Method, Format(Val(strActual_Weight), "##.00"), strPKGID

0
 
VBtomCommented:
Or, if you don't want quotes around it so it's still numeric when written with input", you should use Print #1 instead of Write #1:

Print #1, """" & strPO_Number & """"; ","; CStr(lngDate); ","; """" & strTrack_Number & """"; ","; """" & strShipping_Cost & """"; ","; _
  """" & strShip_Method & """"; ","; Format(Val(strActual_Weight), "##.00"); ","; """" & strPKGID & """"
0
 
VBtomCommented:
sorry mistyping, i meant when read with input# :)
0
 
nicas113000Author Commented:
Thanks, this does exactly what I need.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now