The FSO isn't exactly garbage, but it has so many warts that it almost may as well be. Most of the time you should seek out alternatives. It was only designed to handle text stream files, and was really designed for scripting. It is too bad we didn't get a more practical alternative built into VB6, but .Net came along and killed that for us and we never got a legitimate VB7.
So instead you need to use API calls. Appropriate wrappers for these can be found in the CodeBank, but I presume you are fighting both your programming skills and a language barrier, and that can make searching difficult.
Here's an example based on a couple of things from the CodeBank:
Most of the code above is calling the Unicode MessageBox function. Here is a stripped down version that might be clearer to read:Code:Option Explicit Private Const WIN32_NULL As Long = 0 Private Declare Function MessageBox Lib "user32" Alias "MessageBoxW" ( _ ByVal hWnd As Long, _ ByVal lpText As Long, _ ByVal lpCaption As Long, _ ByVal uType As VbMsgBoxStyle) As VbMsgBoxResult Private Sub Main() Dim HBF As HugeBinaryFile Dim FileSize As Currency Dim FileBytes() As Byte With New CommonDlgsW .DialogTitle = "Open a file" .Flags = cdlOFNFileMustExist _ Or cdlOFNPathMustExist _ Or cdlOFNExplorer _ Or cdlOFNHideReadOnly _ Or cdlOFNLongNames _ Or cdlOFNShareAware .Filter = "All files (*.*)|*.*" If .ShowOpen(WIN32_NULL) Then Set HBF = New HugeBinaryFile On Error Resume Next HBF.OpenFile .FileName, FILE_SHARE_ALL If Err Then On Error GoTo 0 MessageBox WIN32_NULL, _ StrPtr("Failed to open file:" _ & vbNewLine & vbNewLine _ & .FileName), _ StrPtr("Open failed"), _ vbExclamation Else On Error GoTo 0 FileSize = HBF.LOF ReDim FileBytes(FileSize - 1) If HBF.ReadBytes(FileBytes) <> FileSize Then HBF.CloseFile MessageBox WIN32_NULL, _ StrPtr("Failed to read full file:" _ & vbNewLine & vbNewLine _ & .FileName), _ StrPtr("Failed to read file"), _ vbExclamation Else HBF.CloseFile .DialogTitle = "File to write to" .Flags = cdlOFNPathMustExist _ Or cdlOFNExplorer _ Or cdlOFNHideReadOnly _ Or cdlOFNLongNames _ Or cdlOFNShareAware If .ShowSave(WIN32_NULL) Then On Error Resume Next HBF.OpenFile .FileName, FILE_SHARE_EXCLUSIVE If Err Then On Error GoTo 0 MessageBox WIN32_NULL, _ StrPtr("Failed to create new file:" _ & vbNewLine & vbNewLine _ & .FileName), _ StrPtr("Failed to create file"), _ vbExclamation Else On Error GoTo 0 If HBF.WriteBytes(FileBytes) <> FileSize Then HBF.CloseFile MessageBox WIN32_NULL, _ StrPtr("Failed to write full file:" _ & vbNewLine & vbNewLine _ & .FileName), _ StrPtr("Failed to write file"), _ vbExclamation Else HBF.CloseFile MessageBox WIN32_NULL, _ StrPtr("Success. New file written:" _ & vbNewLine & vbNewLine _ & .FileName), _ StrPtr("Success"), _ vbInformation End If End If Else MessageBox WIN32_NULL, _ StrPtr("Canceled save"), _ StrPtr("Canceled"), _ vbInformation End If End If End If Else MessageBox WIN32_NULL, _ StrPtr("Canceled open"), _ StrPtr("Canceled"), _ vbInformation End If End With End Sub
But you really need to hire a programmer if this stuff is important to you. Otherwise you might consider moving to VB.Net where a great deal of it is already done for you. It is very late to be trying to learn VB6 today.Code:Option Explicit Private Const WIN32_NULL As Long = 0 Private Sub Main() Dim HBF As HugeBinaryFile Dim FileSize As Currency Dim FileBytes() As Byte With New CommonDlgsW .DialogTitle = "Open a file" .Flags = cdlOFNFileMustExist _ Or cdlOFNPathMustExist _ Or cdlOFNExplorer _ Or cdlOFNHideReadOnly _ Or cdlOFNLongNames _ Or cdlOFNShareAware .Filter = "All files (*.*)|*.*" If .ShowOpen(WIN32_NULL) Then Set HBF = New HugeBinaryFile On Error Resume Next HBF.OpenFile .FileName, FILE_SHARE_ALL If Err Then On Error GoTo 0 MsgBox "Failed" Else On Error GoTo 0 FileSize = HBF.LOF ReDim FileBytes(FileSize - 1) HBF.ReadBytes FileBytes HBF.CloseFile .DialogTitle = "File to write to" .Flags = cdlOFNPathMustExist _ Or cdlOFNExplorer _ Or cdlOFNHideReadOnly _ Or cdlOFNLongNames _ Or cdlOFNShareAware If .ShowSave(WIN32_NULL) Then On Error Resume Next HBF.OpenFile .FileName, FILE_SHARE_EXCLUSIVE If Err Then On Error GoTo 0 MsgBox "Failed" Else On Error GoTo 0 HBF.WriteBytes FileBytes HBF.CloseFile MsgBox "Success!" End If Else MsgBox "Canceled" End If End If Else MsgBox "Canceled" End If End With End Sub




Reply With Quote
