Announcement

Collapse
No announcement yet.

Problem with Replace-command

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

  • #21
    Fred,
    I 3rd the #REGISTER NONE.
    I always use it after having intermitant GPF's that I could not trace.
    While it may still be circumstantial using #REGISTER NONE fixed them.

    James


    ------------------

    Comment


    • #22
      Fred --
      If you will look more accuracy to Forum's post, you will find a lot advantures w/o Register None.
      1) Exist such commands as Disksize which destroys registers.
      2) Be very careful with Byte, incl. UDT and so on.

      If you worry about performance better to declare general REGISTER NONE and inside functions to use REGISTER i, j ... statements.Really a speed with Register None decrease in 2 times only (approx.)

      Summary again: REGISTER NONE, NONE, NONE ...

      [This message has been edited by Semen Matusovski (edited April 11, 2000).]

      Comment


      • #23
        Semen, James
        Dont get me wrong, I have taken your advice ad notam,
        I think that your advice is correct,
        only a few weeks ago, I experinced the 'mysterious works of #register none".
        I got a statment too complex errors and Lance's simple
        advice to use #register none fixed it


        ------------------
        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se

        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se

        Comment


        • #24
          I think you all agree with me that this is a serious problem.
          If an instruction like Replace is allowed to return false result
          without giving the programmer opportunity to detect it, well then
          atleast me, is in deep trouble.
          I just realised that I have heavily used rutines that use Replace any without any possibility to verify the result.
          I have conversionroutines like:
          XLATEAsciiToEbcdic, XLATEAnsiToAscii etc, that takes a file
          read it in blocks and replaces characters in that block and write
          it back to disk.
          This routines cannot detect this problem.
          This have already happened, I just did not see it...
          We have had files on an AS400 producing strange output..
          This nigth will be devoted to damage control..
          Have to run away now...

          ------------------
          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Comment


          • #25
            Fred;

            Before you start believing that the problem is with the compilers code, you need to try to write your own Replace function to see if the problem disappears (on NT).

            It is not hard to emulate the replace function with your own code. It may not be as fast , but it would allow you to prove to yourself (and others) that there is a real problem with the Replace function or whether the problem lies elsewhere.

            If the code works fine on Win95, then likely it is related to OS DLLs, rather than being a problem with the Replace function.

            What is needed now is more accurate data about the problem. Test the exact same code (not the EXE version if it is OK) that is suspect on multiple PCs and post the results. Does it work OK (in DLL form as you mentioned) on Win 95, 98 NT ?

            Will it work OK on some services packs for NT, but not another ?

            How much Ram is on each computer ?

            What other apps are running at the same time ?

            Have you added "Test" code to track when errors occur to see if any pattern appears ?




            ------------------
            Chris Boss
            Computer Workshop
            Developer of "EZGUI"
            http://cwsof.com
            http://twitter.com/EZGUIProGuy

            Comment


            • #26
              Chris, I don't believe the compiler is responsible for the failing
              Replace-instruction I know that.
              If you do a simple test like this:
              Code:
              C$=String$(15000,"A")
              A$="A":B$="B"
              Replace Any A$ with B$ in C$
              and your C$-string show you 9500 "B" followed by 5500 "A"
              you don't have to do any testing, to see if the instruction failed to do its job.
              Just looking at the resulting C$-string proves it did not.
              --
              My published function shows that there is a validity-check of the output
              from Replace-instruction.
              Whenever this validity-check fails, and before doing anything else,
              the failing buffer (glbInBuff) is saved to a local file,
              File Position,Buffer Size and Buffer position is saved in the same file
              After that the function bails out and returns a failure code.
              This gives me the hard data I need to examine the reason of failure
              You probably realize that this behavior is not intended for checking
              the replace-instruction. It is there to assist my customers to find and correct
              problems in their data files.


              ------------------
              Fred
              mailto:[email protected][email protected]</A>
              http://www.oxenby.se

              Fred
              mailto:[email protected][email protected]</A>
              http://www.oxenby.se

              Comment


              • #27
                Fred --

                I appreciate the way you feel -- I've been there many times -- and I am absolutely not saying "there is no bug in REPLACE ANY", but please consider the following, and accept it in the spirit in which it is offered. I really am trying to help.

                > you don't have to do any testing, to see if
                > the instruction failed to do its job.

                Please correct me if I'm wrong, but it appears that, at least in the code that you posted, you are not testing the glbInBuff string immediately after the REPLACE ANY which you believe is failing. Right after the REPLACE ANY you have this line...

                glbInBuff = Tmp$ + glbInBuff

                ...which, at least in theory, could produce a "mixed result" string of the type that you are describing. For example, if something (like a memory corruption) was going wrong and the gIn.Charset did not have the value that you expect, and as a result the REPLACE ANY did not even execute, you could see a glbInBuff string that was partially converted (Tmp$) and partially not (the glbInBuff string that did not get REPLACEd as expected). Without seeing more code I can't be certain, but it looks that way to me.

                Fred, clearly something is going wrong with your program. When you run the exact same program twice with exactly the same data and get different results, something is obviously not right. But based on my own experience with problems like this I'm not convinced (as you seem to be) that REPLACE ANY is at fault. It is a truism that "if you think you know the answer ahead of time, that is the answer that you will find", and I'd like to encourage you to perform additional tests.

                Any number of different memory-corruption mechanisms could, at least in theory, cause the type of behavior you are describing. Maybe the string is being REPLACEd correctly but is being corrupted later. Maybe a numeric variable like gIn.Charset is being corrupted. Maybe... who knows?

                Please don't get upset with me for saying this, but you seem to dismiss ideas like ERR/ERRAPI/GetlastError, writing your own REPLACE function, and #REGISTER NONE as "not worth trying", and that can be frustrating for those of us that try to offer help on this BBS. And please don't get upset with us for not simply agreeing with you that is a bug in the compiler.

                Also, it would really help if you could post a complete example that fails, and let a variety of people test it on a variety of NT4 systems. Maybe that one customer site is running a certain NT Service Pack, or has a network-wide problem of some kind, or...?

                I doubt that you'll find anybody on this BBS who is 100% sure that any given PowerBASIC function is bug free. But you will find many, many, many people who have been convinced that they'd found a compiler bug, only to slap their forehead later. That being said, once in a while people DO find new compiler bugs, and most of us are open to that possibility, but we tend to "play the odds" and place our bets on the more common cause of problem, code bugs.

                -- Eric


                ------------------
                Perfect Sync: Perfect Sync Development Tools
                Email: mailto:[email protected][email protected]</A>

                "Not my circus, not my monkeys."

                Comment


                • #28
                  Eric,
                  You have not seen the word "B?G" anywhere in my posting.

                  And Yes, unfortunately I have made up my mind about Replace-command
                  But I am not rejecting #Register None, ErrApi etc.
                  I answered the question if I used them. And I told the truth.I did not use them.
                  I have tried ErrApi. It returns zero, which I interpret as 'no problem detected'
                  or 'not applicable in this situation.'
                  My initial question was this:
                  I need a very quick sulotion to this problem.
                  Can someone help?
                  Can I prevent context-switching around the replace-command?
                  I think we have to draw a very sharp line in the discussion.
                  Above the line the Question is:Is Replace producing false result
                  Below the line we can always discuss:What triggers Replace to produce false result
                  ABOVE THE LINE:
                  If you have one page of text in German language.
                  You ask a trusted person (Hans) to translate it into English.
                  When you get the page back from Hans,
                  You take another page,that already is in English language,
                  and put that page in front of Hans page.
                  Later when you read it, on page two (witch Hans has translated),
                  you find the last paragraph still to be in German language
                  What Question do You ask yourself ?
                  1)Yee, I have known Hans for very long, and he has (well almost) never failed me,
                  Perhaps if I put the fist side upside down, the last paragraph will be in English too?
                  2)Yee, something disturbed Hans, perhaps I should lock the doors around him while
                  he is working?
                  BELOW THE LINE
                  1) I think it was the new girl in the neighborhood that passed by Hans window.
                  I will ask her to move somewhere else, so she is not disturbing Hans
                  2) etc...
                  '--
                  In my humble opinion there are no question about it:
                  Running my program on WinNt4:
                  Replace is sporadic producing false result.

                  Running same program on same machine with Win98SE installed:
                  Replace is doing its work correctly.
                  '--
                  I will never be able to dictate what operating system my customer will use in the future,
                  and if I have to abandon the 'Replace-instruction' and replace it with something else,
                  this rewrite of code will be of such magnitude, that my decision to use 'Powerbasic' will be
                  loudly questioned.
                  If I have to verify every Replace-instruction the impact on speed would put me out of
                  buissnes in no time at all.
                  '--
                  In my humble opinion, no external program, no network congestion, may never interfere
                  with a single instruction like Replace, and cause it to silently produce false result.
                  '--


                  ------------------
                  Fred
                  mailto:[email protected][email protected]</A>
                  http://www.oxenby.se

                  Fred
                  mailto:mai[email protected][email protected]</A>
                  http://www.oxenby.se

                  Comment


                  • #29
                    Hello Fred, is the problem arising with ANY specific service pack on NT4?

                    There have been bugs before with the OLE dll's. I don't do service packs unless
                    I absolutely need them.



                    [This message has been edited by Ron Pierce (edited April 12, 2000).]

                    Comment


                    • #30
                      Fred --

                      > You have not seen the word "B?G" anywhere in my posting.

                      Among other things you said "I don't believe the compiler is responsible for the failing Replace-instruction I know that. But let's not argue semantics, let's try to fix your problem...

                      > I will never be able to dictate what operating system my
                      > customer will use in the future

                      I can't tell my customers "you must use version X of Windows" either, but I can -- and do -- tell them things like "Windows NT4 Service Pack X contains a serious bug that is known to cause intermittent problems in our programs". If they argue with me, and they insist that all of their other programs are working fine, I say something like "Why do you think Service Pack 2 exists? Because Service Pack 1 was not perfect. And neither is the most current Service Pack, and the next one won't be perfect either."

                      I just re-read this entire thread looking for clues, and you said this...

                      > This code does not work in NT4 SP6a

                      Service Pack 6 has a reputation of "creating more problems that it solved" so I'd be very suspicious. And SP6 is recent enough that most people have not installed it yet. I have not, have you? How about the customers where your program is working properly. To lurkers: Is there anybody out there who has installed SP6a that would volunteer to run a test program for Fred?

                      I am particularly suspicious of Windows because of what you said about the apparent correlation between external programs and your program's problems.

                      Finally, I would like to modify your "one page of translated text" analogy. It seems to me that 15000 bytes is more like a stack of ten pages. So I would say "I gave Hans a stack of ten pages to translate. When he is done, he gives them to Gretta (the code between the REPLACE and the error-detection code) and she gives them to me. Once in a while the last page is not translated."

                      So who do you mistrust: Hans (the compiler) or Gretta (the other source code)?

                      Or maybe it's that mischief-maker from Redmond, Bill. He seems to enjoy appearing unexpectedly and scrambing other people's work!

                      -- Eric



                      ------------------
                      Perfect Sync: Perfect Sync Development Tools
                      Email: mailto:[email protected][email protected]</A>

                      "Not my circus, not my monkeys."

                      Comment


                      • #31
                        Fred,

                        I wrote a small test piece today using the Replace command and then
                        decompiled it to see what it was doing and it just does not have any
                        problems in the code. It uses the normal OLE string pool in the
                        normal way so the code is in itself fine. This means it can ONLY be
                        a buffering problem with the OLE string pool with the version of NT
                        and service pack that you customer is using.

                        Now in the short term, you are looking for a workaround to stop the
                        crashes, even though your own code is fine. It is not uncommon to
                        have to do workarounds on OS code as badly written as some of this
                        late Microsoft stuff is.

                        OLE string is a pre-allocated pool of memory which is why its faster
                        than GlobalAlloc and it sems that the later operating system versions
                        are making more use of it so it only takes one messup from Microsoft
                        to cause a problem.

                        Now basically your options are to try and take the load off the OLE
                        string pool and you have a few options you can test out quickly to
                        see if it will help.

                        1. De-allocate the basic string each time it is used which means
                        once per loop. a$ = ""

                        2. Try flushing each block of output to disk after each disk write.

                        It is not good code design and it will slow the code up but it may
                        help to stop the crashes.

                        Good Luck with it.

                        [email protected]

                        ------------------
                        hutch at movsd dot com
                        The MASM Forum - SLL Modules and PB Libraries

                        http://www.masm32.com/board/index.php?board=69.0

                        Comment


                        • #32
                          Ok, time to make a comment or two here...

                          1. Fred, you said that REPLACE ANY with a 15000 bytes string fails, right? I tried this code:

                          #COMPILE EXE
                          FUNCTION PBMAIN
                          A$ = STRING$(15000,"A")
                          B$ = "A"
                          C$ = "B"
                          REPLACE ANY B$ WITH C$ IN A$
                          MSGBOX "zero for success... we get " & FORMAT$(INSTR(A$, B$))
                          END FUNCTION

                          This code runs fine for me... the result is zero every time. I tried it under Windows 2000 (NT5) as I don;t have NT4 here. However, others with NT4 are encouraged to execute this code too.

                          2. Your code apparently fails within a DLL not an EXE, but as we have not seen compilable code, nor it seems has anyone else encountered this error... we can only mark this one as an "unconfirmed report".

                          According to my logs, we have never received even a single report of problems or evan a query regarding REPLACE or REPLACE ANY (with the exception of a couple of enquiries that turned out to be mismatched string lengths with the ANY clause).

                          3. Try the code I posted above... Try it yourself under as many NT4 machines you can get your hands on, and also make a DLL out of it to double check this against your complaint. Lets get to the bottom if this once and for all.

                          In summary, continuing with the "guesswork" in this thread is just wasting everyones time until someone can come up with a definitive conclusion as to the cause of the problem or, at the very least, a snippet of compilable code that shows the problem up.

                          Fred, the ball is in your court. I hope we can resolve this RSN.

                          ------------------
                          Lance
                          PowerBASIC Support
                          mailto:[email protected][email protected]</A>
                          Lance
                          mailto:[email protected]

                          Comment


                          • #33
                            Fred;

                            I mentioned this earlier and I think Hutch has "zeroed" in the likelyhood of the problem being in the Windows OLE engine.

                            While a PB app may be dependent upon a single OS DLL, that OS DLL (OLE in this case) may have dependencies of its own.

                            The problem occurs when a particular OS may have "mismatched" DLLs. There are more than one OLE DLLs in the OS and it is possible that one or all of them have been overwritten by an incorrect version. Some applications don't install corectly and may overwrite an "NEW" OS DLL with an "OLDER" version, which can create an OS DLL nightmare.

                            While I can't be sure this is the cause, it is definitely worth investigating the OS OLE DLLs to see if incorrect ones are in use.

                            Another area of concern is the affect of "other" apps running at the same time as yours. A good example is MS Interent Explorer. Running an app after IExplorer has been run can reak havoc for some apps, likely bacause of some bugs in Microsofts own apps. As a rule, I never run my PowerBasic compiler after running IExplorer. I always reboot and then start working on PB apps. I just don;t trust IExplorer.

                            The main point here, is that your code may be failing "because of external reasons" not because of your code or the PB compiler.

                            Lance, is right. If the Replace function was that unreliable, then they would be inundated with reports of a bug in the compiler. The replace function is used a great deal by PB programmers and a bug in it would have been apparent very quickly.



                            ------------------
                            Chris Boss
                            Computer Workshop
                            Developer of "EZGUI"
                            http://cwsof.com
                            http://twitter.com/EZGUIProGuy

                            Comment


                            • #34
                              According to my logs, we have never received even a single report of problems or
                              evan a query regarding REPLACE or REPLACE ANY (with the exception of a couple of enquiries
                              that turned out to be mismatched string lengths with the ANY clause).
                              Lance, remember "Houston... we might have a problem" from
                              march 1999 (a year ago).
                              As I said earlier, at that time I had not enough hard proof to persuit the matter. It was not crystal clear what happened.
                              I was not even really sure it was the Replace-instruction.
                              At that time the problem was solved by using Stamina-routine
                              instead of Replace.
                              I even sent support the complete program
                              Supports reply then were "if there are a bug in PB you can prove
                              this with code less than 10 lines, otherwise there are no bug"
                              (freele translated while trying to pull the knife out of my heart)



                              ------------------
                              Fred
                              mailto:[email protected][email protected]</A>
                              http://www.oxenby.se

                              Fred
                              mailto:[email protected][email protected]</A>
                              http://www.oxenby.se

                              Comment


                              • #35
                                Well, guys, as my problem is not solved but worked around, I can make yokes about it.
                                I have no hard feelings visavi powerbasic.I know that if my code is failing that is my problem.
                                I also know that here is a single instruction failing in the code
                                Follow my code and you will se that 15000 bytes are replaced
                                in one single instruction.
                                Follow my code and you will also find one of those stupid programmers that
                                reset all errorflags before he makes an potential dangerous call
                                Code:
                                      ErrClear:Get$ gIn.FilNr, gIn.BuffSize, glbInBuff
                                      If ErrClear > 0 Then rc%=102:GoSub DebugExit:Function = 102: Exit Function
                                Just to be sure that errors comes from the executed instruction.
                                Next, relevant sequence of instructions
                                Code:
                                      ErrClear:Get$ gIn.FilNr, gIn.BuffSize, glbInBuff
                                      If ErrClear > 0 Then rc%=102:GoSub DebugExit:Function = 102: Exit Function
                                      Replace Any glbAscii With glbEbcdic In glbInBuff
                                      glbInBuff = Tmp$ + glbInBuff
                                I don't use ErrClear here or checking Err or ErrApi. Why?
                                because I have never been able to get anything but zero on this
                                instruction. Even abusing Replace Any with diffrent size of
                                fromChar$ and ToChar$ return Zero in the ErrApi and Err-variable
                                If it is not Replace Any that produces a partial faulty buffer,
                                could it be the merge-instruction:
                                glbInbuff = Tmp$ + glbInBuff
                                Perhaps, but then this merge has to take glbInBuff and translate
                                part of it back to ascii before merging the two strings. I don't think this is very likely to happen.
                                How do I find out that the buffer is not correctly translated?
                                Because pos 1 in every subpart of the string ended with char 0A is a known value,
                                (You can also describe it as the first char after char 0A)
                                And I check this value.
                                During this check of the glbInbuff, it is not altered, tampered with or anything like that.
                                '--------
                                Fred, the ball is in your court. I hope we can resolve this RSN.
                                If you are not part of the sulotion, you are a part of the problem.
                                Sure, but it would be nice, given the fact that this really happens,
                                if someone from the backroom of powerbasic R&D (have I said this before..?)
                                stepped forward and told me that if there is a problem when
                                using Replace Any, ErrApi will hold a reference to whatever
                                caused the problem and the Err variable will be non-zero.
                                Finally, I have appreciated every single advice I have been given here on this board,
                                No question about it, Many of them will be followed promptly,
                                including backing down NT4 to SP4 and make sure IE 4.01 is installed. Then I will run full scale test on this machine, making sure that 'live data' is not involved in the testing.

                                ------------------
                                Fred
                                mailto:[email protected][email protected]</A>
                                http://www.oxenby.se



                                [This message has been edited by Fred Oxenby (edited April 12, 2000).]
                                Fred
                                mailto:[email protected][email protected]</A>
                                http://www.oxenby.se

                                Comment


                                • #36
                                  Some of you have asked for compile-able code.
                                  Lance does not like too much code, but for others here
                                  is the complete code in the DLL.
                                  Code:
                                  #Dim All 
                                  #Compile DLL "..\SLAV_DLL\FOX_ASA.DLL"
                                  #Include "..\COMMON\Win32Api.BAS"
                                  #Include "..\COMMON\FOXRUN32.INC"
                                  
                                  Type BuffTyp
                                   FilNr       As Long
                                   FilLen      As Quad
                                   FilPos      As Quad
                                   BytesToRead As Quad
                                   MaxBuff     As Long
                                   BuffSize    As Long
                                   BuffPos     As Long
                                   RadStart    As Long
                                   RadSlut     As Long
                                   RadLen      As Long
                                   RadLen1     As Long
                                   Refill      As Integer
                                   CharSet     As Integer
                                   BlkLen      As Integer
                                   RutinNamn   As String * 8
                                   FcbNamn     As String * 8
                                   Copies      As Integer
                                   OrderNr     As Long
                                   AsaCmd      As String * 16
                                   Trim        As Integer
                                   CvtRutin    As Integer
                                   xCallBack    As Dword
                                  End Type
                                  
                                  Type ErrResult
                                    ErrNr         As Long
                                    FilPos        As Quad
                                    BuffSize      As Long
                                    BuffPos       As Long
                                    FelRad        As String * 100
                                  End Type
                                  
                                  Global gIn       As BuffTyp
                                  Global gUt       As BuffTyp
                                  Global gErr      As ErrResult
                                  Global ghPBar    As Long
                                  Global glbAbort  As Long
                                  Global glbUtBuff As String
                                  Global glbInBuff As String
                                  Global gDebugFil As String
                                  
                                  %PBM_SETRANGE         =  (%WM_USER+1)
                                  %PBM_SETPOS           =  (%WM_USER+2)
                                  '%PBM_DELTAPOS         =  (%WM_USER+3)
                                  '%PBM_SETSTEP          =  (%WM_USER+4)
                                  '%PBM_STEPIT           =  (%WM_USER+5)
                                  %PBM_SETRANGE32       =  (%WM_USER+6)    ' lParam = high, wParam = low
                                  '%PBM_GETRANGE         =  (%WM_USER+7)    ' wParam = return (TRUE ? low : high). lParam = PPBRANGE or NULL
                                  '%PBM_GETPOS           =  (%WM_USER+8)
                                  '%PBM_SETBARCOLOR      =  (%WM_USER+9)	 ' lParam = bar color
                                  '%PBM_SETBKCOLOR       =  %CCM_SETBKCOLOR ' lParam = bkColor
                                  
                                  '===[EXPORTERAD WRAPPER CVTASA2PCC]==============
                                  Declare Function ASA_CVT2PCC(ByVal InFil$,ByVal UtFil$,ByVal BlkLen%,ByVal CharSet%,ByVal Hdr$,ByVal ProgBar&) As Long   
                                  Declare Function ASA_CVT2XFP(ByVal InFil$,ByVal UtFil$,ByVal BlkLen%,ByVal CharSet%,ByVal Hdr$,ByVal ProgBar&) As Long   
                                  Declare Function ASA_ABORT()As Long
                                  Declare Function ASA_RETCODE(EC As ErrResult)As Long
                                  
                                  '===[LOKALA FUNKTIONER]==========================
                                  Declare Function CVT_ASA2BARR(InFil$,UtFil$,Hdr$)As Integer
                                  Declare Function ASAVar_TO_XFP()As Integer
                                  Declare Function ASAFix_TO_XFP()As Integer
                                  Declare Function ASAVar_TO_PCC()As Integer
                                  Declare Function ASAFix_TO_PCC()As Integer
                                  Declare Function ProgressReport(ByVal FilPos&&,ByVal FilLen&&)As Long
                                  Declare Function HideProgBar()As Long
                                  Declare Function InitProgBar()As Long
                                  
                                  
                                  '===[EXPORTERAD WRAPPER CVTASA2PCC]==============
                                  Declare Function VBASA_CVT2PCC(ByRef InFil$,ByRef UtFil$,ByVal BlkLen%,ByVal CharSet%,ByRef Hdr$,ByVal ProgBar&) As Long   
                                  Declare Function VBASA_CVT2XFP(ByRef InFil$,ByRef UtFil$,ByVal BlkLen%,ByVal CharSet%,ByRef Hdr$,ByVal ProgBar&) As Long   
                                  Declare Function VBASA_ABORT()As Long
                                  Declare Function VBASA_RETCODE(ByRef RC&,ByRef FilPos&&,ByRef BuffPos&,ByRef BuffSize&,ByRef FelRad$)As Long
                                  '---
                                  Function VBASA_CVT2XFP(ByRef InFil$,ByRef UtFil$,ByVal BlkLen%,ByVal CharSet%,ByRef Hdr$,ByVal ProgBar&)Export As Long
                                    Function = ASA_CVT2XFP(InFil$,UtFil$,BlkLen%,CharSet%,Hdr$,ProgBar&)
                                  End Function   
                                  Function VBASA_CVT2PCC(ByRef InFil$,ByRef UtFil$,ByVal BlkLen%,ByVal CharSet%,ByRef Hdr$,ByVal ProgBar&)Export As Long   
                                    Function = ASA_CVT2PCC(InFil$,UtFil$,BlkLen%,CharSet%,Hdr$,ProgBar&)
                                  End Function
                                  Function VBASA_ABORT()Export As Long
                                   glbAbort = 1
                                  End Function 
                                  Function VBASA_RETCODE(ByRef RC&,ByRef FilPos&&,ByRef BuffPos&,ByRef BuffSize&,ByRef FelRad$)Export As Long
                                    RC&       =  gErr.ErrNr
                                    FilPos&&  =  gErr.FilPos
                                    BuffPos&  =  gErr.BuffPos  
                                    BuffSize& =  gErr.BuffSize 
                                    FelRad$   =  gErr.FelRad
                                  End Function  
                                  
                                  '===[EXPORTERAD WRAPPER CVTASA2XFP]==============
                                  Function ASA_ABORT()Export As Long
                                   glbAbort = 1
                                  End Function
                                  Function ASA_RETCODE(EC  As ErrResult)Export As Long
                                   EC = gErr
                                  End Function
                                  
                                  Function ASA_CVT2PCC(ByVal InFil$,ByVal UtFil$,ByVal BlkLen%,ByVal CharSet%,ByVal Hdr$,ByVal ProgBar&)Export As Long   
                                  Local ClrUDT As BuffTyp
                                  Local ClrErr As ErrResult
                                  Local rc%
                                      gDebugFil = FSO_AppPath() & FSO_GetFileName(InFil$)
                                      gErr = ClrErr
                                      gIn  = ClrUDT
                                      gUt  = ClrUDT
                                  '..Sätt Prog-parametrar...........................
                                      glbAbort      = 0
                                      ghPBar        = ProgBar&
                                      gIn.BlkLen    = BlkLen%
                                      Select Case CharSet%
                                       Case %ASCII :gIn.CharSet   = %ASC2EBC
                                       Case %ANSI  :gIn.CharSet   = %ANS2EBC
                                       Case %EBCDIC:gIn.CharSet   = %NONE
                                      End Select
                                      gIn.CvtRutin  = %AsaVar2Pcc
                                      If BlkLen%    > 0 Then gIn.CvtRutin  = %AsaFix2Pcc
                                  '..Sätt Buffer-parametrar.........................
                                      gIn.MaxBuff   = 15000
                                      gUt.MaxBuff   = 15000
                                  '..Anropa konverteringsrutinen....................
                                      Call InitProgBar()
                                      rc%           = CVT_ASA2Barr(InFil$,UtFil$,Hdr$)
                                      Call HideProgBar()
                                      Function      = rc%
                                      gErr.ErrNr    = rc%
                                      gErr.FilPos   = gIn.FilPos
                                      gErr.BuffPos  = gIn.BuffPos
                                      gErr.BuffSize = gIn.BuffSize
                                      gIn = ClrUDT
                                      gUt = ClrUDT
                                      glbUtBuff = "": glbInBuff = ""
                                  End Function
                                  
                                  Function ASA_CVT2XFP(ByVal InFil$,ByVal UtFil$,ByVal BlkLen%,ByVal CharSet%,ByVal Hdr$,ByVal ProgBar&)Export As Long
                                  Local ClrUDT As BuffTyp
                                  Local ClrErr As ErrResult
                                  Local rc%
                                      gDebugFil = FSO_AppPath() & FSO_GetFileName(InFil$)
                                      gErr = ClrErr
                                      gIn  = ClrUDT
                                      gUt  = ClrUDT
                                  '..Sätt Prog-parametrar...........................
                                      glbAbort      = 0
                                      ghPBar        = ProgBar&
                                      gIn.BlkLen    = BlkLen%
                                      Select Case CharSet%
                                       Case %ASCII :gIn.CharSet   = %ASC2EBC
                                       Case %ANSI  :gIn.CharSet   = %ANS2EBC
                                       Case %EBCDIC:gIn.CharSet   = %NONE
                                      End Select
                                      gIn.CvtRutin  = %AsaVar2Xfp
                                      If BlkLen%    > 0 Then gIn.CvtRutin  = %AsaFix2Xfp
                                      gIn.RutinNamn = Rtrim$(Parse$(Hdr$,"|",9),Any Chr$(0,32))
                                      gIn.OrderNr   = Val(Rtrim$(Parse$(Hdr$,"|",10),Any Chr$(0,32)))
                                  '..Sätt Buffer-parametrar.........................
                                      gIn.MaxBuff   = 15000
                                      gUt.MaxBuff   = 15000
                                  '..Anropa konverteringsrutinen....................
                                      Call InitProgBar()
                                      rc%           = CVT_ASA2Barr(InFil$,UtFil$,Hdr$)
                                      Call HideProgBar()
                                      Function      = rc%
                                      gErr.ErrNr    = rc%
                                      gErr.FilPos   = gIn.FilPos
                                      gErr.BuffPos  = gIn.BuffPos
                                      gErr.BuffSize = gIn.BuffSize
                                      gIn = ClrUDT
                                      gUt = ClrUDT
                                      glbUtBuff = "": glbInBuff = ""
                                  End Function
                                  '...[LOKAL KONVERTERINGSRUTIN]...................
                                  Function CVT_ASA2BARR(InFil$,UtFil$,Hdr$)As Integer
                                  '.Retur-koder....................................
                                  '   0 = Success
                                  ' 100 = Kan inte öppna InFil eller UtFil
                                  ' 101 = Fel i "1A"-eliminering
                                  ' 102 = Läsfel InFil
                                  ' 103 = Skrivfel UtFil
                                  ' 110 = Kommandofel
                                  ' 111 = PCC-radlängd större än 255 tecken
                                  ' 200 = User-Abort
                                  Local rc%,Tmp$,x1%,rl%
                                  Local SJob$,SFil$,SOrder$,SEJob$
                                  On Error Resume Next
                                  
                                  '..hyfsa parametrarna............................
                                      InFil$ = Rtrim$(InFil$,Any Chr$(0,32))
                                      UtFil$ = Rtrim$(UtFil$,Any Chr$(0,32))
                                  '..öppna InFilen.................................
                                      ErrClear
                                      gIn.FilNr = FreeFile
                                      Open InFil$ For Binary Access Read Write Lock Write As #gIn.FilNr
                                      If ErrClear > 0 Then rc% = 100:GoTo ErrExit
                                      gIn.FilPos      = 1
                                      gIn.FilLen      = Lof(gIn.FilNr)
                                      gIn.BytesToRead = gIn.FilLen -(gIn.FilPos - 1)
                                  '..öppna Ut-filen................................
                                      ErrClear
                                      gUt.FilNr = FreeFile
                                      Open UtFil$ For Binary As #gUt.FilNr
                                      If ErrClear > 0 Then rc% = 100:GoTo ErrExit
                                  '..lägg header i UTBuff..........................
                                      glbUtBuff = glbPCCHdr
                                  '..Uppdatera header från kommando................
                                      Tmp$=Parse$(Hdr$,"|", 1) :x1% = Instr(glbUtBuff, "JOBNAME=")
                                      If Len(Rtrim$(Tmp$)) Then Mid$(glbUtBuff,x1%+8, 8) = Tmp$
                                      Tmp$=Parse$(Hdr$,"|", 2) :x1% = Instr(glbUtBuff, "FORMNAME=")
                                      If Len(Rtrim$(Tmp$)) Then Mid$(glbUtBuff,x1%+9, 8) = Tmp$
                                      Tmp$=Parse$(Hdr$,"|", 3) :x1% = Instr(glbUtBuff, "FCBNAME=")
                                      If Len(Rtrim$(Tmp$)) Then Mid$(glbUtBuff,x1%+8, 8) = Tmp$
                                      Tmp$=Parse$(Hdr$,"|", 4) :x1% = Instr(glbUtBuff, "COPIES=")
                                      If Len(Rtrim$(Tmp$)) Then Mid$(glbUtBuff,x1%+7, 8) = Tmp$
                                      Tmp$=Parse$(Hdr$,"|", 5) :x1% = Instr(glbUtBuff, "STATE=")
                                      If Len(Rtrim$(Tmp$)) Then Mid$(glbUtBuff,x1%+6, 5) = Tmp$
                                      Tmp$=Parse$(Hdr$,"|", 6) :x1% = Instr(glbUtBuff, "CLASS=")
                                      If Len(Rtrim$(Tmp$)) Then Mid$(glbUtBuff,x1%+6, 1) = Tmp$
                                      Tmp$=Parse$(Hdr$,"|", 7) :x1% = Instr(glbUtBuff, "PRIORITY=")
                                      If Len(Rtrim$(Tmp$)) Then Mid$(glbUtBuff,x1%+9, 2) = Tmp$
                                  '...sätt upp XFP-kommandon.......................
                                      Select Case gIn.CvtRutin
                                       Case %AsaVar2Xfp,%AsaFix2Xfp
                                        SJob$   = Chr$(15) + "SJOB " + Rtrim$(Parse$(Hdr$,"|",9),Any Chr$(0,32))
                                        SFil$   = Chr$(15) + "INIT MPAD 132 OPER 90 '" + FSO_GetFileName(UtFil$) + "' END"
                                        SOrder$ = Chr$(15) + "INIT MPAD 132 OPER 105 '" + Rtrim$(Parse$(Hdr$,"|",10),Any Chr$(0,32)) + "' END"
                                        SEJob$  = Chr$(15) + "EJOB"
                                        Replace Any glbAscii With glbEbcdic In SJob$
                                        Replace Any glbAscii With glbEbcdic In SFil$
                                        Replace Any glbAscii With glbEbcdic In SOrder$
                                        Replace Any glbAscii With glbEbcdic In SEJob$
                                  '...Placera XFP-kommandon i UtBuff...............
                                        Rl% = 1 + Len(SJob$):If Rl% > 255 Then rc% = 111:GoTo ErrExit
                                        glbUtBuff = glbUtBuff + Mki$(Rl%) + Chr$(&H09) + SJob$ + Mki$(Rl%)
                                        Rl% = 1 + Len(SFil$):If Rl% > 255 Then rc% = 111:GoTo ErrExit
                                        glbUtBuff = glbUtBuff + Mki$(Rl%) + Chr$(&H09) + SFil$ + Mki$(Rl%)
                                        Rl% = 1 + Len(SOrder$):If Rl% > 255 Then rc% = 111:GoTo ErrExit
                                        glbUtBuff = glbUtBuff + Mki$(Rl%) + Chr$(&H09) + SOrder$ + Mki$(Rl%)
                                      End Select
                                  '...Commit UtBuff till disk......................
                                      ErrClear:Put$ gUt.FilNr,glbUtBuff
                                      If ErrClear > 0 Then rc% = 103:GoTo ErrExit
                                      glbUtBuff = ""
                                  '..Processa filen................................
                                      Select Case gIn.CvtRutin
                                       Case %AsaVar2Pcc: rc% = ASAVar_TO_PCC()
                                       Case %AsaFix2Pcc: rc% = ASAFix_TO_PCC()
                                       Case %AsaVar2Xfp: rc% = ASAVar_TO_XFP()
                                       Case %AsaFix2Xfp: rc% = ASAFix_TO_XFP()
                                      End Select
                                      If rc% > 0 Then GoTo ErrExit
                                  '..Töm UtBuffer till disk........................
                                      Select Case gIn.CvtRutin
                                       Case %AsaVar2Xfp,%AsaFix2Xfp
                                        Rl% = 1 + Len(SEJob$)
                                        If Rl% > 255 Then rc% = 111:GoTo ErrExit
                                        glbUtBuff = glbUtBuff + Mki$(Rl%) + Chr$(&H09) + SEJob$ + Mki$(Rl%)
                                      End Select
                                      ErrClear:Put$ gUt.FilNr,glbUtBuff
                                      If ErrClear > 0 Then rc% = 103:GoTo ErrExit
                                      glbUtBuff = ""
                                  '..stäng filerna.................................
                                      Close gIn.FilNr
                                      Close gUt.FilNr
                                      Function = 0
                                      Exit Function
                                  '===[ERROR-HANDLER]==============================
                                  ErrExit:
                                    Close gIn.FilNr
                                    Close gUt.FilNr
                                    Call FSO_DeleteFile(UtFil$)
                                    Function = rc%
                                  End Function
                                  
                                  'Option Explicit
                                  '===[LOKAL VARASA2XFP-RUTIN]=====================
                                  Function ASAVar_TO_XFP()As Integer
                                  Local Cmd$,Rad$,CmdPos%
                                  Local rc%,Tmp$,Rl%,z1%,z2%,z3%
                                  On Error Resume Next
                                      Tmp$ ="":glbInBuff=""
                                      gIn.Refill = 1
                                  '..loopa genom filen.............................
                                      ErrClear:Seek gIn.FilNr, gIn.FilPos
                                      If ErrClear > 0 Then Function = 120: Exit Function
                                      Do
                                       apiSleep 0
                                       If gIn.BytesToRead > 0 And gIn.Refill <> 0 Then
                                        gIn.Refill = 0
                                        gIn.BuffSize = Min(gIn.BytesToRead,gIn.MaxBuff)
                                        ErrClear
                                        Get$ gIn.FilNr, gIn.BuffSize, glbInBuff
                                        If ErrClear > 0 Then rc%=102:GoSub DebugExit:Function = 102: Exit Function
                                        gIn.FilPos = Seek(gIn.FilNr)
                                        If ErrClear > 0 Then rc%=120:GoSub DebugExit:Function = 120: Exit Function
                                        gIn.BytesToRead = gIn.FilLen - (gIn.FilPos - 1)
                                      '..Avlägsna Trailing "1A" och NULL...........
                                        If gIn.BytesToRead < 1  Then
                                         glbInBuff = Rtrim$(glbInBuff,Any Chr$(0,&H1A))
                                         If Right$(glbInBuff,1)<>Chr$(10) Then glbInBuff = glbInBuff + Chr$(10)
                                        End If
                                  '--Översätt Ascii Till Ebcdic--------------------
                                        Select Case gIn.Charset
                                         Case %ASC2EBC
                                          z1%=&HCA:z2%=&HB3:z3%=&HFA
                                          Replace Any glbAscii With glbEbcdic In glbInBuff
                                         Case %ANS2EBC
                                          z1%=&HDE:z2%=&HA1:z3%=&H8C
                                          Replace Any glbAnsi  With glbEbcdic In glbInBuff
                                         Case Else
                                          z1%=&HCA:z2%=&HFA:z3%=&HFC
                                        End Select
                                  '--Merge buffer----------------------------------
                                        glbInBuff = Tmp$ + glbInBuff
                                  '--Tabort CR och FF------------------------------
                                        glbInBuff = Remove$(glbInBuff$,Any Chr$(12,13))
                                  '--rätta till buffer-----------------------------
                                        gIn.BuffSize = Len(glbInBuff)
                                        gIn.BuffPos = 1
                                  '--rapportera filpos-----------------------------
                                        If ProgressReport(gIn.FilPos,gIn.FilLen)<> 0 Then rc%=200:GoSub DebugExit:Function = 200: Exit Function
                                       End If
                                  '--Konvertera raden------------------------------
                                       gIn.RadSlut = Instr(gIn.BuffPos,glbInBuff, Chr$(10))
                                       If gIn.RadSlut = 0 Then rc%=110:GoSub DebugExit:Function = 110: Exit Function
                                       Rad$ = Mid$(glbInBuff,gIn.BuffPos,gIn.RadSlut - gIn.BuffPos)
                                       gIn.BuffPos = gIn.RadSlut + 1
                                  '--Dags att fylla på buffer----------------------
                                       If gIn.BuffSize - gIn.BuffPos < 1024 Then
                                        Tmp$ = Mid$(glbInBuff,gIn.BuffPos)
                                        gIn.Refill = 1
                                       End If
                                  '--Validera Cmd/rad------------------------------
                                       Rad$=Rtrim$(Rad$,Any Chr$(0,64))
                                       Select Case Len(Rad$)
                                        Case > 1 : Cmd$ = Left$(Rad$,1):Rad$ = Mid$(Rad$,2)
                                        Case = 1 : Cmd$ = Rad$:Rad$ = Chr$(&H40)
                                        Case Else: Cmd$ = Chr$(&H40):Rad$ = Chr$(&H40)
                                       End Select
                                  '--Hantera NonAsa-kommandon----------------------
                                       Select Case Asc(Cmd$)
                                        Case &H5C :cmd$ = Chr$(&H40)
                                        Case &H4F,z1%,z2%,z3%:cmd$ = Chr$(&HC1): rad$ = Chr$(&H0E) + rad$
                                       End Select
                                  '--Returnera Normaliserat kommando---------------
                                       CmdPos% = Instr(Chr$(078,064,240,096,241,242,243,244, _
                                                            245,246,247,248,249,193,194,195),Cmd$)
                                       If CmdPos% = 0 Then
                                        Replace Any glbEbcdic With glbAscii In Rad$
                                        gErr.FelRad = "ERROR 110 CMD = " + Hex$(Asc(Cmd$)) + " RAD = " + Rad$
                                        rc%=110:GoSub DebugExit:Function = 110: Exit Function
                                       End If
                                  '--Skicka dem till PCC-buffer--------------------
                                       Cmd$ = Mid$(Chr$(001,009,017,025,137,145,153,161, _
                                                        169,177,185,193,201,209,217,225), CmdPos%, 1)
                                  '--Skapa PCC-rad---------------------------------
                                       Rl% = 1 + Len(Rad$)
                                       If Rl% > 255 Then rc%=111:GoSub DebugExit:Function = 111:Exit Function
                                       glbUtBuff = glbUtBuff + Mki$(Rl%) + Cmd$ + Rad$ + Mki$(Rl%)
                                  '--skriv ut buff---------------------------------
                                       If Len(glbUtBuff) > gUt.MaxBuff Then
                                        ErrClear:Put$ gUt.FilNr,glbUtBuff
                                        If ErrClear > 0 Then Function = 103:Exit Function
                                        glbUtBuff = ""
                                       End If
                                  '--är filen processad----------------------------
                                       If gIn.BytesToRead < 1 And gIn.BuffPos >= gIn.BuffSize Then Exit Do
                                      Loop
                                  '--Töm Utbuffer till disk------------------------
                                      If Len(glbUtBuff) > 0 Then
                                       ErrClear
                                       Put$ gUt.FilNr,glbUtBuff
                                       If ErrClear > 0 Then Function = 103:Exit Function
                                       glbUtBuff = ""
                                      End If
                                      Function = 0
                                      Exit Function
                                  DebugExit:
                                  Local q%,DebugString$,CSet$
                                  CSet$ = " NONE " & " RC= " & Format$(Rc%) 
                                  If gIn.CharSet= %ASC2EBC Then CSet$ =" ASC2EBC " & " RC= " & Format$(Rc%)
                                  If gIn.CharSet= %ANS2EBC Then CSet$ =" ANS2EBC " & " RC= " & Format$(Rc%)
                                  ErrClear:q% = FreeFile
                                  ErrClear:Open gDebugFil For Binary As #q%
                                  ErrClear:Put$ q%,glbInBuff
                                  DebugString$ = "|CharSet= " & CSet$ & "|FilPos= " & Format$(gIn.FilPos) & " |BuffPos= " & Format$(gIn.BuffPos)
                                  Put$ q%,DebugString$
                                  Close q%
                                  Return    
                                  End Function
                                  '===[LOKAL FIXASA2XFP-RUTIN]=====================
                                  Function ASAFix_TO_XFP()As Integer
                                  Local Cmd$,Rad$,CmdPos%
                                  Local rc%,Tmp$,Rl%,z1%,z2%,z3%
                                  On Error Resume Next
                                  
                                      Tmp$ = "":glbInBuff = ""
                                      gIn.Refill = 1
                                  '--loopa genom filen-----------------------------
                                      ErrClear:Seek gIn.FilNr, gIn.FilPos
                                      If ErrClear > 0 Then Function = 102: Exit Function
                                      Do
                                       apiSleep 0
                                       If gIn.BytesToRead > 0 And gIn.Refill <> 0 Then
                                        gIn.Refill = 0
                                        gIn.BuffSize = Min(gIn.BytesToRead,gIn.MaxBuff)
                                        ErrClear:Get$ gIn.FilNr, gIn.BuffSize, glbInBuff
                                        If ErrClear > 0 Then rc%=102:GoSub DebugExit:Function = 102: Exit Function
                                        gIn.FilPos = Seek(gIn.FilNr)
                                        If ErrClear > 0 Then rc%=120:GoSub DebugExit:Function = 120: Exit Function
                                        gIn.BytesToRead = gIn.FilLen - (gIn.FilPos - 1)
                                  '--Översätt Ascii Till Ebcdic--------------------
                                        Select Case gIn.Charset
                                         Case  %ASC2EBC
                                          Replace Any glbAscii With glbEbcdic In glbInBuff
                                          z1%=&HCA:z2%=&HB3:z3%=&HFA
                                         Case  %ANS2EBC
                                          Replace Any glbAnsi  With glbEbcdic In glbInBuff
                                          z1%=&HDE:z2%=&HA1:z3%=&H8C
                                         Case Else
                                          z1%=&HCA:z2%=&HFA:z3%=&HFC
                                         End Select
                                  '--Merge buffer----------------------------------
                                        glbInBuff = Tmp$ + glbInBuff
                                        gIn.BuffSize = Len(glbInBuff)
                                        gIn.BuffPos = 1                            
                                  '--rapportera filpos-----------------------------
                                        If ProgressReport(gIn.FilPos,gIn.FilLen)<> 0 Then rc%=200:GoSub DebugExit:Function = 200: Exit Function
                                       End If
                                  '--Konvertera raden------------------------------
                                       Cmd$ = Mid$(glbInBuff, gIn.BuffPos, 1)
                                       Rad$ = Mid$(glbInBuff, gIn.BuffPos + 1, gIn.BlkLen - 1)
                                       gIn.BuffPos = gIn.BuffPos + gIn.BlkLen
                                  '--Dags att fylla på buffert---------------------
                                       If gIn.BuffSize - gIn.BuffPos < 1024 Then
                                        Tmp$ = Mid$(glbInBuff,gIn.BuffPos)
                                        gIn.Refill = 1
                                       End If
                                  '--Trimma raden----------------------------------
                                       Rad$ = Rtrim$(Rad$,Any Chr$(0,64))
                                  '--Hantera NonAsa-kommandon----------------------
                                       Select Case Asc(Cmd$)
                                        Case &H5C :cmd$ = Chr$(&H40)
                                        Case &H4F,z1%,z2%,z3%:cmd$ = Chr$(&HC1): rad$ = Chr$(&H0E) + rad$
                                       End Select
                                  '--Returnera Normaliserat kommando---------------
                                       CmdPos% = Instr(Chr$(078,064,240,096,241,242,243,244, _
                                                            245,246,247,248,249,193,194,195),Cmd$)
                                       If CmdPos% = 0 Then
                                        Replace Any glbEbcdic With glbAscii In Rad$
                                        gErr.FelRad = "ERROR 110 CMD = " + Hex$(Asc(Cmd$)) + " RAD = " + Rad$
                                        rc%=110:GoSub DebugExit:Function = 110: Exit Function
                                       End If
                                  '--Skicka dem till PCC-buffer--------------------
                                       Cmd$ = Mid$(Chr$(001,009,017,025,137,145,153,161, _
                                                        169,177,185,193,201,209,217,225), CmdPos%, 1)
                                  '--Skapa PCC-rad---------------------------------
                                       Rl% = 1 + Len(Rad$)
                                       If Rl% > 255 Then rc%=111:GoSub DebugExit:Function = 111:Exit Function
                                       glbUtBuff = glbUtBuff + Mki$(Rl%) + Cmd$ + Rad$ + Mki$(Rl%)
                                  '--skriv ut buff---------------------------------
                                       If Len(glbUtBuff) > gUt.MaxBuff Then
                                        ErrClear:Put$ gUt.FilNr,glbUtBuff
                                        If ErrClear > 0 Then Function = 103:Exit Function
                                        glbUtBuff = ""
                                       End If
                                  '--är filen processad----------------------------
                                       If gIn.BytesToRead < 1 And gIn.BuffPos >= gIn.BuffSize Then Exit Do
                                      Loop
                                  '--Skicka EndOfJob och Flush PCC-Buffer----------
                                      If Len(glbUtBuff) > 0 Then
                                       ErrClear
                                       Put$ gUt.FilNr,glbUtBuff
                                       If ErrClear > 0 Then Function = 103:Exit Function
                                       glbUtBuff = ""
                                      End If
                                      Function = 0
                                      Exit Function
                                  DebugExit:
                                  Local q%,DebugString$,CSet$
                                  CSet$ = " NONE " & " RC= " & Format$(Rc%) 
                                  If gIn.CharSet= %ASC2EBC Then CSet$ =" ASC2EBC " & " RC= " & Format$(Rc%)
                                  If gIn.CharSet= %ANS2EBC Then CSet$ =" ANS2EBC " & " RC= " & Format$(Rc%)
                                  ErrClear:q% = FreeFile
                                  ErrClear:Open gDebugFil For Binary As #q%
                                  ErrClear:Put$ q%,glbInBuff
                                  DebugString$ = "|CharSet= " & CSet$ & "|FilPos= " & Format$(gIn.FilPos) & " |BuffPos= " & Format$(gIn.BuffPos)
                                  Put$ q%,DebugString$
                                  Close q%
                                  Return    
                                  End Function
                                  '===[LOKAL VARASA2PCC-RUTIN]=====================
                                  Function ASAVar_TO_PCC()As Integer
                                  Local Cmd$,Rad$,CmdPos%
                                  Local PrevRad$,LastCmdPos%
                                  Local rc%,Tmp$,Rl%,z1%,z2%,z3%
                                  On Error Resume Next
                                      Tmp$ ="":glbInBuff=""
                                  '--hämta första bufferten------------------------
                                      Seek gIn.FilNr,gIn.FilPos
                                      If ErrClear > 0 Then Function = 120: Exit Function
                                      gIn.BuffSize = Min(gIn.BytesToRead,gIn.MaxBuff)
                                      ErrClear:Get$ gIn.FilNr, gIn.BuffSize, glbInBuff
                                      If ErrClear > 0 Then rc%=102:GoSub DebugExit:Function = 102: Exit Function
                                      gIn.FilPos = Seek(gIn.FilNr)
                                      If ErrClear > 0 Then rc%=120:GoSub DebugExit:Function = 120: Exit Function
                                      gIn.BytesToRead = gIn.FilLen - (gIn.FilPos - 1)
                                  '--Avlägsna Trailing "1A" och NULL---------------
                                      If gIn.BytesToRead < 1  Then
                                       glbInBuff = Rtrim$(glbInBuff,Any Chr$(0,&H1A))
                                       If Right$(glbInBuff,1)<>Chr$(10) Then glbInBuff = glbInBuff + Chr$(10)
                                      End If
                                  '--Översätt Ascii Till Ebcdic--------------------
                                      Select Case gIn.Charset
                                       Case  %ASC2EBC
                                        Replace Any glbAscii With glbEbcdic In glbInBuff
                                        z1%=&HCA:z2%=&HB3:z3%=&HFA
                                       Case  %ANS2EBC
                                        Replace Any glbAnsi  With glbEbcdic In glbInBuff
                                        z1%=&HDE:z2%=&HA1:z3%=&H8C
                                       Case Else
                                        z1%=&HCA:z2%=&HFA:z3%=&HFC
                                      End Select
                                  '--Merge buffer----------------------------------
                                      glbInBuff = Tmp$ + glbInBuff
                                  '--Tabort CR och FF------------------------------
                                      glbInBuff = Remove$(glbInBuff$,Any Chr$(12,13))
                                  '--rätta till buffer-----------------------------
                                      gIn.BuffSize = Len(glbInBuff)
                                      gIn.BuffPos = 1
                                      gIn.Refill = 0
                                  '--Det första kommandot--------------------------
                                  '   Cmdpointer i LastCmdPos%
                                  '   PrevRad$ håller den första raden som skall
                                  '   kombineras med nästa Cmd$
                                      gIn.RadSlut    = Instr(gIn.BuffPos,glbInBuff, Chr$(10))
                                      If gIn.RadSlut = 0 Then rc%=110:GoSub DebugExit:Function = 110: Exit Function
                                      Rad$           = Mid$(glbInBuff,gIn.BuffPos,gIn.RadSlut - gIn.BuffPos)
                                      gIn.BuffPos    = gIn.RadSlut + 1
                                  '--Validera Cmd/rad------------------------------
                                      Rad$=Rtrim$(Rad$,Any Chr$(0,64))
                                      Select Case Len(Rad$)
                                       Case > 1 : Cmd$ = Left$(Rad$,1):Rad$ = Mid$(Rad$,2)
                                       Case = 1 : Cmd$ = Rad$:Rad$ = Chr$(&H40)
                                       Case Else: Cmd$ = Chr$(&H40):Rad$ = Chr$(&H40)
                                      End Select
                                  '--Hantera NonAsa-kommandon----------------------
                                      Select Case Asc(Cmd$)
                                       Case &H5C :cmd$ = Chr$(&H40)
                                       Case &HFA,z1%,z2%,z3%:rad$ = Cmd$ + rad$:cmd$ = Chr$(&H40) ',&HCA,&H9A,&H4F
                                      End Select
                                  '--Returnera Normaliserat kommando---------------
                                      LastCmdPos% = Instr(Chr$(078,064,240,096,241,242,243,244, _
                                                               245,246,247,248,249,193,194,195),Cmd$)
                                      If LastCmdPos% = 0 Then
                                        Replace Any glbEbcdic With glbAscii In Rad$
                                        gErr.FelRad = "ERROR 110 CMD = " + Hex$(Asc(Cmd$)) + " RAD = " + Rad$
                                        rc%=110:GoSub DebugExit:Function = 110: Exit Function
                                      End If
                                  '--Spara raden till nästa kommando---------------
                                      PrevRad$ = Rad$
                                  '--loopa genom filen-----------------------------
                                      Do
                                       apiSleep 0
                                       If gIn.BytesToRead > 0 And gIn.Refill <> 0 Then
                                        gIn.Refill=0
                                        gIn.BuffSize = Min(gIn.BytesToRead,gIn.MaxBuff)
                                        ErrClear
                                        Get$ gIn.FilNr, gIn.BuffSize, glbInBuff
                                        If ErrClear > 0 Then rc%=102:GoSub DebugExit:Function = 102: Exit Function
                                        gIn.FilPos = Seek(gIn.FilNr)
                                        If ErrClear > 0 Then rc%=120:GoSub DebugExit:Function = 120: Exit Function
                                        gIn.BytesToRead = gIn.FilLen - (gIn.FilPos - 1)
                                  '--Avlägsna Trailing "1A" och NULL---------------
                                        If gIn.BytesToRead < 1  Then
                                         glbInBuff = Rtrim$(glbInBuff,Any Chr$(0,&H1A))
                                         If Right$(glbInBuff,1)<>Chr$(10) Then glbInBuff = glbInBuff + Chr$(10)
                                        End If
                                  '--Översätt Ascii Till Ebcdic-------------------
                                        Select Case gIn.Charset
                                         Case  %ASC2EBC
                                          Replace Any glbAscii With glbEbcdic In glbInBuff
                                          z1%=&HCA:z2%=&HB3:z3%=&HFA
                                         Case  %ANS2EBC
                                          Replace Any glbAnsi  With glbEbcdic In glbInBuff
                                          z1%=&HDE:z2%=&HA1:z3%=&H8C
                                         Case Else
                                          z1%=&HCA:z2%=&HFA:z3%=&HFC
                                        End Select
                                  '--Merge buffer----------------------------------
                                        glbInBuff = Tmp$ + glbInBuff
                                  '--Tabort CR och FF------------------------------
                                        glbInBuff = Remove$(glbInBuff$,Any Chr$(12,13))
                                  '--rätta till buffer-----------------------------
                                        gIn.BuffSize = Len(glbInBuff)
                                        gIn.BuffPos = 1                            
                                  '--rapportera filpos-----------------------------
                                        If ProgressReport(gIn.FilPos,gIn.FilLen)<> 0 Then rc%=200:GoSub DebugExit:Function = 200: Exit Function
                                       End If
                                  '--Konvertera raden------------------------------
                                       gIn.RadSlut = Instr(gIn.BuffPos,glbInBuff, Chr$(10))
                                       If gIn.RadSlut = 0 Then rc%=111:GoSub DebugExit:Function = 111: Exit Function
                                       Rad$ = Mid$(glbInBuff,gIn.BuffPos,gIn.RadSlut - gIn.BuffPos)
                                       gIn.BuffPos = gIn.RadSlut + 1
                                  '--Dags att fylla på buffer----------------------
                                       If gIn.BuffSize - gIn.BuffPos < 1024 Then
                                        Tmp$ = Mid$(glbInBuff,gIn.BuffPos)
                                        gIn.Refill = 1
                                       End If
                                  '--Validera Cmd/rad------------------------------
                                       Rad$=Rtrim$(Rad$,Any Chr$(0,64))
                                       Select Case Len(Rad$)
                                        Case > 1 :Cmd$ = Left$(Rad$,1):Rad$ = Mid$(Rad$,2)
                                        Case = 1 :Cmd$ = Rad$:Rad$ = Chr$(64)
                                        Case Else:Cmd$ = Chr$(64):Rad$ = Chr$(64)
                                       End Select
                                  '--Hantera NonAsa-kommandon----------------------
                                       Select Case Asc(Cmd$)
                                        Case &H5C :cmd$ = Chr$(&H40)
                                        Case &HCA,z1%,z2%,z3%:rad$ = Cmd$ + rad$:cmd$ = Chr$(&H40) ',&HCA,&H9A,&H4F
                                       End Select
                                  '--Returnera Normaliserat kommando---------------
                                       CmdPos% = Instr(Chr$(078,064,240,096,241,242,243,244, _
                                                            245,246,247,248,249,193,194,195),Cmd$)
                                       If CmdPos% = 0 Then
                                        Replace Any glbEbcdic With glbAscii In Rad$
                                        gErr.FelRad = "ERROR 110 CMD = " + Hex$(Asc(Cmd$)) + " RAD = " + Rad$
                                        rc%=110:GoSub DebugExit:Function = 110: Exit Function
                                       End If
                                  '--Skicka dem till PCC-buffer--------------------
                                       Cmd$ = Mid$(Chr$(001,009,017,025,137,145,153,161, _
                                                        169,177,185,193,201,209,217,225), CmdPos%, 1)
                                  '--Till detta kommando hör PrevRad$--------------
                                       Swap Rad$,PrevRad$
                                  '--Skapa PCC-rad---------------------------------
                                       Rl% = 1 + Len(Rad$)
                                       If Rl% > 255 Then rc%=111:GoSub DebugExit:Function = 111:Exit Function
                                       glbUtBuff = glbUtBuff + Mki$(Rl%) + Cmd$ + Rad$ + Mki$(Rl%)
                                  '--skriv ut buff---------------------------------
                                       If Len(glbUtBuff) > gUt.MaxBuff Then
                                        ErrClear:Put$ gUt.FilNr,glbUtBuff
                                        If ErrClear > 0 Then Function = 103:Exit Function
                                        glbUtBuff = ""
                                       End If
                                  '--är filen processad----------------------------
                                       If gIn.BytesToRead < 1 And gIn.BuffPos >= gIn.BuffSize Then Exit Do
                                      Loop
                                  '--Sista kommandot skall hanteras----------------
                                      Cmd$ = Mid$(Chr$(001,009,017,025,137,145,153,161, _
                                                       169,177,185,193,201,209,217,225), LastCmdPos%, 1)
                                      Swap Rad$,PrevRad$
                                  '--Skapa PCC-rad---------------------------------
                                      Rl% = 1 + Len(Rad$)
                                      If Rl% > 255 Then rc%=111:GoSub DebugExit:Function = 111:Exit Function
                                      glbUtBuff = glbUtBuff + Mki$(Rl%) + Cmd$ + Rad$ + Mki$(Rl%)
                                  '--skriv ut buff---------------------------------
                                      ErrClear:Put$ gUt.FilNr,glbUtBuff
                                      If ErrClear > 0 Then Function = 103:Exit Function
                                      glbUtBuff = "":glbInBuff = ""
                                      Function = 0
                                      Exit Function
                                  DebugExit:
                                  Local q%,DebugString$,CSet$
                                  CSet$ = " NONE " & " RC= " & Format$(Rc%) 
                                  If gIn.CharSet= %ASC2EBC Then CSet$ =" ASC2EBC " & " RC= " & Format$(Rc%)
                                  If gIn.CharSet= %ANS2EBC Then CSet$ =" ANS2EBC " & " RC= " & Format$(Rc%)
                                  ErrClear:q% = FreeFile
                                  ErrClear:Open gDebugFil For Binary As #q%
                                  ErrClear:Put$ q%,glbInBuff
                                  DebugString$ = "|CharSet= " & CSet$ & "|FilPos= " & Format$(gIn.FilPos) & " |BuffPos= " & Format$(gIn.BuffPos)
                                  Put$ q%,DebugString$
                                  Close q%
                                  Return    
                                  End Function
                                  '===[LOKAL FIXASA2PCC-RUTIN]=====================
                                  Function ASAFix_TO_PCC()As Integer
                                  Local Cmd$,Rad$,CmdPos%
                                  Local PrevRad$,LastCmdPos%
                                  Local rc%,Tmp$,Rl%,z1%,z2%,z3%
                                  On Error Resume Next
                                  '--Hantera första raden--------------------------
                                      Tmp$ = "":glbInBuff = Space$(gIn.Blklen)
                                      ErrClear
                                      Seek gIn.FilNr,gIn.FilPos
                                      If ErrClear > 0 Then Function = 120:Exit Function
                                      Get gIn.FilNr,gIn.FilPos,glbInBuff
                                      If ErrClear > 0 Then rc%=102:GoSub DebugExit:Function = 102: Exit Function
                                      Select Case gIn.Charset
                                       Case  %ASC2EBC
                                        Replace Any glbAscii With glbEbcdic In glbInBuff
                                        z1%=&HCA:z2%=&HB3:z3%=&HFA
                                       Case  %ANS2EBC
                                        Replace Any glbAnsi  With glbEbcdic In glbInBuff
                                        z1%=&HDE:z2%=&HA1:z3%=&H8C
                                       Case Else
                                        z1%=&HCA:z2%=&HFA:z3%=&HFC
                                      End Select
                                      Cmd$ = Mid$(glbInBuff, 1, 1)
                                      Rad$ = Mid$(glbInBuff, 2, gIn.BlkLen - 1)
                                      Rad$ = Rtrim$(Rad$,Chr$(64))
                                  '--Hantera NonAsa-kommandon----------------------
                                      Select Case Asc(Cmd$)
                                       Case &H5C :cmd$ = Chr$(&H40)
                                       Case &HCA,z1%,z2%,z3%:Rad$ = Cmd$ + rad$:cmd$ = Chr$(&H40) ',&HCA,&H9A,&H4F
                                      End Select
                                  '--Spara CmdPos% till sista raden----------------
                                      LastCmdPos% = Instr(Chr$(078,064,240,096,241,242,243,244, _
                                                               245,246,247,248,249,193,194,195),Cmd$)
                                      If LastCmdPos% = 0 Then
                                        Replace Any glbEbcdic With glbAscii In Rad$
                                        gErr.FelRad = "ERROR 110 CMD = " + Hex$(Asc(Cmd$)) + " RAD = " + Rad$
                                        rc%=110:GoSub DebugExit:Function = 110: Exit Function
                                      End If
                                  '--Spara Rad$ för nästa Cmd$---------------------
                                      PrevRad$ = Rad$
                                  '--Läs resten av filen---------------------------
                                      gIn.FilPos = Seek(gIn.FilNr)
                                      gIn.BytesToRead = gIn.FilLen - (gIn.FilPos - 1)
                                      gIn.Refill = 1
                                      Do
                                       apiSleep 0
                                       If gIn.BytesToRead > 0 And gIn.Refill <> 0 Then
                                        gIn.Refill= 0
                                        gIn.BuffSize = Min(gIn.BytesToRead,gIn.MaxBuff)
                                        ErrClear:Get$ gIn.FilNr, gIn.BuffSize, glbInBuff
                                        If ErrClear > 0 Then rc%=102:GoSub DebugExit:Function = 102: Exit Function
                                        gIn.FilPos = Seek(gIn.FilNr)
                                        If ErrClear > 0 Then rc%=120:GoSub DebugExit:Function = 120: Exit Function
                                        gIn.BytesToRead = gIn.FilLen - (gIn.FilPos - 1)
                                  '--Översätt Ascii Till Ebcdic--------------------
                                        Select Case gIn.Charset
                                         Case  %ASC2EBC
                                          Replace Any glbAscii With glbEbcdic In glbInBuff
                                          z1%=&HCA:z2%=&HB3:z3%=&HFA
                                         Case  %ANS2EBC
                                          Replace Any glbAnsi  With glbEbcdic In glbInBuff
                                          z1%=&HDE:z2%=&HA1:z3%=&H8C
                                         Case Else
                                          z1%=&HCA:z2%=&HFA:z3%=&HFC
                                        End Select
                                  '--Merge buffer----------------------------------
                                        glbInBuff = Tmp$ + glbInBuff
                                        gIn.BuffSize = Len(glbInBuff)
                                        gIn.BuffPos = 1
                                        If ProgressReport(gIn.FilPos,gIn.FilLen)<> 0 Then rc%=200:GoSub DebugExit:Function = 200: Exit Function
                                       End If
                                  '--Konvertera raden------------------------------
                                       Cmd$ = Mid$(glbInBuff, gIn.BuffPos, 1)
                                       Rad$ = Mid$(glbInBuff, gIn.BuffPos + 1, gIn.BlkLen - 1)
                                       gIn.BuffPos = gIn.BuffPos + gIn.BlkLen
                                       Rad$ = Rtrim$(Rad$,Chr$(64))
                                  '--Dags att fylla på buffer----------------------
                                       If gIn.BuffSize - gIn.BuffPos < 1024 Then
                                        Tmp$ = Mid$(glbInBuff,gIn.BuffPos)
                                        gIn.Refill = 1
                                       End If
                                  '--Hantera NonAsa-kommandon----------------------
                                       Select Case Asc(Cmd$)
                                        Case &H5C :cmd$ = Chr$(&H40)
                                        Case &HCA,z1%,z2%,z3%:rad$ = Cmd$ + rad$:cmd$ = Chr$(&H40) ',&HCA,&H9A,&H4F
                                       End Select
                                  '--Returnera Normaliserat kommando---------------
                                       CmdPos% = Instr(Chr$(078,064,240,096,241,242,243,244, _
                                                            245,246,247,248,249,193,194,195),Cmd$)
                                       If CmdPos% = 0 Then
                                        Replace Any glbEbcdic With glbAscii In Rad$
                                        gErr.FelRad = "ERROR 110 CMD = " + Hex$(Asc(Cmd$)) + " RAD = " + Rad$
                                        rc%=110:GoSub DebugExit:Function = 110: Exit Function
                                       End If
                                  '--Skicka dem till PCC-buffer--------------------
                                       Cmd$ = Mid$(Chr$(001,009,017,025,137,145,153,161, _
                                                        169,177,185,193,201,209,217,225), CmdPos%, 1)
                                  '--PrevRad hör till detta kommando---------------
                                       Swap Rad$,PrevRad$
                                  '--Skapa PCC-rad---------------------------------
                                       Rl% = 1 + Len(Rad$)
                                       If Rl% > 255 Then rc%=111:GoSub DebugExit:Function = 111:Exit Function
                                       glbUtBuff = glbUtBuff + Mki$(Rl%) + Cmd$ + Rad$ + Mki$(Rl%)
                                  '--skriv ut buff---------------------------------
                                       If Len(glbUtBuff) > gUt.MaxBuff Then
                                        ErrClear:Put$ gUt.FilNr,glbUtBuff
                                        If ErrClear > 0 Then Function = 103:Exit Function
                                        glbUtBuff = ""
                                       End If
                                  '--är filen processad----------------------------
                                       If gIn.BytesToRead < 1 And gIn.BuffPos >= gIn.BuffSize Then Exit Do
                                      Loop
                                  '--Sista kommandot skall hanteras----------------
                                      Cmd$ = Mid$(Chr$(001,009,017,025,137,145,153,161, _
                                                       169,177,185,193,201,209,217,225), LastCmdPos%, 1)
                                      Swap Rad$,PrevRad$
                                  '--Skapa PCC-rad---------------------------------
                                      Rl% = 1 + Len(Rad$)
                                      If Rl% > 255 Then rc%=111:GoSub DebugExit:Function = 111:Exit Function
                                      glbUtBuff = glbUtBuff + Mki$(Rl%) + Cmd$ + Rad$ + Mki$(Rl%)
                                  '--skriv ut buff---------------------------------
                                      ErrClear:Put$ gUt.FilNr,glbUtBuff
                                      If ErrClear > 0 Then Function = 103:Exit Function
                                      glbUtBuff = "":glbInBuff = ""
                                      Function = 0
                                      Exit Function
                                  DebugExit:
                                  Local q%,DebugString$,CSet$
                                  CSet$ = " NONE " & " RC= " & Format$(Rc%) 
                                  If gIn.CharSet= %ASC2EBC Then CSet$ =" ASC2EBC " & " RC= " & Format$(Rc%)
                                  If gIn.CharSet= %ANS2EBC Then CSet$ =" ANS2EBC " & " RC= " & Format$(Rc%)
                                  ErrClear:q% = FreeFile
                                  ErrClear:Open gDebugFil For Binary As #q%
                                  ErrClear:Put$ q%,glbInBuff
                                  DebugString$ = "|CharSet= " & CSet$ & "|FilPos= " & Format$(gIn.FilPos) & " |BuffPos= " & Format$(gIn.BuffPos)
                                  Put$ q%,DebugString$
                                  Close q%
                                  Return    
                                  End Function
                                  
                                  '==[OUTPUT-FUNKTIONER]============================
                                  Function InitProgBar()As Long
                                    If ghPBar = 0 Then Function = glbAbort:Exit function
                                    Call SendMessage(ghPBar,%PBM_SETRANGE, 0,MakLng(0,1000))
                                    Call SendMessage(ghPBar,%PBM_SETPOS,0,0)
                                    Call ShowWindow(ghPBar,%SW_SHOW)
                                    Function = glbAbort
                                  End Function
                                  Function HideProgBar()As Long
                                    If ghPBar = 0 Then Function = glbAbort:Exit function
                                    Call SendMessage(ghPBar,%PBM_SETPOS,0,0)
                                    Call ShowWindow(ghPBar,%SW_HIDE)
                                    Function = glbAbort
                                  End Function
                                  Function ProgressReport(ByVal FilPos&&,ByVal FilLen&&)As Long
                                  Static NewPos&
                                    If ghPBar = 0 Then Function = glbAbort:Exit function
                                    NewPos& = CLng(FilPos&& / FilLen&& * 1000)
                                    Call SendMessage(ghPBar, %PBM_SETPOS,NewPos&,0)
                                    Function = glbAbort
                                  End Function
                                  
                                  '==[DLL-CODE]====================================
                                  Sub InitGlobal()
                                  '--ANSI teckenuppsättning---
                                  glbANSI =   Chr$(000,001,002,003,004,005,006,007,008,009,010,011,012,013,014,015, _
                                                   016,017,018,019,020,021,022,023,024,025,026,027,028,029,030,031, _
                                                   032,033,034,035,036,037,038,039,040,041,042,043,044,045,046,047, _
                                                   048,049,050,051,052,053,054,055,056,057,058,059,060,061,062,063, _
                                                   064,065,066,067,068,069,070,071,072,073,074,075,076,077,078,079, _
                                                   080,081,082,083,084,085,086,087,088,089,090,091,092,093,094,095, _
                                                   096,097,098,099,100,101,102,103,104,105,106,107,108,109,110,111, _
                                                   112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, _
                                                   199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197, _
                                                   201,230,198,244,246,242,251,249,255,214,220,248,163,216,215,128, _
                                                   225,237,243,250,241,209,129,130,191,174,131,189,188,161,171,187, _
                                                   132,133,134,135,136,193,194,192,169,137,138,139,140,162,165,141, _
                                                   142,143,144,145,146,147,227,195,148,149,150,151,152,153,154,155, _
                                                   240,208,202,203,200,170,205,206,207,157,158,159,164,166,204,176, _
                                                   211,223,212,210,245,213,181,254,222,218,219,217,253,156,175,180, _
                                                   173,177,172,190,182,167,247,184,186,168,183,185,179,178,221,160)
                                  '--EBCDIC teckenupsättning----
                                  glbEBCDIC = Chr$(000,001,002,003,055,045,046,047,022,005,010,011,012,013,014,015, _
                                                   016,017,018,019,060,061,050,038,024,025,063,039,028,029,030,031, _
                                                   064,079,127,099,103,108,080,125,077,093,092,078,107,096,075,097, _
                                                   240,241,242,243,244,245,246,247,248,249,122,094,076,126,110,111, _
                                                   236,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, _
                                                   215,216,217,226,227,228,229,230,231,232,233,181,113,159,095,109, _
                                                   081,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, _
                                                   151,152,153,162,163,164,165,166,167,168,169,065,187,071,220,255, _
                                                   104,161,121,066,192,068,208,072,082,083,084,087,086,088,123,091, _
                                                   224,156,158,203,106,205,219,221,223,124,252,112,177,128,191,007, _
                                                   069,085,206,222,073,105,154,155,171,175,186,184,183,170,138,139, _
                                                   043,044,009,033,040,101,098,100,180,056,049,052,051,176,178,036, _
                                                   034,023,041,006,032,042,070,102,026,053,008,057,054,048,058,090, _
                                                   140,172,114,115,116,037,117,118,119,035,021,020,004,204,120,059, _
                                                   238,089,235,237,207,239,160,142,174,254,251,253,141,173,188,190, _
                                                   202,143,027,185,182,067,225,157,144,189,179,218,250,234,062,074)
                                  '--ASCII teckenuppsättning----
                                  glbASCII =  Chr$(000,001,002,003,004,005,006,007,008,009,010,011,012,013,014,015, _
                                                   016,017,018,019,020,021,022,023,024,025,026,027,028,029,030,031, _
                                                   032,033,034,035,036,037,038,039,040,041,042,043,044,045,046,047, _
                                                   048,049,050,051,052,053,054,055,056,057,058,059,060,061,062,063, _
                                                   064,065,066,067,068,069,070,071,072,073,074,075,076,077,078,079, _
                                                   080,081,082,083,084,085,086,087,088,089,090,091,092,093,094,095, _
                                                   096,097,098,099,100,101,102,103,104,105,106,107,108,109,110,111, _
                                                   112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, _
                                                   128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, _
                                                   144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, _
                                                   160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, _
                                                   176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, _
                                                   192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, _
                                                   208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, _
                                                   224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, _
                                                   240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255)
                                  '...Header.......................................
                                  glbPccHdr = Chr$(118,026,255,255,206,000,255,080,082,073,078,084,069,082,032,070, _
                                                   079,082,077,078,065,077,069,061,032,032,032,032,032,032,032,032, _
                                                   032,076,080,070,061,032,032,032,032,080,076,080,070,061,032,032, _
                                                   032,032,076,080,073,061,032,032,067,079,078,084,082,079,076,061, _
                                                   032,032,032,076,079,067,078,065,077,069,061,032,032,032,032,032, _
                                                   032,032,032,013,010,074,079,066,078,065,077,069,061,032,032,032, _
                                                   032,032,032,032,032,032,067,079,080,073,069,083,061,032,032,032, _
                                                   032,032,032,032,032,032,080,082,073,079,082,073,084,089,061,032, _
                                                   032,032,083,084,065,084,069,061,032,032,032,032,032,032,067,076, _
                                                   065,083,083,061,032,032,032,032,032,032,032,032,032,032,032,013, _
                                                   010,070,067,066,078,065,077,069,061,032,032,032,032,032,032,032, _
                                                   032,032,085,067,083,061,032,032,032,032,032,032,032,032,032,032, _
                                                   032,032,032,032,032,032,032,032,032,032,032,032,049,050,051,052, _
                                                   053,054,055,013,206,000,068,000,198,129,001,000,000,000,000,000)
                                  glbPccHdr = glbPccHdr _
                                            + Chr$(000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000, _
                                                   000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000, _
                                                   000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000, _
                                                   000,000,000,000,000,000,000,000,000,000,000,016,068,000,188,000, _
                                                   255,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,064,064,064,064, _
                                                   064,064,064,064,064,064,064,064,064,064,064,064,188,000)
                                  End Sub
                                  
                                  Function LibMain(ByVal hInstance   As Long, _
                                                   ByVal fwdReason   As Long, _
                                                   ByVal lpvReserved As Long) Export As Long
                                  
                                    Select Case fwdReason
                                      Case %DLL_PROCESS_ATTACH
                                         InitGlobal
                                         LibMain = 1   'success!
                                         'LibMain = 0   'failure!
                                        Exit Function
                                      Case %DLL_PROCESS_DETACH
                                         LibMain = 1   'success!
                                         'LibMain = 0   'failure!
                                        Exit Function
                                      Case %DLL_THREAD_ATTACH
                                         LibMain = 1   'success!
                                         'LibMain = 0   'failure!
                                        Exit Function
                                      Case %DLL_THREAD_DETACH
                                         LibMain = 1   'success!
                                         'LibMain = 0   'failure!
                                        Exit Function
                                    End Select
                                  End Function
                                  ------------------
                                  Fred
                                  mailto:[email protected][email protected]</A>
                                  http://www.oxenby.se

                                  Fred
                                  mailto:[email protected][email protected]</A>
                                  http://www.oxenby.se

                                  Comment


                                  • #37
                                    Fred;

                                    For arguments sake lets say you are right. Lets assume that the problem is with the Replace command.

                                    Lets look at this logically !


                                    The following code I assume is one of the places where the translation is getting trashed because of the replace command.

                                    Code:
                                    [b]Replace Any glbAscii With glbEbcdic In SJob$[/b]
                                    Now lets look at this command carefully:

                                    There are 4 possible causes for the command to return an incorrect string.

                                    (1) The string glbAscii may have been changed somehow.

                                    (2) The string glbEbcdic may have been changed somehow.

                                    (3) The string SJob$ may have been changed somehow.

                                    (4) The assembler code for the Replace command failed to do what it is supposed to do.

                                    Before "assuming" it is # 4, you have to verify that it isn't #1, #2 or #3.

                                    Now there needs to be some verification code to test all 4 possibilities:

                                    Code:
                                    #IF %EXTRA_TEST_CODE
                                       DIM Test_ERROR&, Test_L1&, SJob_bak$
                                       if glbAscii<>glbAscii_bak then Test_ERROR&=Test_ERROR& or 1
                                       if glbEbcdic<>glbEbcdic_bak then Test_ERROR&=Test_ERROR& or 2
                                       Test_L1&=len(SJob$)
                                       SJob_bak$=SJob$
                                    #ENDIF
                                    Replace Any glbAscii With glbEbcdic In SJob$
                                    #IF %EXTRA_TEST_CODE
                                       if Test_L1&<>len(SJob$) then  Test_ERROR&=Test_ERROR& or 4
                                       if glbAscii<>glbAscii_bak then Test_ERROR&=Test_ERROR& or 8
                                       if glbEbcdic<>glbEbcdic_bak then Test_ERROR&=Test_ERROR& or 16
                                       Replace Any glbAscii With glbEbcdic In SJob_bak$
                                       if SJob_bak$<>SJob$ then Test_ERROR&=Test_ERROR& or 32
                                       if Test_ERROR& then
                                           ' Each error is trapped in a bit value
                                           msgbox "Error Found - "+str(Test_ERROR&)
                                       end if
                                    #ENDIF
                                    By creating backup strings for your global conversion strings, you can test to see if the strings have changed. The likely hood of the both the original and the backup string changing exactly the same would be rare.

                                    Now this will temporarily slow down your code, but it is necessary to test out the problem. By using conditional compiling you can remove the unneeded code easily.

                                    Unlesss you test this out thoroughly, there is no way to be sure what is really happening. If you can prove that the variables glbAscii and glbEbcdic have not changed somehow and that the SJob$ variable is loaded with the correct data, then it is possible the replace command is to blame.

                                    Remember the old programming adage, "Garbage In, Garbage Out".


                                    ------------------
                                    Chris Boss
                                    Computer Workshop
                                    Developer of "EZGUI"
                                    http://cwsof.com
                                    http://twitter.com/EZGUIProGuy

                                    Comment


                                    • #38
                                      Alright boys, Its time to close this discussion.
                                      I admit that Replace is not failing and somwhere else
                                      in my program, in code not yet executed glbAscii is changed,
                                      to the contents of glbEbcdic. and then Replace is executed
                                      by some code I am going to write tomorrow.
                                      That could explain why the last part is in Ascii,
                                      and the first part is in Ebcdic.



                                      ------------------
                                      Fred
                                      mailto:[email protected][email protected]</A>
                                      http://www.oxenby.se

                                      Fred
                                      mailto:[email protected][email protected]</A>
                                      http://www.oxenby.se

                                      Comment


                                      • #39
                                        Fred --
                                        I wrote simple sub which replaces REPLACE ANY.
                                        To my surprise without any optimization it works 10-15 times faster than PB Replace Any.(at least, for your situation).
                                        I posted it in Source code' forum.


                                        [This message has been edited by Semen Matusovski (edited April 12, 2000).]

                                        Comment


                                        • #40
                                          There used to be something called "Garbage Collect", an internal Basic function that would cleanup string space by moving strings around.
                                          Back then I knew how this worked, I even found and patched a bug in GfA basic (for 680x0 machines) once. I never bothered to read up on how Windows manages this.

                                          To the point, would it be possible that some thread in that particular version of NT4 does a garbage collect while the replace code is running?
                                          That would also explain why it's never consistent, it would depend on whenever there's a context switch and at the same time the string pool approaches full.
                                          Maybe they even "improved" garbage collect by lowering the treshhold, making it complete faster each time, but running more often.

                                          This is just a thought, maybe Fred can check the STRPTR value before and after the REPLACE.


                                          Peter Manders


                                          ------------------
                                          [email protected]

                                          Comment

                                          Working...
                                          X