Results 1 to 8 of 8

Thread: VB's screwing around...

  1. #1

    Thread Starter
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221

    Angry 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

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    paste some code?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    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
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  4. #4

    Thread Starter
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    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

  5. #5

    Thread Starter
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    VB Code:
    1. Public Sub PutString(ByVal FileHandle As Integer, ByVal Text As String)
    2. On Error Resume Next
    3. Dim TextArray() As Byte, TextLength As Long
    4.     Err.Clear
    5.     Text = Text
    6.     If Len(Text) <= 0 Then
    7.         TextLength = 0
    8.         Put #FileHandle, , TextLength
    9.     Else
    10.         TextLength = Len(Text)
    11.         Put #FileHandle, , TextLength
    12.         MsgBox "Saved Text Length: " + CStr(TextLength) + vbCrLf + CStr(Err.Description)
    13.         TextArray = StrConv(Text, vbFromUnicode)
    14.         MsgBox "Converted Text" + vbCrLf + CStr(Err.Description)
    15.         Put #FileHandle, , TextArray
    16.         MsgBox "Saved Text: " + Text + vbCrLf + CStr(Err.Description)
    17.     End If
    18.     Err.Clear
    19. 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

  6. #6

    Thread Starter
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    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

  7. #7
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    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
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  8. #8

    Thread Starter
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    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
  •  



Click Here to Expand Forum to Full Width