Dim InpFile As String Dim OutFile As String Dim hFile As Long Dim fileStruct As OFSTRUCT Dim FSize As Long Dim BytesRead As Long Dim BytesWritten As Long Dim hMem As Long Dim lpMem As Long Dim r As Long Dim bts As Byte InpFile = "input.txt" OutFile = "OUTPUT.txt" 'Get the size of the file to be read FSize = FileLen(InpFile) If FSize > 0 Then 'Allocate a block of memory equal to the size of the input file. 'hMem = GlobalAlloc(GMEM_ZEROINIT, FSize) hMem = GlobalAlloc(GPTR, FSize) If hMem <> 0 Then lpMem = GlobalLock(hMem) 'Read the file into memory hFile = OpenFile(InpFile, fileStruct, OF_READ Or _ OF_SHARE_DENY_NONE) BytesRead = hread(hFile, ByVal lpMem, FSize) MsgBox Format(BytesRead) & " bytes read into memory" r = lclose(hFile) 'Write the file back to disk to verify the file was 'read correctly hFile = OpenFile(OutFile, fileStruct, OF_CREATE Or _ OF_WRITE Or OF_SHARE_DENY_NONE) BytesWritten = hwrite(hFile, ByVal lpMem, FSize) MsgBox Format(BytesWritten) & " bytes written to output file" r = lclose(hFile) 'Free resources r = GlobalUnlock(hMem) r = GlobalFree(hMem) Else MsgBox "Not enough memory to store file" End If Else MsgBox "Input file is zero bytes in length" End If End
|Question about INSTR - need to extract data MS ACCESS query||6||53|
|passing a value with stream reader AFTER a ";"||3||58|
|Help with retrieving partial value from a column using VB.NET||4||41|
|VB 6 error 5 in windows 10 but not in XP||7||42|
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
19 Experts available now in Live!