|
-
Feb 28th, 2002, 05:38 AM
#1
Thread Starter
Addicted Member
VB's screwing around...
This is REALLY pissing me off, I've been trying to fix it for days.
Based on some unknown factor (I still have absolutely NO clue what causes this), sometimes trying to save data to one of my files will cause the file handle to become invalid. From then on, all file operations on that handle return 'bad file name or number'. I never call the Close statement (I searched through my entire source code and added message boxes to trace every close), and I traced all my values... all the data I'm saving seems to be fine.
Also, this only happens when my app is compiled. If i'm in the IDE, it doesn't happen.
Usually the app is compiled as an ActiveX EXE, and then the client hands it some text and tells the app to save the text. The app then measures the string, saves a 4-byte long containing the length (this is where the error occurs... >_<) and then the string itself.
The error that occurs is... get this, Bad File Name or Number (52).
Anyone have ANY idea what could be causing this?
"1 4m 4 1337 #4xz0r!'
Janus
-
Feb 28th, 2002, 05:56 AM
#2
Bouncy Member
-
Feb 28th, 2002, 06:07 AM
#3
Frenzied Member
Use the Freefile command when creating file handles....
Code:
Dim fNum As Integer
fNum = FreeFile
Open "c:\thing.txt" For Output As fNum
Close fnum
Hope this helps,
Duncan
-
Feb 28th, 2002, 06:13 PM
#4
Thread Starter
Addicted Member
The problem is not getting a valid file handle, Duncan. Did you read my post? The file handle I have becomes invalid.
Anyway, I'm already using FreeFile.
"1 4m 4 1337 #4xz0r!'
Janus
-
Feb 28th, 2002, 06:15 PM
#5
Thread Starter
Addicted Member
VB Code:
Public Sub PutString(ByVal FileHandle As Integer, ByVal Text As String)
On Error Resume Next
Dim TextArray() As Byte, TextLength As Long
Err.Clear
Text = Text
If Len(Text) <= 0 Then
TextLength = 0
Put #FileHandle, , TextLength
Else
TextLength = Len(Text)
Put #FileHandle, , TextLength
MsgBox "Saved Text Length: " + CStr(TextLength) + vbCrLf + CStr(Err.Description)
TextArray = StrConv(Text, vbFromUnicode)
MsgBox "Converted Text" + vbCrLf + CStr(Err.Description)
Put #FileHandle, , TextArray
MsgBox "Saved Text: " + Text + vbCrLf + CStr(Err.Description)
End If
Err.Clear
End Sub
That's the function, the error occurs at the Put #FileHandle, , TextLength line.
Also, i successfully call this function many times before it stops working, and it seems to only be certain strings that make it stop working. But I can't find any difference between the strings that work and the ones that don't.
"1 4m 4 1337 #4xz0r!'
Janus
-
Mar 1st, 2002, 02:42 AM
#6
Thread Starter
Addicted Member
I called MS tech support and they don't have a clue either, so far...
It still doesn't work, I've tried using a UDT to save the string, copying it to the clipboard and saving from the clipboard, and a number of other options. No matter what I do, i can't save this string...
"1 4m 4 1337 #4xz0r!'
Janus
-
Mar 1st, 2002, 04:30 AM
#7
Bouncy Member
re: ...The app then measures the string, saves a 4-byte long containing the length (this is where the error occurs... >_< ) and then the string itself...
how big is this string???
might have something to do with it
-
Mar 1st, 2002, 04:42 AM
#8
Thread Starter
Addicted Member
anywhere from 8 to 600 bytes.
Nevermind guys, after about 2 hours of code hacking I have permanently fixed this problem. 
Turned out that having 3 different processes all creating objects caused problems :P
"1 4m 4 1337 #4xz0r!'
Janus
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
|