?
Solved

format single variable and write to sequential file

Posted on 2003-03-21
7
Medium Priority
?
133 Views
Last Modified: 2010-05-01
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
Comment
Question by:nicas113000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:spauljoseph
ID: 8185447
Use this in code

sngActual_Weight = Format(Val(strActual_Weight), "##.0#")
0
 

Author Comment

by:nicas113000
ID: 8185524
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
 
LVL 1

Expert Comment

by:Sankar_V
ID: 8185663
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.

 
LVL 3

Expert Comment

by:VBtom
ID: 8185717
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
 
LVL 3

Accepted Solution

by:
VBtom earned 1000 total points
ID: 8185751
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
 
LVL 3

Expert Comment

by:VBtom
ID: 8185754
sorry mistyping, i meant when read with input# :)
0
 

Author Comment

by:nicas113000
ID: 8188473
Thanks, this does exactly what I need.
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question