How to show the Windows File copying progress dialog throug PB? - api

I used the functions CopyFilea and ShFileOperation. CopyFileA it copied the file(large cumbersome data). but it didn't show the Copy Progress and Also tried in SHFileOperation api this shows the error.
PB Version is 10.2.0 build 7516
Error Msg: Error Calling external function %s
any body Please give me a solution?

There is a discussion of SHFileOperation on sybase.public.powerbuilder.general . This code block shows how to set up the structure correctly, for a delete operation in this case - does it help?
type os_shfileopstruct from structure
unsignedlong hwnd
unsignedlong wfunc
blob pfrom
blob pto
unsignedinteger fflags
unsignedlong banyoperationsaborted
unsignedlong hnamemappings
string lpszprogresstitle
end type
//inside a function call:
// Arguments: as_SourceFile - the file(s) to delete.
// aui_flags - file operation flags (0 - default)
// aw_requestor - the requesting window
os_shfileopstruct lstr_FileOp
Integer li_rc
lstr_FileOp.hWnd = Handle(aw_requestor)
lstr_FileOp.wFunc = FO_DELETE
lstr_FileOp.pFrom = Blob( as_SourceFile + Space(2) )
BlobEdit( lstr_FileOp.pFrom, Len( as_sourcefile ) + 1, Char(0) )
BlobEdit( lstr_FileOp.pFrom, Len( as_sourcefile ) + 2, Char(0) )
lstr_FileOp.fFlags = aui_flags
lstr_FileOp.hNameMappings = 0
lstr_FileOp.lpszProgressTitle = Space(10)
li_rc = SHFileOperationA( lstr_FileOp )
IF li_rc <> 0 THEN
IF NOT IsNull( lstr_FileOp ) THEN
IF lstr_FileOp.bAnyOperationsAborted = 1 THEN
RETURN 0
END IF
END IF
ELSE
-1
END IF
RETURN 1
from sybase.public.powerbuilder.general

What is your operating system? SHFileOperation has has been replaced in Windows Vista by IFileOperation.

Related

How to import unicode data from WinHttpReq

WinHttpRequest is used to import bank statement from Nordiget.com containing characters from Windows-1257 code page. For an unknown reason, FoxPro does replace accented characters with? signs. To fix this, COMPROP(WinHttpReq ,"UTF8",1) is added:
WinHttpReq = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")
WinHttpReq.Open("GET", "https://ob.nordigen.com/api/v2/accounts/11111-22222-333333-4444-/transactions/", .f.)
WinHttpReq.setrequestheader('accept', 'application/json')
WinHttpReq.setrequestheader('Authorization', "Bearer afde554a5sd45a45as4")
WinHttpReq.Send()
* If this is removed, accented characters appear as single question characters:
COMPROP(WinHttpReq ,"UTF8",1)
Response WinHttpReq.ResponseText contains accented characters represented by 4 bytes. The first 3 are the same but the fourth is different. Those characters are converted by code using
Function NordigetConvert(cStr)
cstr = strt( cStr, CHR(0xc3)+CHR(0x83)+ CHR(0xc2)+CHR(0x9c) , 'Ü' )
cstr = strt( cStr, CHR(0xc3)+CHR(0x83)+ CHR(0xc2)+CHR(0xBC) , 'ü' )
cstr = strt( cStr, CHR(0xc3)+CHR(0x83)+ CHR(0xc2)+CHR(0x84) , 'Ä' )
cstr = strt( cStr, CHR(0xc3)+CHR(0x83)+ CHR(0xc2)+CHR(0xB6) , 'ö' )
return cStr
This converts only ÜüÄö. There are much more characters to convert.
Tried
STRCONV(strconv(CHR(0xc3)+CHR(0x83)+ CHR(0xc2)+CHR(0x9c) ,10) ,11, 1257, 1)
this should return letter Ü but returns two question marks.
Tried also code below from https://github.com/VFPX/Win32API/blob/master/libraries/kernel32/WideCharToMultiByte.md
but it still returns two question marks.
How to convert it?
SET ECHO OFF
SET TALK OFF
CLEAR
#DEFINE CF_UNICODETEXT 13
DO decl
LOCAL hData, lcUnicode
MESSAGEBOX( uconv (CHR(0xc3)+CHR(0x83)+ CHR(0xc2)+CHR(0x9c), 1257) )
* end of main
FUNCTION uconv (lcSrc, lnCodePage)
LOCAL lcDst, lnUsedDefault, lnResult
lcDst = Repli(Chr(0), Len(lcSrc) * 2)
lnUsedDefault = 0
lnResult = WideCharToMultiByte (lnCodePage, 0,;
lcSrc, Len(lcSrc),;
#lcDst, Len(lcDst), "?", 0)
IF lnResult = 0
* 87 - ERROR_INVALID_PARAMETER
* 122 - ERROR_INSUFFICIENT_BUFFER
* 1004 - ERROR_INVALID_FLAGS
? "Error code:", GetLastError()
lcDst = ""
ELSE
lcDst = SUBSTR(lcDst, 1, lnResult)
ENDIF
RETURN SUBSTR(lcDst, 1, AT(Chr(0),lcDst)-1)
FUNCTION memwchar2str (lnMemBlock)
* copies Unicode characters (two-byte) from a memory address to a VFP string
RETURN mem2str(lnMemBlock, Chr(0)+Chr(0))
FUNCTION mem2str(lnMemBlock, end_sequence)
#DEFINE BUFFER_SIZE 16
#DEFINE EMPTY_BUFFER Repli(Chr(0), BUFFER_SIZE)
DECLARE RtlMoveMemory IN kernel32 As Heap2Str;
STRING #, INTEGER, INTEGER
LOCAL lnPtr, lcResult, lcBuffer, lnPos
lnPtr = lnMemBlock
lcResult = ""
DO WHILE .T.
lcBuffer = EMPTY_BUFFER
= Heap2Str (#lcBuffer, lnPtr, BUFFER_SIZE)
lnPos = AT(end_sequence, lcBuffer)
IF lnPos > 0
lcResult = lcResult + SUBSTR(lcBuffer, 1, lnPos-1)
RETURN lcResult
ELSE
lcResult = lcResult + lcBuffer
lnPtr = lnPtr + BUFFER_SIZE
ENDIF
ENDDO
PROCEDURE decl
DECLARE INTEGER GetLastError IN kernel32
DECLARE INTEGER OpenClipboard IN user32 INTEGER hwnd
DECLARE INTEGER CloseClipboard IN user32
DECLARE INTEGER GetClipboardData IN user32 INTEGER uFormat
DECLARE INTEGER IsClipboardFormatAvailable IN user32 INTEGER wFormat
DECLARE INTEGER WideCharToMultiByte IN kernel32;
INTEGER CodePage, INTEGER dwFlags, STRING lpWideCharStr,;
INTEGER cchWideChar, STRING #lpMultiByteStr, INTEGER cbMultiByte,;
STRING lpDefaultChar, INTEGER lpUsedDefaultChar

Get number from Excel column

I'm am using the code example below to represent an integer as an alphabetic string
Private Function GetExcelColumnName(columnNumber As Integer) As String
Dim dividend As Integer = columnNumber
Dim columnName As String = String.Empty
Dim modulo As Integer
While dividend > 0
modulo = (dividend - 1) Mod 26
columnName = Convert.ToChar(65 + modulo).ToString() & columnName
dividend = CInt((dividend - modulo) / 26)
End While
Return columnName
End Function
I found the above example here:
Converting Numbers to Excel Letter Column vb.net
How do I get the reverse, for example:
123 = DS -- Reverse -- DS = 123
35623789 = BYXUWS -- Reverse -- BYXUWS = 35623789
Is it possible to get the number from the alphabetic string without importing Excel?
I found an answer from another post. This function below will work to get the reverse
Public Function GetCol(c As String) As Long
Dim i As Long, t As Long
c = UCase(c)
For i = Len(c) To 1 Step -1
t = t + ((Asc(Mid(c, i, 1)) - 64) * (26 ^ (Len(c) - i)))
Next i
GetCol = t
End Function

Round values by either to 5 or 9

I have to format some decimal values into specific logic. I would like to round input values always into either to 5 or 9. How can i accomplish that easiest way, is there any function already? Below find examples what i am trying to reach. On the left are some input values and on the right are output i would like to achieve. Is there any easy way to do so?
Input Formatted
------ ----------
614,46 = 615,00
614,57 = 615,00
615,01 = 619,00
616,57 = 619,00
91,11 = 95,00
96,11 = 99,00
89,25 = 95,00
There is nothing build in for your case but you can easily implement it by your own:
Public Sub Main()
Console.WriteLine("{0:N2}", myFlor(614.46))
Console.WriteLine("{0:N2}", myFlor(614.57))
Console.WriteLine("{0:N2}", myFlor(615.01))
Console.WriteLine("{0:N2}", myFlor(616.57))
Console.WriteLine("{0:N2}", myFlor(91.11 ))
Console.WriteLine("{0:N2}", myFlor(96.11 ))
Console.WriteLine("{0:N2}", myFlor(89.25 ))
End Sub
Function myFlor(ByVal value As Double) As Double
Dim base as Integer
base = Math.Truncate(value / 10) *10
If value - base > 9
' Handle 9.01 -9.99 case
Return base + 15
ElseIf value - base > 5
Return base + 9
Else
Return base + 5
End If
End Function
If I understand correctly you need to use Ceiling method to returns the smallest integer greater than or equal to the specified number and then round this integer to the nearest 5 or 9.
I don't think you can obtain this behaviour without writing your own function:
Private Function intRoundTo5Or9(ByVal dblNumber As Double) As Integer
Dim intLastDigit As Integer = CInt(Math.Ceiling(dblNumber).ToString().Substring(Math.Ceiling(dblNumber).ToString().Length - 1, 1))
If intLastDigit <= 5 Then
Return Math.Ceiling(dblNumber) + 5 - intLastDigit
Else
Return Math.Ceiling(dblNumber) + 9 - intLastDigit
End If
End Function

Lua table.toString(tableName) and table.fromString(stringTable) functions?

I am wanting to convert a 2d lua table into a string, then after converting it to a string convert it back into a table using that newly created string. It seems as if this process is called serialization, and is discussed in the below url, yet I am having a difficult time understanding the code and was hoping someone here had a simple table.toString and table.fromString function
http://lua-users.org/wiki/TableSerialization
I am using the following code in order to serialize tables:
function serializeTable(val, name, skipnewlines, depth)
skipnewlines = skipnewlines or false
depth = depth or 0
local tmp = string.rep(" ", depth)
if name then tmp = tmp .. name .. " = " end
if type(val) == "table" then
tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
for k, v in pairs(val) do
tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
end
tmp = tmp .. string.rep(" ", depth) .. "}"
elseif type(val) == "number" then
tmp = tmp .. tostring(val)
elseif type(val) == "string" then
tmp = tmp .. string.format("%q", val)
elseif type(val) == "boolean" then
tmp = tmp .. (val and "true" or "false")
else
tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
end
return tmp
end
the code created can then be executed using loadstring(): http://www.lua.org/manual/5.1/manual.html#pdf-loadstring if you have passed an argument to 'name' parameter (or append it afterwards):
s = serializeTable({a = "foo", b = {c = 123, d = "foo"}})
print(s)
a = loadstring(s)()
The code lhf posted is a much simpler code example than anything from the page you linked, so hopefully you can understand it better. Adapting it to output a string instead of printing the output looks like:
t = {
{11,12,13},
{21,22,23},
}
local s = {"return {"}
for i=1,#t do
s[#s+1] = "{"
for j=1,#t[i] do
s[#s+1] = t[i][j]
s[#s+1] = ","
end
s[#s+1] = "},"
end
s[#s+1] = "}"
s = table.concat(s)
print(s)
The general idea with serialization is to take all the bits of data from some data structure like a table, and then loop through that data structure while building up a string that has all of those bits of data along with formatting characters.
How about a JSON module? That way you have also a better exchangeable data. I usually prefer dkjson, which also supports utf-8, where cmjjson won't.
Under the kong works this
local cjson = require "cjson"
kong.log.debug(cjson.encode(some_table))
Out of the kong should be installed package lua-cjson https://github.com/openresty/lua-cjson/
Here is a simple program which assumes your table contains numbers only. It outputs Lua code that can be loaded back with loadstring()(). Adapt it to output to a string instead of printing it out. Hint: redefine print to collect the output into a table and then at the end turn the output table into a string with table.concat.
t = {
{11,12,13},
{21,22,23},
}
print"return {"
for i=1,#t do
print"{"
for j=1,#t[i] do
print(t[i][j],",")
end
print"},"
end
print"}"
Assuming that:
You don't have loops (table a referencing table b and b referencing a)
Your tables are pure arrays (all keys are consecutive positive integers, starting on 1)
Your values are integers only (no strings, etc)
Then a recursive solution is easy to implement:
function serialize(t)
local serializedValues = {}
local value, serializedValue
for i=1,#t do
value = t[i]
serializedValue = type(value)=='table' and serialize(value) or value
table.insert(serializedValues, serializedValue)
end
return string.format("{ %s }", table.concat(serializedValues, ', ') )
end
Prepend the string resulting from this function with a return, store it on a .lua file:
-- myfile.lua
return { { 1, 2, 3 }, { 4, 5, 6 } }
You can just use dofile to get the table back.
t = dofile 'myfile.lua'
Notes:
If you have loops, then you will have
to handle them explicitly - usually with an extra table to "keep track" of repetitions
If you don't have pure arrays, then
you will have to parse t differently,
as well as handle the way the keys are rendered (are they strings? are they other tables? etc).
If you have more than just integers
and subtables, then calculating
serializedValue will be more
complex.
Regards!
I have shorter code to convert table to string but not reverse
function compileTable(table)
local index = 1
local holder = "{"
while true do
if type(table[index]) == "function" then
index = index + 1
elseif type(table[index]) == "table" then
holder = holder..compileTable(table[index])
elseif type(table[index]) == "number" then
holder = holder..tostring(table[index])
elseif type(table[index]) == "string" then
holder = holder.."\""..table[index].."\""
elseif table[index] == nil then
holder = holder.."nil"
elseif type(table[index]) == "boolean" then
holder = holder..(table[index] and "true" or "false")
end
if index + 1 > #table then
break
end
holder = holder..","
index = index + 1
end
return holder.."}"
end
if you want change the name just search all compileTable change it to you preferred name because this function will call it self if it detect nested table but escape sequence I don't know if it work
if you use this to create a lua executable file that output the table it will ge compilation error if you put new line and " sequence
this method is more memory efficient
Note:
Function not supported
User data I don't know
My solution:
local nl = string.char(10) -- newline
function serialize_list (tabl, indent)
indent = indent and (indent.." ") or ""
local str = ''
str = str .. indent.."{"
for key, value in pairs (tabl) do
local pr = (type(key)=="string") and ('["'..key..'"]=') or ""
if type (value) == "table" then
str = str..nl..pr..serialize_list (value, indent)..','
elseif type (value) == "string" then
str = str..nl..indent..pr..'"'..tostring(value)..'",'
else
str = str..nl..indent..pr..tostring(value)..','
end
end
str = str:sub(1, #str-1) -- remove last symbol
str = str..nl..indent.."}"
return str
end
local str = serialize_list(tables)
print('return '..nl..str)

Need VB code commented to convert it to Java

I am a Java developer. I have the task of converting a VB class to Java.
Can some VB developer comment the following VB code so that I can write its Java equivalent?
Public Class RmaValidationCode
' Values for test type
Public Const SOFTWARE_TEST_TYPE = 0
Public Const FIRMWARE_TEST_TYPE = 1
' Values for test length
Public Const SHORT_TEST_LENGTH = 0
Public Const LONG_TEST_LENGTH = 1
' Values for test result
Public Const PASS_TEST_RESULT = 0
Public Const FAIL_TEST_RESULT = 1
Public Const ABORT_TEST_RESULT = 2
Public Const CAUTION_TEST_RESULT = 3
' GetRMAValidationCode function bit mapped return values
Public Const RMA_VC_RET_PASS = 0
Public Const RMA_VC_RET_NULL_PTR_PARAMETER = 1
Public Const RMA_VC_RET_INVALID_STR_LENGTH = 2
Public Const RMA_VC_RET_INVALID_SN_STRING = 4
Public Const RMA_VC_RET_INVALID_TEST_TYPE = 8
Public Const RMA_VC_RET_INVALID_TEST_LENGTH = 16
Public Const RMA_VC_RET_INVALID_TEST_RESULT = 32
Private Const RMA_LENGTH = 8
Private rmaValidationCode As String
' This function will return the warranty validation code based on serial number, test type,
' test result, test software and test length.
' Test type - Generic=0, DST=1
' Test result - Pass=0, FAIL=1
' Test Software - DOS=0, Windows=1
' Test Length - Short=0 Long=1
Public Function GetRMAValidationCode(ByVal serialNumber As String, ByVal testType As Byte, _
ByVal testResult As Byte, ByVal testSoftware As Byte, ByVal testLength As Byte)
Dim returnValue As UInt32
Dim tempRMACode As String
Dim tempRMAEnumerator As CharEnumerator
Dim temp8Bit As Byte
returnValue = RMA_VC_RET_PASS
temp8Bit = 0
' Make sure we were passed valid strings
If String.IsNullOrEmpty(serialNumber) OrElse _
String.IsNullOrEmpty(rmaValidationCode) Then
returnValue = returnValue Or RMA_VC_RET_NULL_PTR_PARAMETER
End If
' Make sure our strings are big enough
If serialNumber.Length < RMA_LENGTH OrElse _
rmaValidationCode.Length < RMA_LENGTH Then
returnValue = returnValue Or RMA_VC_RET_INVALID_STR_LENGTH
End If
' Assure that valid test types were passed in
If testType <> SOFTWARE_TEST_TYPE AndAlso _
testType <> FIRMWARE_TEST_TYPE Then
returnValue = returnValue Or RMA_VC_RET_INVALID_TEST_TYPE
End If
' Assure that valid test lengths were passed in
If testLength <> SHORT_TEST_LENGTH AndAlso _
testLength <> LONG_TEST_LENGTH Then
returnValue = returnValue Or RMA_VC_RET_INVALID_TEST_LENGTH
End If
' Assure that valid test results were passed in
If testResult <> PASS_TEST_RESULT AndAlso _
testResult <> FAIL_TEST_RESULT AndAlso _
testResult <> ABORT_TEST_RESULT AndAlso _
testResult <> CAUTION_TEST_RESULT Then
returnValue = returnValue Or RMA_VC_RET_INVALID_TEST_RESULT
End If
If returnValue = RMA_VC_RET_PASS Then
' Trim leading and trailing whitespace
serialNumber.Trim()
' Check to see if the serialNumber string is long enough
' after whitespace is removed
If serialNumber.Length < RMA_LENGTH Then
Return RMA_VC_RET_INVALID_SN_STRING
End If
tempRMACode = serialNumber.ToLower()
tempRMAEnumerator = tempRMACode.GetEnumerator()
While (tempRMAEnumerator.MoveNext())
If Not Char.IsLetterOrDigit(tempRMAEnumerator.Current) Then
Return RMA_VC_RET_INVALID_SN_STRING
End If
End While
' Initialize the rmaValidationCode
rmaValidationCode = ""
' Compute and save the first 6 bytes of RMA Validation Code
temp8Bit = 0
temp8Bit = Convert.ToByte(tempRMACode.ToCharArray().GetValue(0)) + Convert.ToByte((tempRMACode.ToCharArray()).GetValue(7))
rmaValidationCode += String.Format("{0:X2}", temp8Bit)
temp8Bit = 0
temp8Bit = Convert.ToByte((tempRMACode.ToCharArray()).GetValue(1)) + Convert.ToByte((tempRMACode.ToCharArray()).GetValue(6))
rmaValidationCode += String.Format("{0:X2}", temp8Bit)
temp8Bit = 0
temp8Bit = Convert.ToByte((tempRMACode.ToCharArray()).GetValue(2)) + Convert.ToByte((tempRMACode.ToCharArray()).GetValue(5))
rmaValidationCode += String.Format("{0:X2}", temp8Bit)
' Byte 6 is the Test & Result byte.
temp8Bit = 0
temp8Bit = (testSoftware << 3) Or (testResult << 2) Or (testType << 1) Or testLength
rmaValidationCode += String.Format("{0:X1}", temp8Bit)
' Compute the parity byte
temp8Bit = 0
Dim mychar As Char
mychar = rmaValidationCode.ToCharArray().GetValue(3)
If ((Convert.ToInt32(rmaValidationCode.ToCharArray().GetValue(3), 16) Mod 2) = 1) Then
temp8Bit = temp8Bit Or (1 << 3)
Else
temp8Bit = temp8Bit Or (0 << 3)
End If
Dim value As Integer
mychar = rmaValidationCode.ToCharArray().GetValue(2)
value = System.Convert.ToInt32(mychar, 16)
If ((Convert.ToInt32(rmaValidationCode.ToCharArray().GetValue(2), 16) Mod 2) = 1) Then
temp8Bit = temp8Bit Or (1 << 2)
Else
temp8Bit = temp8Bit Or (0 << 2)
End If
mychar = rmaValidationCode.ToCharArray().GetValue(1)
If ((Convert.ToInt32(rmaValidationCode.ToCharArray().GetValue(1), 16) Mod 2) = 1) Then
temp8Bit = temp8Bit Or (1 << 1)
Else
temp8Bit = temp8Bit Or (0 << 1)
End If
mychar = rmaValidationCode.ToCharArray().GetValue(0)
If ((Convert.ToInt32(rmaValidationCode.ToCharArray().GetValue(0), 16) Mod 2) = 1) Then
temp8Bit = temp8Bit Or 1
Else
temp8Bit = temp8Bit Or 0
End If
rmaValidationCode += String.Format("{0:X1}", temp8Bit)
End If
Return rmaValidationCode
End Function
Public Sub New()
' serialNumber = " "
rmaValidationCode = " "
' testType = 0
'testLength = 0
'testResult = 0
End Sub
End Class
Actually that is pretty readable and straightforward code. You may want to take a look at VB keywords as well as the AndAlso/OrElse operators (those two sometimes confuse C-style language developers). The rest that's used are just plain old .NET class library methods. Nothing too fancy and you'll find plenty of documentation about those on MSDN.
Unfortunately you're not going to find anyone here that will comment the above code for free.
Visual Basic syntax is relatively simple - it was designed as an entry level language. If you engage your mind and read over the general key words such as AndAlso OrElse WhileNot etc, you shouldn't have a massive issue commenting it yourself.
If you were further interested in the way the code works - the way I usually learn to understand X piece of code is to go step - by - step through it until I finally get the gist of it.
Try searching MSDN for any keywords you don't fully understand.