I have a problem with get-value() method in progress4GL.
I am trying to get all values from html form.
My Progress4GL Code looks like:
for each tt:
do k = 1 to integer(h-timeframe):
h-from [k] = get-value(string(day(tt.date)) + "#" + string(tt.fnr) + "#" + string(tt.pnr) + "_von" + string(k)).
h-to [k] = get-value(string(day(tt.date)) + "#" + string(tt.fnr) + "#" + string(tt.pnr) + "_bis" + string(k)).
h-code [k] = get-value(string(day(tt.date)) + "#" + string(tt.fnr) + "#" + string(tt.pnr) + "_code" + string(k)).
end.
end.
h-timeframe is parameter and could be max. 10. (1-10)
tt is a temp-table and represents a week(fix 7 days)
It works perfectly till 9.Parameter. If I choose the 10 (which is max) then I get some performance Problem using get-value() Function.
Example when h-timeframe = 10:
as you can see from one get-value to another It takes really long time.( h-timeframe = 10 )
Example when h-timeframe = 9:
and here way much faster than other.
Can anyone explain why ? It is really strange and I have no Idea.
p.s: I have this problem just at 10. 0-9 It works perfectly
The performance difference is probably something external to your code snippet but, for performance, I would write it more like this:
define variable d as integer no-undo.
define variable n as integer no-undo.
define variable s as character no-undo.
for each tt:
// avoid recalculating and invoking functions N times per TT record
assign
d = day( tt.date )
n = integer( h-timeframe )
s = substitute( "&1#&2#&3_&&1&&2", d, tt.fnr, tt.pnr )
.
do k = 1 to n:
// consolidate multiple repeated operations, eliminate STRING() calls
assign
h-from [k] = get-value( substitute( s, "von", k ))
h-to [k] = get-value( substitute( s, "bis", k ))
h-code [k] = get-value( substitute( s, "code", k ))
.
end.
end.
I am trying to compare the input string with the strings present in the doc. I am using strcmp for the purpose. These are non-English strings. When the input string is English language, the output is correct. But for any Kannada (non-English language) word the output is the same. I am trying to write a program to check if the word is present in the database. Please guide me in what could be the problem.
The calling function is as below:
str_kan = handles.InputBox.String;
res = strcmp('str_kan','s1.text')
if res == 1 then handles.InputBox.String = string( ' present')
abort
else
handles.InputBox.String = string( 'not present')
abort
end
The whole program is as below:
global s1
f=figure('figure_position',[400,50],'figure_size',[640,480],'auto_resize','on','background',[33],'figure_name','Graphic window number %d','dockable','off','infobar_visible','off','toolbar_visible','off','menubar_visible','off','default_axes','on','visible','off');
handles.dummy = 0;
handles.InputBox=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tunga','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.0929487,0.6568182,0.4647436,0.1795455],'Relief','default','SliderStep',[0.01,0.1],'String','Enter a Kannada Word','Style','edit','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','InputBox','Callback','')
handles.CheckDB=uicontrol(f,'unit','normalized','BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight','normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.1025641,0.4636364,0.4567308,0.1204545],'Relief','default','SliderStep',[0.01,0.1],'String','Check','Style','pushbutton','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','CheckDB','Callback','CheckDB_callback(handles)')
f.visible = "on";
function CheckDB_callback(handles)
str_kan = handles.InputBox.String;
res = strcmp('str_kan','s1.text')
if res == 1 then handles.InputBox.String = string( ' present')
abort
else
handles.InputBox.String = string( 'not present')
abort
end
endfunction
Here is an example showing that, in Scilab, strcmp() does support UTF-8 extended characters:
--> strcmp(["aα" "aα" "aβ"], ["aα" "aβ" "aα"])
ans =
0. -1. 1.
The problem in the original posted code is the confusion between literal values as "Hello" and variables names as Hello="my text", as already noted by PTRK.
I have a simple function fact() to print factorial of a number which is to input at runtime.
Everything works fine ata this code given below.
# Find factorial of a number...
def fact():
number = int(input('Please enter a number: '))
tmp = 1
while number > 0:
tmp *= number
number -= 1
print(tmp)
ask = input('Do you want to try again... [y/n]: ')
if ('y' or 'Y') in ask:
fact()
else:
print('Thank you for using my tool. Good bye')
fact()
But if I add some string in first print() function I get syntax error for the line "ask = input...". Here is the code below.
# Find factorial of a number...
def fact():
number = int(input('Please enter a number: '))
tmp = 1
while number > 0:
tmp *= number
number -= 1
print("Factorial of %d is %d" %(number, tmp)
ask = input('Do you want to try again... [y/n]: ')
if ('y' or 'Y') in ask:
fact()
else:
print('Thank you for using my tool. Good bye')
fact()
I have one last problem. My program asks me if I want to try again. If I type y and enter, in works as it should be. But if I type Y, it exicute else statement.
I am using python3.6.4rc1 in Debian.
this should work!
def fact():
number = int(input("Please enter a number: "))
tmp = 1
while number > 0:
tmp *= number
number -= 1
print("Factorial of %d is %d" %(number, tmp))
ask = input("Do you want to try again... [y/n]: ")
if ask in ['y','Y']:
fact()
else:
print('Thank you for using my tool. Good bye')
fact()
I had to preserve value of number variable as it will become 0 at end of loop. Otherwise my program will print Modulas of 0 is 'some_number. Now I have the correct code...
def fact():
number = int(input("Please enter a number: "))
preserve_number = number
tmp = 1
while number > 0:
tmp *= number
number -= 1
print("Factorial of %d is %d" %(preserve_number, tmp))
ask = input("Do you want to try again... [y/n]: ")
if ask in ['y','Y']:
fact()
else:
print('Thank you for using my tool. Good bye')
fact()
I am trying to encrypt a message but if I use the letter Z it gives an error. This is the error (it's Dutch):
Set x = WScript.CreateObject("WScript.Shell")
mySecret = InputBox("The code")
mySecret = StrReverse(mySecret)
x.Run "%windir%\notepad"
WScript.Sleep 1000
x.SendKeys encode(mySecret)
Function encode(s)
For i = 1 To Len(s)
newtxt = Mid(s, i, 1)
newtxt = Chr(Asc(newtxt)+3)
coded = coded & newtxt
Next
encode = coded
End Function
The docs for SendKeys state:
Brackets "[ ]" have no special meaning when used with SendKeys, but
you must enclose them within braces to accommodate applications that
do give them a special meaning (for dynamic data exchange (DDE) for
example).
Your encoding method:
>> WScript.Echo Chr(Asc("Z") + 3)
>> WScript.Echo Chr(Asc("X") + 3)
>>
]
[
>>
generates brackets for Z and X.
After further testing:
The nasty letters are not (uppercase) X ([) and Z (]) but their lowercase cousins:
docs:
To send brace characters, send the string argument "{{}" for the left
brace and "{}}" for the right one.
evidence:
>> set x = WScript.CreateObject("WScript.Shell")
>> x.sendkeys Chr(Asc("z") + 3)
>>
Error Number: 5
Error Description: Invalid procedure call or argument
>> x.sendkeys Chr(Asc("x") + 3)
>>
Error Number: 5
Error Description: Invalid procedure call or argument
>>
What i want is to retrieve quantity in database from piece and covert it to dozen. Then input as dozen and convert back to pieces and save to database again.
when I input data eg. 10.3, it should convert to 123 piece for me ((10 * 12) + 3). My code work well without my "If clause" but only when data was "single" type. It made error when I input integer number, so I added "If.." statement to check it first which is now the output was correct for Integer but incorrect when I input single number.
I have this code..
Function DzToPcs(val)
'If CLng(val) = val then <-- not work
'if Fix(val) <> val then <-- work but the output was not correct when input single type number.
if Int(vInt) = vInt then <-- work but the output was not correct when input single type number.
DztoPcs = val * 12
else
strInt = Cstr(val)
a = Split(strInt,".")
dz = a(0)
pcs = a(1)
getdz = Cint(dz)
getpcs = Cint(pcs)
DztoPcs = (getdz * 12) + getpcs
end if
I'm not sure what's wrong with your if statements (my VBScript is a little rusty), but you could try this alternative:
Function DzToPcs(val)
strInt = Cstr(val)
a = Split(strInt,".")
dz = a(0)
if UBound(a) > 0 then
pcs = a(1)
getdz = Cint(dz)
getpcs = Cint(pcs)
DztoPcs = (getdz * 12) + getpcs
else
DztoPcs = dz * 12
end if
end function