#Include "windows.bi"
' Declare external functions
''Declare function GetStdHandle( byval nStdHandle as ulong ) as ulong
''Declare function ReadConsoleA( byval hConsoleInput as ulong, byval lpBuffer as any ptr, byval nNumberOfCharsToRead as ulong, byref lpNumberOfCharsRead as ulong, byval lpReserved as any ptr ) as long
' Define constants
''Const STD_INPUT_HANDLE = -10
''Const STD_OUTPUT_HANDLE = -11
''Const STD_ERROR_HANDLE = -12
const BUFSIZE As integer = 128
' Define input function
function InputBox( prompt as string ) as string
dim as ulong bytes_read,vp
dim as any ptr input_handle
dim as integer Ptr buffer ' any ?
dim as string input_text
' Get handle to console input
input_handle = GetStdHandle( STD_INPUT_HANDLE )
' Allocate memory for input buffer
buffer = allocate( BUFSIZE * SIZEOF( INTEGER )) ' Char ?
If (buffer = 0) Then
Print "error"
End -1
EndIf
' Print prompt
print prompt;
' Read input from console
'------------------------------ problem zone ?---------------//
ReadConsoleA( input_handle, buffer, BUFSIZE, varptr(bytes_read),0 ) '
'------------------------------ problem zone ?---------------//
' Convert buffer to string
input_text = ltrim(Str(buffer) ) ' *buffer
''input_text = str(buffer)
' Free memory
DeAllocate(buffer)
' Return input text
return input_text
End function
' Main program
dim as string myname
' Get user input
myname = InputBox( "Enter your name: " )
' Print input
Print ("Hello, "); myname; "!"
sleep
End 0
#Include "windows.bi"
' Declare external functions
''Declare function GetStdHandle( byval nStdHandle as ulong ) as ulong
''Declare function ReadConsoleA( byval hConsoleInput as ulong, byval lpBuffer as any ptr, byval nNumberOfCharsToRead as ulong, byref lpNumberOfCharsRead as ulong, byval lpReserved as any ptr ) as long
' Define constants
''Const STD_INPUT_HANDLE = -10
''Const STD_OUTPUT_HANDLE = -11
''Const STD_ERROR_HANDLE = -12
const BUFSIZE As integer = 128
' Define input function
function InputBox( prompt as string ) as string
dim as ulong bytes_read,vp
dim as any ptr input_handle
dim as zstring Ptr buffer ' <==========
dim as string input_text
' Get handle to console input
input_handle = GetStdHandle( STD_INPUT_HANDLE )
' Allocate memory for input buffer
buffer = allocate( BUFSIZE * SIZEOF( Zstring )) ' <==========
If (buffer = 0) Then
Print "error"
End -1
EndIf
' Print prompt
print prompt;
' Read input from console
'------------------------------ problem zone ?---------------//
ReadConsoleA( input_handle, buffer, BUFSIZE, varptr(bytes_read),0 ) '
'------------------------------ problem zone ?---------------//
' Convert buffer to string
input_text = ltrim(*buffer) ' <==========
''input_text = str(buffer)
' Free memory
DeAllocate(buffer)
' Return input text
return input_text
End function
' Main program
dim as string myname
' Get user input
myname = InputBox( "Enter your name: " )
' Print input
Print ("Hello, "); Left(myname, Instr(myname, Chr(&h0D)) - 1); "!" ' <========== to stop before the carriage return in the myname string
sleep
End 0
But why make it complicated when you can make it simpler:
Function InputBox(prompt As String) As String
Dim As String input_text
Print prompt;
Input "", input_text
Return input_text
End Function
Dim As String myname
myname = InputBox("Enter your name: ")
Print "Hello, "; myname; "!"
Sleep
Thank you fxm for corrections and Lothar in general I'm interested in programming and what's behind it and I enjoy learning about it freebasic is an interesting and very good Basic language