|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
End Of Line (EOF) Problem
im having a great problem now..i want to read files like pictures, music...but when i read it like
Code:
Do Until EOF (iRead) Line Input #iRead, strString Loop it reads like half a line and then stops i have studied the files i read and found out that there is an EOF unicode character that makes the program stop reading it when it hits it. is there any way i can make it read until the real end of line. thanks in advance |
|
#2
|
||||
|
||||
|
you're trying to read media files into a string variable?
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#3
|
||||
|
||||
|
oops, yea ive never thought of that..well how can i read media files into something so i can replace some text in it
you see, i replace each small case letter into a number like (001)(002) means "b" so i want to do that to pictures and music so i can "encode" them..is there anyway i can do that thanks in advance ![]() |
|
#4
|
|||
|
|||
|
U should use binary model to read a media file..Because some files are made of binary elements..
This is a simple code: To write the file, open the file for binary access giving the number of bytes in the array as its record size. Use Put to write the whole array at once. Private Sub cmdWriteValues_Click() Dim file_name As String Dim file_length As Long Dim fnum As Integer Dim bytes() As Byte Dim txt As String Dim i As Integer Dim values As Variant Dim num_values As Integer ' Build the values array. values = Split(txtValues.Text, vbCrLf) For i = 0 To UBound(values) If Len(Trim$(values(i))) > 0 Then num_values = num_values + 1 ReDim Preserve bytes(1 To num_values) bytes(num_values) = values(i) End If Next i ' Delete any existing file. file_name = txtFile.Text On Error Resume Next Kill file_name On Error GoTo 0 ' Save the file. fnum = FreeFile Open file_name For Binary As #fnum Len = num_values Put #fnum, 1, bytes Close fnum ' Clear the results. txtValues.Text = "" End Sub To read the file, open the file for binary access its length as its record size. Use Get to read the whole array at once. Private Sub cmdReadValues_Click() Dim file_name As String Dim file_length As Long Dim fnum As Integer Dim bytes() As Byte Dim txt As String Dim i As Integer file_name = txtFile.Text file_length = FileLen(file_name) fnum = FreeFile ReDim bytes(1 To file_length) Open file_name For Binary As #fnum Len = file_length Get #fnum, 1, bytes Close fnum ' Display the results. For i = 1 To file_length txt = txt & Format$(bytes(i)) & vbCrLf Next i txtValues.Text = txt End Sub |
|
#5
|
|||
|
|||
|
But if u will display some media file content like music or image,u should use media player control or image control to do it!..
|
|
#6
|
||||
|
||||
|
alright i dont understand anything can u please explain it a piece by piece..since im a begginer in VB6 (ive been using VB.NET)
i dont seem to understand anything from the code Thanku |
|
#7
|
|||
|
|||
|
OK..If u will read a binary file's content..U must read the file from binary format to a byte array which store the content of the all file..
Let's begin at this simple code: To read the file, open the file for binary access its length as its record size. Use Get to read the whole array at once. Private Sub cmdReadValues_Click() Dim file_name As String'file path Dim file_length As Long'length of the file Dim fnum As Integer'filehandle number Dim bytes() As Byte'byte array Dim txt As String'a string to store the result Dim i As Integer 'set file_name file_name = txtFile.Text 'get length of the file file_length = FileLen(file_name) 'get filehandle for read the file in binary model fnum = FreeFile 'reset byte array to adapt the file length ReDim bytes(1 To file_length) 'Open file for binary model Open file_name For Binary As #fnum Len = file_length 'read the file content to byte array Get #fnum, 1, bytes 'close filehandle-close the file Close fnum ' Display the results. For i = 1 To file_length 'set the each member of byte array to string format,and add it to txt txt = txt & Format$(bytes(i)) & vbCrLf Next i 'set the txt to textbox for show the result txtValues.Text = txt End Sub |
|
#8
|
||||
|
||||
|
well cleverpig i dont know we could ever live without u
|
|
#9
|
||||
|
||||
|
when i try to write file in binary it in the underlined line which sais
Code:
ReDim Preserve bytes(1 To num_values)
bytes(num_values) = values(i)
End If
it tells me a type mismatch error please help ![]() |
|
#10
|
||||
|
||||
|
haha that was such a silly question...
i waas typing letters instead of binary ___ but i have a greater problem..is there any way i can code a certain picture for example so it cannot be read until it is decoded so i tryed replaced each "97" with "200" and each "100" with "201" snd it worked with a text file,,,but when i tryed to do that with a a very small picture (about 8KB) and when writing it came to this underlined line and said a "Overflow" Code:
'Make the values array
Values = Split(TheValues, vbCrLf)
For I = 0 To UBound(Values)
If Len(Trim$(Values(I))) > 0 Then
NumberValues = NumberValues + 1
ReDim Preserve Bytes(1 To NumberValues)
Bytes(NumberValues) = Values(I)
End If
Next I
i dont know why it does overflow please help me out i really need to finish this |
|
#11
|
|||
|
|||
|
Yes...This the reason that u won't use certain variable type for 2 variables "bytes and values"..The values is a array that made by a string member,and the bytes is a array that made by a byte member!..when u wanna to assign a byte array member from a string array member,the 2 variables are different by store room in the memory..So the error happened!If u wanna implement this assignment,u will use forced type transfer by CByte() function...
|
|
#12
|
||||
|
||||
|
ok uve got me all confused up cha know
how do u use this CByte function.. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > End Of Line (EOF) Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|