Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

binary file write in VB6

2 views
Skip to first unread message

Elliot Marks

unread,
Jun 22, 2004, 8:31:44 PM6/22/04
to
I want to output this data to text and binary files. The binary
file contains the garbage you would expect to see if you try to
read it with a text editor, but below that the output appears as
text as it also appears in the text file. It's been a long time
since I've written any VB code. What am I doing wrong? (The
default value of modulus is 255.)


Private Sub cmdStart_Click()
'samples an image at intervals depending on the settings
'of range (number of rows and columns) and stepval (interval
'between pixels) and generates a prnd number by performing
'modular division on the color value of the pixel

Dim nbin As Byte
Dim numbers As String
Dim row As Integer
Dim col As Integer
Dim n As Integer
Dim colcount As Integer
Dim range As Integer
Dim stepval As Integer
Dim modulus As Integer

lncount = 0
numbers = ""
range = Val(txtRange.Text)
stepval = Val(txtStep.Text)
modulus = Val(txtModulus.Text)

'send data to a text file and a binary file
Open "C:\windows\desktop\data\random.txt" For Output As #1
Open "C:\windows\desktop\data\rnd.dat" For Binary Access Write As #2

For row = 100 To range Step stepval
For col = 100 To range Step stepval
n = pboxImage.Point(row, col) Mod modulus
nbin = pboxImage.Point(row, col) Mod modulus
numbers = numbers & Str(pboxImage.Point(row, col)) & vbCrLf
If n > 0 Then
Print #1, n;
Put #2, , nbin
colcount = colcount + 1
If colcount Mod 10 = 0 Then Print #1, vbCrLf
End If
Next col
Next row
Close #1
Close #2

txtNumbers.Text = numbers
End Sub

ema...@email.net

unread,
Jun 22, 2004, 8:33:00 PM6/22/04
to
This message was cancelled from within Mozilla.

Elliot Marks

unread,
Jun 22, 2004, 8:38:23 PM6/22/04
to
I want to output this data to text and binary files. The binary
file contains the garbage I would expect to see if I try to read
it with a text editor, but below that the output appears as text.
It's been a long time since I've written any VB code. What am I
doing wrong? (The default value of modulus is 255.)


Private Sub cmdStart_Click()
'samples an image at intervals depending on the settings
'of range (number of rows and columns) and stepval (interval
'between pixels) and generates a prnd number by performing
'modular division on the color value of the pixel

Dim nbin As Byte
Dim numbers As String
Dim row As Integer
Dim col As Integer
Dim n As Integer
Dim colcount As Integer
Dim range As Integer
Dim stepval As Integer
Dim modulus As Integer

colcount = 0


numbers = ""
range = Val(txtRange.Text)
stepval = Val(txtStep.Text)
modulus = Val(txtModulus.Text)

'send data to a text file and a binary file

Open "C:\windows\desktop\data\otpad.txt" For Output As #1

Bob Butler

unread,
Jun 23, 2004, 9:43:44 AM6/23/04
to
Elliot Marks <ema...@email.net> wrote in message news:<40D8CF85...@email.net>...

> I want to output this data to text and binary files. The binary
> file contains the garbage you would expect to see if you try to
> read it with a text editor, but below that the output appears as
> text as it also appears in the text file.

is it possible that the rnd.dat file already exists with the text you
are seeing? If you aren't writing enough bytes to overwrite old data
then it will still be there. try adding

on error resume next
kill "C:\windows\desktop\data\rnd.dat"
on error goto 0

before you open the binary file

0 new messages