-
Mar 6th, 2004, 06:44 AM
#1
Thread Starter
Supreme User
Add bytes to any file
This came from one of my older projects, so take note in the code of the required controls and name suffixes
VB Code:
Private Sub lblAdd_Click()
Dim lprog As Long
If txtFile.Text = "" Then
frmMessage!lblMessage.Caption = "Please select a file first to add required bytes to it."
frmMessage.Show vbModal
Else
lblPercent.Visible = True
lblStatus2.ForeColor = &HC0&
lblStatus2.Caption = "Working"
lblBytes3.Caption = "N/A"
lblFile3.Caption = "N/A"
lblTime2.Caption = "N/A"
If txtFile.Text <> "" And txtBytes.Text > 0 Then
fsiz = ShowFileSize(txtFile.Text)
prgMain.Value = 0
prgMain.Max = txtBytes.Text
prgMain.Visible = True
DoEvents
Me.Enabled = False
Open txtFile.Text For Binary As #1
For A = 1 To txtBytes.Text
Put #1, fsiz - 1 + A, 0
prgMain.Value = A
prgMain.Refresh
lprog = (A / txtBytes) * 100
lblPercent = lprog & "%"
lblPercent.Refresh
Next
Close
End If
prgMain.Visible = False
prgMain.Value = 0
lblPercent.Visible = False
lblStatus2.ForeColor = &H8000&
lblStatus2.Caption = "Ready"
lblBytes3.Caption = txtBytes.Text
lblFile3.Caption = Replace(txtFile.Text, "&", "&&")
lblTime2.Caption = Now
DoEvents
Me.Enabled = True
End If
End Sub
Function ShowFileSize(file)
Dim fs, f, S
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(file)
ShowFileSize = f.Size
's = UCase(f.Name) & " uses " & f.Size & " bytes."
'MsgBox s, 0, "Folder Size Info"
End Function
'94208
Private Sub lblFileBrowse_Click()
dlgFile.ShowOpen
txtFile.Text = dlgFile.FileName
End Sub
-
Mar 12th, 2004, 04:05 AM
#2
Bad Wiggles, you could use:
VB Code:
Public Sub AmendFile(ByVal pstrFilename As String, ByRef pbytData() As Byte)
Dim intFile As Integer
On Error GoTo ErrHandler
'if required add code here to see if file exists
intFile = FreeFile
Open pstrFilename For Binary Access Write As #intFile
Put #intFile, LOF(intFile) + 1, pbytData()
Close #intFile
Exit Sub
ErrHandler:
Close #intFile
Err.Raise Err.Number, Err.Source, Err.Description
End Sub
Woka
-
Mar 12th, 2004, 04:18 AM
#3
Wiggles, you can even take this one step further and add the code to a class:
VB Code:
Option Explicit
Public Event Progress(ByVal BytesWritten As Long, ByVal TotalBytes As Long)
Public Sub AmendFile(ByVal pstrFilename As String, ByRef pbytData() As Byte)
Dim intFile As Integer
Dim lngFileLen As Long
Dim lngByteLen As Long
Dim lngIndex As Long
Dim lngLBound As Long
Dim lngUBound As Long
On Error GoTo ErrHandler
'if required add code here to see if file exists
intFile = FreeFile
Open pstrFilename For Binary Access Write As #intFile
lngFileLen = LOF(intFile)
lngLBound = LBound(pbytData)
lngUBound = UBound(pbytData)
lngByteLen = lngUBound - lngLBound + 1
For lngIndex = 1 To lngByteLen
Put #intFile, lngFileLen + lngIndex, pbytData(lngLBound + lngIndex - 1)
RaiseEvent Progress(lngIndex, lngByteLen)
Next lngIndex
Close #intFile
Exit Sub
ErrHandler:
Close #intFile
Err.Raise Err.Number, Err.Source, Err.Description
End Sub
This will raise an event to your form so that you can display the progress of the writting if you wish.
Woof
-
Mar 12th, 2004, 12:44 PM
#4
Thread Starter
Supreme User
-
Apr 20th, 2005, 11:30 AM
#5
Thread Starter
Supreme User
Re: Add bytes to any file
I had this converted for Delphi, how do you do it again, in DELPHI?
Thanks
-
Apr 23rd, 2005, 08:16 PM
#6
Re: Add bytes to any file
Originally Posted by Madboy
Anyone, i cant find my old threads
Do you mean this: http://www.vbforums.com/showthread.php?t=292654
-
Apr 24th, 2005, 07:29 AM
#7
Thread Starter
Supreme User
Re: Add bytes to any file
Nope, thats the address book one
thanks, still cant find it though
-
Apr 24th, 2005, 09:34 AM
#8
Thread Starter
Supreme User
Re: Add bytes to any file
Still no luck,
and why were you posting at 2am in the morning, you insomniac
-
Apr 7th, 2017, 02:10 AM
#9
Re: Add bytes to any file
Can the added bytes have a use ?
Could I use them to Tag files, so that a user can filter a list of files based on the Tags previously added ?
-
Apr 7th, 2017, 10:15 AM
#10
Re: Add bytes to any file
This thread is probably not the right place for either of the last two posts, but I don't understand them. The original was started in 04, then there was some activity a year later, then that one post seven years later in 2012, and now this, five years later. The original poster hasn't been around these parts in over a decade, and the others for almost as long. If you have a question to ask, ask it in the right forum, adding to a CodeBank thread this old makes no sense at all. You almost certainly won't get a reply from the original poster.
My usual boring signature: Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|