Announcement

Collapse
No announcement yet.

Garbage from DISPLAY OPENFILE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Garbage from DISPLAY OPENFILE

    This does not get a filename on the first pass, on subsequent calls, it does return a filename:
    Code:
    FUNCTION GetFileName(FileFilter AS STRING, FilePath AS STRING, _
        FileTitle AS STRING, OpenMode AS LONG) AS STRING
    DIM OFName AS OPENFILENAME, FileName AS STRING, myOpen AS LONG
    DIM strExt AS STRING, strName AS STRING, strPath AS STRING, strFilter AS STRING
        strExt = PARSE$(FileFilter, "|", 2)
        strExt = PARSE$(strExt, ".", 2)
        strExt = PARSE$(strExt, ";", 1) & CHR$(0)
        strName = CHR$(0)
        strPAth = CHR$(0)
        IF FilePath <> "" THEN
            strPath = FilePath & CHR$(0)
            IF RIGHT$(FilePath, 1) <> "\" THEN
                strName = PARSE$(FilePath, "\", PARSECOUNT(FilePath))
                REPLACE strName WITH "" IN strPath
                strName = PARSE$(strName, ".", 1) & CHR$(0)
            END IF
        END IF
        strFilter = FileFilter & "||"
        REPLACE "|" WITH CHR$(0) IN strFilter
        myOpen = OpenMode OR %OFN_ENABLESIZING
        FileName = STRING$(%max_path, " ")
        DISPLAY OPENFILE hwndWinMain,,, FileTitle, strPath, strFilter, strName, _
            strExt, myOpen TO FileName
        #DEBUG PRINT FileName
        GetFileName = FileName
    END FUNCTION
    FileFilter is a | delimited string from some globals set up to restrict selection to one of the filetypes I'm interested in opening.
    Ex: $TextFiles = "Text Files (*.txt)|*.txt|Source Files (*.src)|*.src"

    The first time it's called, I get garbage like:
    <00><00>À<00><00><00><13><00><01>m FH6À<00>P6À<00>X<00><00><00>˜6À<00>$ô<12><00>Páï|„ö<12><00>d~û
    from the procedure.

    P.S. The additional & CHR$(0) tacked onto the various function strings is a late addition in attempting to determine what was wrong, they were not present originally, and the function was still returning garbage on first call.
    Furcadia, an interesting online MMORPG in which you can create and program your own content.

  • #2
    I thought your problem might be....
    Code:
    strName = PARSE$(strName, ".", 1) & CHR$(0)
    .. when strname does NOT contain a "."

    So, I checked the help file (9.0.0) to see what is supposed to happen when the first argument does not contain the named delimiter.

    Oops....
    PARSE$ function
    Purpose
    Return a delimited field from a string expression.

    Syntax
    a$ = PARSE$(string_expr [, {[ANY] string_delimiter | BINARY}], index&)

    Remarks
    PARSE$ uses the following parameters:

    string_expr
    The to parse. If string_expr is empty (a null string) or contains no delimiter character(s), the string is considered to contain exactly one field. In this case, PARSECOUNT will return the value 1.
    .. the help file tells me what PARSECOUNT returns, not what PARSE$ returns.

    Reported.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      However, when called:
      FileFilter = $TextFiles
      FilePath = ""
      FileTitle = "Open a Text File"
      OpenMode %OFN_FILEMUSTEXIST
      The function fails on first call.
      Furcadia, an interesting online MMORPG in which you can create and program your own content.

      Comment


      • #4
        I am going to add to this:

        After frequent debug runs, it does not garbage every filename on first time, just seems to dislike certain files in the folder, other files of the same type get the filename right the first time every time, the ones which return garbage get garbage the first time every time.
        Furcadia, an interesting online MMORPG in which you can create and program your own content.

        Comment


        • #5
          Originally posted by Michael Mattias View Post
          Oops....

          .. the help file tells me what PARSECOUNT returns, not what PARSE$ returns.

          MCM
          Dunno which help file you're looking at, ...
          Originally posted by PBWin Help: PARSE$ function
          index&
          An variable or expression that specifies the delimited field number to return. The first field is 1, and so on up to the maximum number of fields contained in string_expr, which may be determined with the PARSECOUNT function. If index& is negative, string_expr is parsed from right to left. In this case, index& = -1 returns the last field in string_expr, -2 returns the second to last, etc. If index& evaluates to zero, or is outside of the actual field count, an empty string is returned.

          Example
          a$ = PARSE$("one,two,three", 2) ' returns "two"
          a$ = PARSE$("one;two,three", 2) ' returns "three"
          a$ = PARSE$("one",2) ' returns ""
          a$ = PARSE$("xyz",1) ' returns "xyz"
          a$ = PARSE$("xx1x","x",3) ' returns "1"
          a$ = PARSE$("1;2,3", ANY ",;", 2) ' returns "2"
          Furcadia, an interesting online MMORPG in which you can create and program your own content.

          Comment


          • #6
            >Dunno which help file you're looking at, ...

            PB/WIN 9.0.0, which is how I reported the problem.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment

            Working...
            X