Array changes value from string to number - autohotkey

I'm trying to assign a hex color value to an array. This is not possible, because when I assign the value, it is changed to a number. Here is the code that does that:
settings := {myColor: "color"}
myColor := "color"
settingName := "myColor"
settingValue := "0x00FF00"
%settingName% := settingValue
settings[settingName] := settingValue
e := settings[settingName]
MsgBox %e% - %settingValue%
;Displays 65280 - 0x00FF00

I think you went wrong in the 5th code line. Variables that you define do not get % signs.
settings := {myColor: "color"}
myColor := "color"
settingName := "myColor"
settingValue := "0x00FF00"
settingName = %settingValue% ; Alternative 1
settingName := settingValue ; Alternative 2
settings[settingName] := settingValue
e := settings[settingName]
MsgBox % e " - " settings[settingName] " - " settingValue
;Displays 0x00FF00 - 0x00FF00 - 0x00FF00
ExitApp
Though I think that you want: Settings[MyColor] = 0x00FF00, you now have Settings[0x00FF00] = 0x00FF00.
settings := {myColor: "color"}
myColor := "color"
settingName := "myColor"
settingValue := "0x00FF00"
settings[settingName] := settingValue
MsgBox % settings[settingName] " - " settingValue
;Displays 0x00FF00 - 0x00FF00
ExitApp

Related

how to use count and or expression at same time golang mongodb?

hi i write this line of codes but when i try it just return when total is greater then number i gave and it just doesn't use checked . i mean i have 6 documants and 5 of them are true but it give me 6 reuslt !
checked := bson.D{{"$or", []interface{}{bson.D{{"checked", false}}, bson.D{{"checked", nil}}}}}
totalReport := bson.D{{"total", bson.D{{"$gte", config.ReportNumberToChangeNickname}}}}
totalReportAndChecked := bson.D{{"$and", []interface{}{checked, totalReport}}}
matchStage := bson.D{{"$match", totalReportAndChecked}}
groupStage := bson.D{{"$group", bson.D{{"_id", "$user_id"}, {"total", bson.D{{"$sum", 1}}}}}}
cursor, err := UserReportDb.Aggregate(ctx, mongo.Pipeline{groupStage, matchStage})
if err != nil {
fmt.Println(err)
return &mongo.Cursor{}, err
}
i found the answer thanks
cond := bson.D{{"$cond", []interface{}{"$checked", 0, 1}}}
matchStage := bson.D{{"$match", bson.D{{"$expr", bson.D{{"$gte", []interface{}{"$total", config.ReportNumberToChangeNickname}}}}}}}
groupStage := bson.D{{"$group", bson.D{{"_id", "$user_id"}, {"total", bson.D{{"$sum", cond}}}, {"value", bson.D{{"$last", "$value"}}}}}}
cursor, err := UserReportDb.Aggregate(ctx, mongo.Pipeline{groupStage, matchStage})

Delphi - Rich edit doesn't show on dynamically created form

I've dynamically created a Form in my program, and it works and shows perfectly, but the RichEdit I've also dynamically created doesn't want to show on the Form at all. How can I show the RichEdit on the Form?
Code I'm using:
procedure TfrmPuntehou.lblAbbClick(Sender: TObject);
var
frmAbb: TForm;
redAbbreviations: TRichEdit;
begin
//opens abbreviations
frmAbb := TForm.Create(nil);
redAbbreviations := TRichEdit.Create(nil);
try
with frmAbb do
begin
Width := 400;
Height := 400;
Caption := 'Abbreviations';
Position := poOwnerFormCenter;
ShowModal;
end;
with redAbbreviations do
begin
Parent := frmAbb;
Width := 300;
Height := 353;
redAbbreviations.Paragraph.TabCount := 2;
redAbbreviations.Paragraph.Tab[0] := 30;
redAbbreviations.Paragraph.Tab[1] := 60;
Lines.Add('DEV'+#9+'='+#9+'SWD Development');
Lines.Add('1660'+#9+'='+#9+'1660s');
Lines.Add('2.1'+#9+'='+#9+'2.1s');
Lines.Add('MIN'+#9+'='+#9+'Minis');
Lines.Add('SR'+#9+'='+#9+'Stockrods');
Lines.Add('PR'+#9+'='+#9+'Pinkrods');
Lines.Add('HR'+#9+'='+#9+'Hotrods');
Lines.Add('HM'+#9+'='+#9+'Heavy Metals');
Lines.Add('V8'+#9+'='+#9+'V8s');
Lines.Add('MA'+#9+'='+#9+'Midgets A');
Lines.Add('MB'+#9+'='+#9+'Midgets B');
Lines.Add('SP'+#9+'='+#9+'Sprints');
Lines.Add('CRO'+#9+'='+#9+'Crosskarts');
Lines.Add('LM'+#9+'='+#9+'Late Models');
Font.Size := 13;
end;
finally
frmAbb.Free;
end;
end;
Move the ShowModal from the initialization part of the frmAbb to the end of the code, just before the finally statement.
procedure TForm1.Button1Click(Sender: TObject);
var
frmAbb: TForm;
redAbbreviations: TRichEdit;
begin
//opens abbreviations
frmAbb := TForm.Create(nil);
try
redAbbreviations := TRichEdit.Create(frmAbb);
with frmAbb do
begin
Width := 400;
Height := 400;
Caption := 'Abbreviations';
Position := poOwnerFormCenter;
end;
with redAbbreviations do
begin
Parent := frmAbb;
Width := 300;
Height := 353;
redAbbreviations.Paragraph.TabCount := 2;
redAbbreviations.Paragraph.Tab[0] := 30;
redAbbreviations.Paragraph.Tab[1] := 60;
Lines.Add('DEV'+#9+'='+#9+'SWD Development');
Lines.Add('1660'+#9+'='+#9+'1660s');
Lines.Add('2.1'+#9+'='+#9+'2.1s');
Lines.Add('MIN'+#9+'='+#9+'Minis');
Lines.Add('SR'+#9+'='+#9+'Stockrods');
Lines.Add('PR'+#9+'='+#9+'Pinkrods');
Lines.Add('HR'+#9+'='+#9+'Hotrods');
Lines.Add('HM'+#9+'='+#9+'Heavy Metals');
Lines.Add('V8'+#9+'='+#9+'V8s');
Lines.Add('MA'+#9+'='+#9+'Midgets A');
Lines.Add('MB'+#9+'='+#9+'Midgets B');
Lines.Add('SP'+#9+'='+#9+'Sprints');
Lines.Add('CRO'+#9+'='+#9+'Crosskarts');
Lines.Add('LM'+#9+'='+#9+'Late Models');
Font.Size := 13;
end;
frmAbb.ShowModal;
finally
frmAbb.Free;
end;
end;
You forgot to make it visible:
redAbbreviations.Visible := TRUE;
And you show the form modal before setting properties to the RichEdit.
Here is the correct reformatted code:
procedure TForm1.Button1Click(Sender: TObject);
var
frmAbb : TForm;
redAbbreviations : TRichEdit;
begin
// opens abbreviations
frmAbb := TForm.Create(nil);
try
redAbbreviations := TRichEdit.Create(frmAbb);
frmAbb.Width := 400;
frmAbb.Height := 400;
frmAbb.Caption := 'Abbreviations';
frmAbb.Position := OwnerFormCenter;
redAbbreviations.Parent := frmAbb;
redAbbreviations.Width := 300;
redAbbreviations.Height := 353;
redAbbreviations.Paragraph.TabCount := 2;
redAbbreviations.Paragraph.Tab[0] := 30;
redAbbreviations.Paragraph.Tab[1] := 60;
redAbbreviations.Lines.Add('DEV'+#9+'='+#9+'SWD Development');
redAbbreviations.Lines.Add('1660'+#9+'='+#9+'1660s');
redAbbreviations.Lines.Add('2.1'+#9+'='+#9+'2.1s');
redAbbreviations.Lines.Add('MIN'+#9+'='+#9+'Minis');
redAbbreviations.Lines.Add('SR'+#9+'='+#9+'Stockrods');
redAbbreviations.Lines.Add('PR'+#9+'='+#9+'Pinkrods');
redAbbreviations.Lines.Add('HR'+#9+'='+#9+'Hotrods');
redAbbreviations.Lines.Add('HM'+#9+'='+#9+'Heavy Metals');
redAbbreviations.Lines.Add('V8'+#9+'='+#9+'V8s');
redAbbreviations.Lines.Add('MA'+#9+'='+#9+'Midgets A');
redAbbreviations.Lines.Add('MB'+#9+'='+#9+'Midgets B');
redAbbreviations.Lines.Add('SP'+#9+'='+#9+'Sprints');
redAbbreviations.Lines.Add('CRO'+#9+'='+#9+'Crosskarts');
redAbbreviations.Lines.Add('LM'+#9+'='+#9+'Late Models');
redAbbreviations.font.Size :=13;
redAbbreviations.Visible := TRUE;
frmAbb.ShowModal;
finally
frmAbb.Free;
end;
end;

Can't obtain solution for the variable gamma1, what's wrong?

I want to use the following code
f := sqrt(7200*8200)*10^6:
Ig := 0, 9330; Ug := 13.134:
f_gr := 10^10:
r_e := .8:
L_e := .5*10^(-9):
C_e := 2.5*10^(-12):
Cka := .4*10^(-12):
Ckp := .8*10^(-12):
L_b := .3*10^(-9):
I_0 := I*f*Ig*(cos(.4*f/f_gr)+I*sin(.4*f/f_gr))/(f_gr*gamma1):
I_e := I_0+Ig:
U_e := I_e*(r_e+I*(2*Pi*f*L_e)):
U_p := -I*(1-gamma1)*I_0/(2*Pi*f*C_e):
Uska := Ug+U_p:
Iska := I*(2*Pi*f*Cka*Uska):
Irb := I_0+Iska:
Urb := 2.8*Irb:
Uskp := Urb+Uska:
Iskp := I*(2*Pi*f*Ckp*Uskp):
Irk := Uskp/773.5:
Ib := Irb+Iskp+Irk:
Ulb := I*(2*Pi*f*L_b*Ib):
Uv := U_e+Ulb+Urb+U_p:
Ik := Ig-Iska-Iskp-Irk:
Uk := Ug-U_e:
to solve Re(Uk)*Re(Ik)+Im(Uk)*Im(Ik)=0.186 for gamma1 (I is for imaginary unit). But this doesn't work. I've tried to use brute force, assigning some numbers to gamma1 and then finding Re(Uk)*Re(Ik)+Im(Uk)*Im(Ik), but I can't obtain a number anyway. Could you help me?
Your code has an apparent mistake in the definition of Ig, to which you have assigned the expression sequence 0, 9330.
Perhaps you intended Ig:=0.9330 instead.
restart;
f := sqrt(7200*8200)*10^6:
Ig := 0.9330:
Ug := 13.134:
f_gr := 10^10:
r_e := .8:
L_e := .5*10^(-9):
C_e := 2.5*10^(-12):
Cka := .4*10^(-12):
Ckp := .8*10^(-12):
L_b := .3*10^(-9):
I_0 := I*f*Ig*(cos(.4*f/f_gr)+I*sin(.4*f/f_gr))/(f_gr*gamma1):
I_e := I_0+Ig:
U_e := I_e*(r_e+I*(2*Pi*f*L_e)):
U_p := -I*(1-gamma1)*I_0/(2*Pi*f*C_e):
Uska := Ug+U_p:
Iska := I*(2*Pi*f*Cka*Uska):
Irb := I_0+Iska:
Urb := 2.8*Irb:
Uskp := Urb+Uska:
Iskp := I*(2*Pi*f*Ckp*Uskp):
Irk := Uskp/773.5:
Ib := Irb+Iskp+Irk:
Ulb := I*(2*Pi*f*L_b*Ib):
Uv := U_e+Ulb+Urb+U_p:
Ik := Ig-Iska-Iskp-Irk:
Uk := Ug-U_e:
And now,
solve(Re(Uk)*Re(Ik)+Im(Uk)*Im(Ik)=0.186, {gamma1});
{gamma1 = -0.9296926790 - 0.6316639400 I}

FB_FileClose is only the first time busy

I'm working with TwinCAT 3 and ST to save data from a socket connection. The sockets work and parts of the saving too, but not all of it. The first array I try to save works fine. But if i want to save another one, it fails. The FB_FileClose doesn't go bBusy.
IF reset THEN // I reset the FB after it saved one array.
bSuccess := FALSE;
iError := 0;
step := 1;
reset := FALSE;
MEMSET(ADR(saveArray), 0, SIZEOF(saveArray));
RETURN;
END_IF
CASE step OF
1:
IF path = '' THEN
bSuccess := FALSE;
iError := 12;
step := 1;
END_IF
fbFileOpen.sPathName := path;
fbFileOpen.nMode := FOPEN_MODEAPPEND OR FOPEN_MODEPLUS;
fbFileOpen.bExecute := TRUE;
fbFileOpen.tTimeout := T#2S;
fbFileOpen();
step := 2;
2:
fbFileOpen(bExecute := FALSE);
IF NOT fbFileOpen.bBusy AND NOT fbFileOpen.bError THEN
step := 3;
ELSE
iError := fbFileOpen.nErrId;
END_IF
3:
fbWriteFile.hFile := fbFileOpen.hFile;
fbWriteFile.bExecute := TRUE;
fbWriteFile.pWriteBuff := ADR(saveArray);
fbWriteFile.cbWriteLen := SIZEOF(saveArray);
fbWriteFile.tTimeout := T#2S;
fbWriteFile();
step := 4;
4:
fbWriteFile(bExecute := FALSE);
IF NOT fbWriteFile.bBusy AND NOT fbWriteFile.bError THEN
step := 5;
END_IF
5:
fbCloseFile.hFile := fbFileOpen.hFile;
fbCloseFile.bExecute := TRUE;
fbCloseFile.tTimeout := T#3S;
fbCloseFile();
IF fbCloseFile.bBusy THEN //Gets suck here at the second run. And if I remove it, the FB doesn't get busy and doesn't close my hFile.
step := 6;
END_IF
6:
fbCloseFile(bExecute := FALSE);
IF NOT fbCloseFile.bBusy AND NOT fbCloseFile.bError THEN
bSuccess := TRUE;
ELSE
iError := fbCloseFile.nErrId;
END_IF
END_CASE
I also noticed that FB_FileOpen opens the same hFile two times in a row. The second one of it can't get closed from the FB_FileClose. The next run it gets a new hFile and then it can save the data. Next one it can't, and so on. What's my error in this one?
Thank you!
Found the solution by myself after a bit of hackaround. Before I set all the parameters for FB_FileOpen, FB_FileWrite and FB_FileClose I set the execute to false like this:
1:
IF path = '' THEN
bSuccess := FALSE;
iError := 12;
step := 1;
END_IF
fbFileOpen(bExecute := FALSE); // Set this to false before.
fbFileOpen.sPathName := path;
fbFileOpen.nMode := FOPEN_MODEAPPEND OR FOPEN_MODEPLUS;
fbFileOpen.bExecute := TRUE;
fbFileOpen.tTimeout := T#2S;
fbFileOpen();
step := 2;
Now it's working.

String is Not Numeric

Having an issue when attempting to run a Mod formula against a field. I keep receiving the error "String is Not Numeric" and so far I have not been able to get ToNumber to correctly format the field. The field is being generated by adding a static value and three fields that have been padded. Any help would be appreciated.
Combines fields and pads
StringVar strMICR;
StringVar strMICRLINE;
strMICRLINE := Chr(13) & "0603250694";
strMICRLINE := strMICRLINE & Right("000000" & Trim(Split({CUST.C_ID_ALPHA},"-")[1]),6);
strMICRLINE := strMICRLINE & Right("00000000" & ToText({STMT.STMT_NUMBER},0,""),8);
strMICRLINE := strMICRLINE & Right("0000000000" & Replace(ToText({#Total},2,""),".",""),10);
//Uncomment below to test Mod10 Check-digit
//strMICR := mod10("0603250694084469108961440000127874");
//IF NumericText (strMICRLINE)
//THEN ToNumber (strMICRLINE);
Mod10 (strMICRLINE);
MOD10 Function
Function (StringVar input_number)
input_number := replace(input_number, " ", "");
numbervar i := length(input_number);
numbervar sum_val := 0;
stringvar position := "odd";
do (
if position = "odd" then (
sum_val := sum_val + 3*tonumber(input_number[i]);
position := "even" )
else (
sum_val := sum_val + tonumber(input_number[i]);
position := "odd" )
;
i := i-1
) while i > 0;
numbervar remainder_val := Remainder(sum_val, 10);
numbervar check_digit := if remainder_val = 0 then 0 else (10-remainder_val) ;
input_number + ToText(check_digit, 0)
You're attempting to call toNumber() on a string that is not numeric and therefore can't be converted. You need to strip all non-numeric characters out of your string first.
//Formula sample to strip non-numeric characters
local stringvar input := "78906-adf0asdf-234";
local stringvar output;
local numbervar i;
for i:=1 to length(input) do
if numerictext(input[i]) then output:=output&input[i];
output
Then I would highly suggest you use the built in mod function instead of rolling your own.
toNumber({#NumericTextOnly}) mod 10