String to Integer - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

String to Integer

CheeseMonkeyCheeseMonkey Posts: 2Member
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

Comments

  • billywm664billywm664 Posts: 176Member
    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
    :


  • retrogeekretrogeek Posts: 93Member
    : 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


Sign In or Register to comment.