Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1681
Number of posts: 4770

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
String to Integer Posted by CheeseMonkey on 7 Jun 2001 at 4:42 PM
I'm making this program that requires taking a number from a file and using it in the program. Is there anyway i can take an integer from a file? How can a change that number in the file to an integer?

Thanks for everyones help

Report
Re: String to Integer Posted by billywm664 on 10 Jun 2001 at 3:30 AM
To get a string from a text file -
First, have the file open of course:

OPEN "filename.txt" for input as #1

Filename.txt should be replaced with whatever the filename is

Then, to input, read in lines of text into a string variable:

line input #1, a$

This will get one line from the file into a$. To print it out to the screen as an integer:

print val(int(a$))

You can omit int and just use val(a$), but then it wont necessarily be an integer. could be floating point, etc.

: I'm making this program that requires taking a number from a file and using it in the program. Is there anyway i can take an integer from a file? How can a change that number in the file to an integer?
:
: Thanks for everyones help
:


Report
Re: String to Integer Posted by retrogeek on 14 Jun 2001 at 7:24 PM
: To get a string from a text file -
: First, have the file open of course:
:
: OPEN "filename.txt" for input as #1
:
: Filename.txt should be replaced with whatever the filename is
:
: Then, to input, read in lines of text into a string variable:
:
: line input #1, a$
:
: This will get one line from the file into a$. To print it out to the screen as an integer:
:
: print val(int(a$))
:
: You can omit int and just use val(a$), but then it wont necessarily be an integer. could be floating point, etc.
:
: : I'm making this program that requires taking a number from a file and using it in the program. Is there anyway i can take an integer from a file? How can a change that number in the file to an integer?
: :
: : Thanks for everyones help
: :
:
:

You have val and int reversed. An oversight I'm sure. Should be:
print int(val(a$))

rg





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.