1. Jeong Dae Ryong
  2. PowerBuilder
  3. Tuesday, 23 January 2024 06:31 AM UTC

I'm migrating to PowerBuilder 2022.
This is a phrase I used previously.


blob ab_data

FileOpen(as_filename,StreamMode!,Write!,LockWrite!,Replace!,EncodingANSI!)

ls_body = 'aaaa'

ab_data = blob(ls_body,EncodingANSI!)

IF FileWriteEX(li_FileNum, ab_data) = -1 THEN
    MessageBox("Error", "Write Error")
    FileClose(li_FileNum)
return false
END IF

As above, with EncodingAnSi!
Define the format and create the file
There is no text in the file.
Encodingutf8! If you do this, the file will be created normally.
Why is the logic that worked well in 2019 not working?

 

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 23 January 2024 13:36 PM UTC
  2. PowerBuilder
  3. # 1

Hi Jeong;

   Are you using the latest release of PB (PB 2022 R3)?

Regards ... Chris 

Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 24 January 2024 00:07 AM UTC
FYI: R3 went production at the beginning of January.
  1. Helpful
  1. Jeong Dae Ryong
  2. Wednesday, 24 January 2024 00:20 AM UTC
Download Booster Trap

You can download it only until 2022 R2.
  1. Helpful
  1. Jeong Dae Ryong
  2. Wednesday, 24 January 2024 00:21 AM UTC
What you said is in 2022 R2

Does this mean it can't be done and is possible in 2022 R3?
  1. Helpful
There are no comments made yet.
Marco Meoni Accepted Answer Pending Moderation
  1. Tuesday, 23 January 2024 17:20 PM UTC
  2. PowerBuilder
  3. # 2

hi,

you forgot to save the filenumber.

li_FileNum = FileOpen(as_filename,StreamMode!,Write!,LockWrite!,Replace!,EncodingANSI!)

Best,

.m

 

Comment
  1. Jeong Dae Ryong
  2. Wednesday, 24 January 2024 00:05 AM UTC
Of course, it is written as follows.

li_FileNum = FileOpen(as_filename,StreamMode!,Write!,LockWrite!,Replace!,EncodingANSI!)
  1. Helpful
There are no comments made yet.
Jeong Dae Ryong Accepted Answer Pending Moderation
  1. Wednesday, 24 January 2024 00:44 AM UTC
  2. PowerBuilder
  3. # 3

Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 24 January 2024 01:18 AM UTC
Wrong installer. Try this one ...

https://account.appeon.com/download

R3 is the 1st one listed.
  1. Helpful
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Wednesday, 24 January 2024 07:39 AM UTC
  2. PowerBuilder
  3. # 4

Hi.

I tested the following code and it works fine in PB 2022 R2 (2819 & 2828) and PB 2022 R3 (3289).

integer li_FileNum
string ls_body, ls_filename = 'C:\Tests\bintest.bin'
blob ab_data

if fileexists(ls_filename) then
	filedelete(ls_filename)
end if

li_FileNum = FileOpen(ls_filename,StreamMode!,Write!,LockWrite!,Replace!,EncodingANSI!)

if li_filenum > 0 then
	ls_body = 'aaaa'
	
	ab_data = blob(ls_body,EncodingANSI!)
	
	IF FileWriteEX(li_FileNum, ab_data) = -1 THEN
		 MessageBox("Error", "Write Error")
	END IF
	
	FileClose(li_FileNum)
else
	messagebox("Error:", "Could not open file: " + ls_filename)
end if

All test where done using PB 2022 R3 (3289) IDE.

Andreas.

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 24 January 2024 19:50 PM UTC
  2. PowerBuilder
  3. # 5

Hi Jeong;

   Ahhhh ... I think that I see your issue - its the use of the Replace! argument in your FileOpen() command.

Note that when MS-Windows encounters an existing file of that name it will not change the encoring scheme. Instead, it will use the current encoding scheme of the existing file that already exists. Thus, you "think" that your file encoding scheme was changed to Z but it's still the original X format.   HTH

Regards ... Chris 

Comment
  1. Benjamin Gaesslein
  2. Thursday, 25 January 2024 13:16 PM UTC
This is easily testable by creating a new file using FileOpen w/ EncodingAnsi!, writing the String "FakeBOMÄÖÜ:)" to this file, close it, and try to open it again using EncodingAnsi!

 is the UTF-8 BOM bytes interpreted as Windows-1252 (widely but incorrectly known as "ANSI") character data, which proves that FileOpen() does open the file just fine but rejects it based on the first three bytes despite the actual text encoding being "ANSI".
  1. Helpful
  1. Chris Pollach @Appeon
  2. Thursday, 25 January 2024 13:34 PM UTC
As a test to change the encoding, try doing an IF FileExits () followed by a FileDelete() before the FileOpen().

BTW: I encountered this windows O/S phenomenon way back in the W95 days. AFAIK it's still the same in W11.
  1. Helpful 1
  1. Benjamin Gaesslein
  2. Thursday, 25 January 2024 14:35 PM UTC
It has nothing to do with the OS, it's 100% PBs internal logic.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.