Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:33:41+00:00 2026-05-26T17:33:41+00:00

So I am trying to do something simple: printfn Enter a number: try let

  • 0

So I am trying to do something simple:

 printfn "Enter a number:"
    try
       let x = System.Console.ReadLine();
       Some(int32(x))
    with
       | :? System.FormatException -> printfn "Invalid number!"
                                      Some(0)

I want to print the message, then get the user to input a number, and try to convert it to an int and return it.

If I just compile the code (by typing fsc a3.fs on the command line), it works fine. It pauses, waits for input, then returns Some(int).

If I copy and paste the code into the FSI on the command line, it works great.

But when I am in visual studio, and I run the code in the FSI (highlight + alt+enter), it just goes right over the input part and the exception is thrown (and caught).

Here is the output when I run in the FSI (in visual studio):

Enter a number:
Invalid number!
0

As you can see, It doesnt ever actually pause and wait for me to enter input.

Anyone know how to make this work?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:33:41+00:00Added an answer on May 26, 2026 at 5:33 pm

    The F# Interactive console in Visual Studio does not support reading input, so there is no way to ask for an input from the console. If you’re running code interactively, you can always enter the input in the editor, so the best workaround is to have let binding at the beginning where you enter the input before running your code. You can use #if to support both scenarios:

    #if INTERACTIVE
    // TODO: Enter input here when running in F# Interactive
    let input = "42"
    #endif
    
    try 
        #if INTERACTIVE
        Some(int32 input)
        #else
        let x = System.Console.ReadLine(); 
        Some(int32(x)) 
        #endif
    with 
        | :? System.FormatException -> 
            printfn "Invalid number!" 
            Some(0) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying something very simple, but for some reason it does not work.
I'm trying to do something simple to practice my Javascript (which I learned some
actually I thought I was trying something really simple. ControllerClassNameHandlerMapping sounded great to produce
I feel like I'm trying to do something simple but I am not getting
Hey guys, I've been trying to build something simple in Flash 8, and I
I'm trying to do something very simple, yet I can't seem to find the
I'm trying to do something seemingly simple: ensure that Application_BeginRequest is called for every
I am trying to accomplish something very simple, and I'm hoping someone can point
I'm trying to do something really simple, but starting to realize that dates in
I am trying to deserialize an object from XML in Ruby. Something simple like:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.