0

In python to assign an input to a variable with the input() function now i know the vb equivalent would be variable = console.readline but with python you can specify text in the input eg name = input("Enter your name") Is there such a way to do this in vb without writing them on two seperate lines?

-Thanks

3
  • You would have to create your own method that does that. Commented Nov 20, 2018 at 19:51
  • Would writing your own function to do this satisfy your requirement? Otherwise, ReadLine won't write to the console and WriteLine won't read from the console. Commented Nov 20, 2018 at 19:52
  • Short answer no. learn.microsoft.com/en-us/dotnet/api/… it doesn't accept any arguments. As the_lotus said you could simply make your own method which accepts a string and then does a writeline and readline for you. Saves you a bit of typing Commented Nov 20, 2018 at 19:52

1 Answer 1

2

What was said in the comments

Public Class LikePython
    Public Shared Function Input(Optional Prompt As String = "") As String
        Console.Write(Prompt)
        Return Console.ReadLine
    End Function
End Class

Test

Sub Main()
    Dim foo As String
    foo = LikePython.Input
    Stop
    foo = LikePython.Input(">")
    Stop
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.