Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > help


Reply
 
Thread Tools Display Modes
  #1  
Old 11-27-2003, 03:30 AM
jayalath jayalath is offline
Newcomer
 
Join Date: Nov 2003
Location: Sri Lanka
Posts: 13
Default help


how can I save a number to a required format in a file

Thanks
Reply With Quote
  #2  
Old 11-27-2003, 03:38 AM
wilbert's Avatar
wilbert wilbert is offline
Senior Contributor
 
Join Date: Dec 2002
Location: Netherlands
Posts: 867
Default

What do you mean?? Writing a number/text to a file has been discussed many times on this forum. If that is what you mean have a search for 'writing files'.

Wilbert
Reply With Quote
  #3  
Old 11-27-2003, 04:33 PM
jayalath jayalath is offline
Newcomer
 
Join Date: Nov 2003
Location: Sri Lanka
Posts: 13
Default

Quote:
Originally Posted by wilbert
What do you mean?? Writing a number/text to a file has been discussed many times on this forum. If that is what you mean have a search for 'writing files'.

Wilbert



I have some values/numbers entered through the key board and I want to save those numbers to a predefined format,

Ex, If I enter 3,4.5,6,7.2 I like to save these numbers
3.0 4.5 6.0 7.2

I used the following method for that,

if the values are stroed in c, g, etc.

c_string = format (c,"####.####)
g_string =format (g,"####.####)

etc...

print #3, c_string;g_string


But this did not work

Thanks
Reply With Quote
  #4  
Old 11-27-2003, 04:35 PM
Volte's Avatar
Volte Volte is offline
Ultimate Contributor

Retired Leader
* Guru *
 
Join Date: Aug 2001
Posts: 5,343
Default

Can you paste some actual code?
Reply With Quote
  #5  
Old 11-27-2003, 06:17 PM
jayalath jayalath is offline
Newcomer
 
Join Date: Nov 2003
Location: Sri Lanka
Posts: 13
Default

Quote:
Originally Posted by VolteFace
Can you paste some actual code?



Hello

This is the code I used

Open "fort101.dat" For Output As #3
Print #3, np_block - 1

For i = 1 To np_block
ii = Format(i, "#####")
xx = Format(xp(i), "####.#####")
yy = Format(yp(i), "####.#####")
Print #3, ii; xx; yy
Me.Caption = xx
Next i

For i = 1 To np_block - 2
ii = Format(i, "#####")
xx = Format(xc(i), "####.#####")
yy = Format(yc(i), "####.#####")
Print #3, ii; xx; yy
Next i


Print #3, "0"

c_print = Format(c, "####.#####")
fai_print = Format(fai, "####.#####")
gamma_print = Format(gamma, "####.#####")

Print #3, fai_print; c_print; gamma_print
Print #3, "0.0"
Close #3

I am expecting to use this file in a previously developed program in Fortran. It needs to read data using formatI5,F10.3 etc...

Thanks
Reply With Quote
  #6  
Old 11-27-2003, 06:24 PM
DaftasBrush's Avatar
DaftasBrush DaftasBrush is offline
Senior Contributor

* Expert *
 
Join Date: Jun 2003
Location: A room without Windows
Posts: 896
Default

For Fixed Length / Decimal Place formatting use 0 not #

Format(12.345,"#####.#####") will give 12.345
Format(12.345,"00000.00000") will give 00012.34500

HTH
__________________
Dan B
"Don't anthropomorphize computers. They don't like it."
Trig is for wuss's - Coordinate Geometry RULES!
Reply With Quote
  #7  
Old 11-27-2003, 06:42 PM
jayalath jayalath is offline
Newcomer
 
Join Date: Nov 2003
Location: Sri Lanka
Posts: 13
Default

Quote:
Originally Posted by DaftasBrush
For Fixed Length / Decimal Place formatting use 0 not #

Format(12.345,"#####.#####") will give 12.345
Format(12.345,"00000.00000") will give 00012.34500

HTH



Hello !

Thanks for the advice. I tried that as well, but I want to have numbers without un-necessry "0's" if possible.

Otherwise, with extra zeros the program is running now.

Thanks for the point

Jayalath
Reply With Quote
  #8  
Old 11-27-2003, 06:45 PM
Volte's Avatar
Volte Volte is offline
Ultimate Contributor

Retired Leader
* Guru *
 
Join Date: Aug 2001
Posts: 5,343
Default

How about if you format it with "#.00"?
Reply With Quote
  #9  
Old 11-27-2003, 07:07 PM
jayalath jayalath is offline
Newcomer
 
Join Date: Nov 2003
Location: Sri Lanka
Posts: 13
Default

Quote:
Originally Posted by VolteFace
How about if you format it with "#.00"?



Hello !

No it does not work.....It will not leave blank spaces for required length.

Thanks for your concern

Jayalath
Reply With Quote
  #10  
Old 11-27-2003, 07:08 PM
Volte's Avatar
Volte Volte is offline
Ultimate Contributor

Retired Leader
* Guru *
 
Join Date: Aug 2001
Posts: 5,343
Default

When I do this:
Code:
MsgBox Format(4, "#.0")
It shows 4.0 -- is this not what you want, or am I totally mistaken?
Reply With Quote
  #11  
Old 11-28-2003, 03:05 AM
jayalath jayalath is offline
Newcomer
 
Join Date: Nov 2003
Location: Sri Lanka
Posts: 13
Default

Quote:
Originally Posted by VolteFace
When I do this:
Code:
MsgBox Format(4, "#.0")
It shows 4.0 -- is this not what you want, or am I totally mistaken?



As long as there are numbers, it follows the condition given by '#', otherwise, it will not leave any spaces as we want. For '0's it will att extra '0's to the length indicated by format.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->