Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

ReadFromStdInput - Read from standard input stream

Total Hit ( 3452)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) _
  As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, _
  lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, _
  lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long

Private Const STD_INPUT_HANDLE = -10&

' read a number of chars from standard input channel
'
' if NumBytes < 0 then it reads all the bytes
' from the standard input
'
' NOTE: this routine works only in compiled applications

Function ReadFromStdInput(Optional ByVal NumBytes As Long = -1) As String
  Dim hStdIn As Long
  Dim ret As Long
  Dim buffer As String
  Dim bytesRead As Long
  
  ' get the handle of standard input
  hStdIn = GetStdHandle(STD_INPUT_HANDLE)
  
  ' prepare receiving buffer
  buffer = Space$(1024)
  
  Do
    ' read from standard input
    ret = ReadFile(hStdIn, ByVal buffer, Len(buffer), bytesRead, ByVal 0&)
  
    ' deal with errors
    If ret = 0 Then
      Err.Raise 1001, , "Unable to read from standard input"
    End If
    
    ' append to result built so far
    ReadFromStdInput = ReadFromStdInput & Left$(buffer, bytesRead)
    
    ' continue to read if there are more chars
  Loop Until bytesRead < Len(buffer)
    
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.