Jump to content











Photo
- - - - -

If statement


  • Please log in to reply
19 replies to this topic

#1 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 15 October 2007 - 12:11 PM

What I originally thought to be an 'IniWriteTextLine' issue, is really an 'If' issue (see here):

If I append a well running statement as the command of an If statement, it really should never happen that the well running statement is misinterpreteted.

I think, that WinBuilder
  • splits the line into comma separated array elements
  • dispatches depending on element[0]
In the case of 'If' element[4] up to element[<last>] have to be combined again to element[4] with separating commas.

Peter

#2 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 15 October 2007 - 12:26 PM

Hard task..

Technically we are saying that wb needs to know when to ignore and recognize a comma as a separate component from a command.

At this moment everytime a comma is found it will split the rest of the line into another slot which is later used as the command wishes.

Replacing all commas with special characters on the text part allows to print a comma anywhere - and this works.

Otherwise it will become very hard to handle this sort of operation because you're writing a text statement on a file and would be nearly impossible to know exactly when you need commas added and not.

#3 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 15 October 2007 - 12:35 PM

Hard task..

Technically we are saying that wb needs to know when to ignore and recognize a comma as a separate component from a command.

At this moment everytime a comma is found it will split the rest of the line into another slot which is later used as the command wishes.

Using the special character allows to print a comma and this works.

----------

Adding this modification would mean adding special rules and complicate the language processing a lot..


I fully understand the technical background and really would not like to do such work which perhaps needs a redesign of your core functionality.

But for an excellent application (not only for WinBuilder) the statement I gave above in increased size, is essential!

Hold it in your mind, every time!

I think the hint I gave, could be a temporary workaround:
In case of 'If', before executing 'command', rebuild it from all elements of 4 and higher.
Or just, search for the start of 'command' in the original line, and use it.

That are only about 3 statements, and could be included in the next beta.

Peter

#4 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 15 October 2007 - 12:45 PM

Replacing all commas with special characters on the text part allows to print a comma anywhere - and this works.

A different alternity:
WinBuilder does not allow any comma anywhere, only as syntax separator.

But in this case the following statement w/o 'If' must generate an error about misused commas.
IniWriteTextLine,&#34;%PreISOScript%&#34;,&#34;Process&#34;,&#34;Exec,%ScriptFile%,pre-ISO&#34;

Peter

#5 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 15 October 2007 - 01:31 PM

I may be wrong, but i don't see the problem in fixing.
Every command knows exactly how many sections it has. No need to seperate after all comma. Just seperate up to the number of sections. The second command can then contain as many commas as it needs without confusing the first one.

:cheers:

#6 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 15 October 2007 - 01:51 PM

Each command should know how many components it will use - however this won't be possible when adding parameters on the run/exec commands or even on the if commands since these are not static to a few known parameters.

Then it will also be needed to change the default procedure that translate all special characters back to normal commas.

And this is something I'd really prefer to keep as it is before getting deeper and deeper into new bugs introduced by this modification.

The comma is used to split each part of the string and implementing this feature would make things very confusing and hard to assure good values when it simpler to just use #$c and know exactly what a comma does inside a command.

....

This is really asking to "guess" when a comma is no longer meant to be a comma.. :cheers:

#7 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 15 October 2007 - 01:57 PM

I may be wrong, but i don't see the problem in fixing.
Every command knows exactly how many sections it has. No need to seperate after all comma. Just seperate up to the number of sections. The second command can then contain as many commas as it needs without confusing the first one.

:cheers:

You are a little bit wrong.
Some commands have an undefined number of args:
Run,%ScriptFile%,my-dommand,#1,#2, ...
But you are right as far that 'If' has 'command' as #4 or #5 (depending on how you count)
Peter

#8 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 15 October 2007 - 02:09 PM

Each command should know how many components it will use - however this won't be possible when adding parameters on the run/exec commands or even on the if commands since these are not static to a few known parameters.

Then it will also be needed to change the default procedure that translate all special characters back to normal commas.

And this is something I'd really prefer to keep as it is before getting deeper and deeper into new bugs introduced by this modification.

The comma is used to split each part of the string and implementing this feature would make things very confusing and hard to assure good values when it simpler to just use #$c and know exactly what a comma does inside a command.

....

This is really asking to "guess" when a comma is no longer meant to be a comma.. :cheers:


But at least in case of the IF command you should change something:
  • I have a running command, which of course contains some syntax commas
    If it contains #$c instead of the comma, it won't run.
  • I change the script:
  • My command depends on a condition:
  • I write the condition in front of the command
  • I have to change my running command, just because it is preceeded by a condition
    Crazy :cheers:
Did you ever have seen a Delphi (or other language) statement which has to be revised if you let it depend on an 'If' clause?

Peter

#9 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 15 October 2007 - 03:11 PM

Have you ever called in delphi something like this?
Procedure run&#40;text&#58;string&#41;;

   begin

	 text;

   end;

It would obviously fail because it's a simple text sentence and not a procedure or function - in wb you still need to convert a working command to a text string in order to use it as a string.

Delphi doesn't use commas to separate commands - it will use ; and text strings need to be defined as text strings.

On our case I still think that it's the safest way to handle the string as a whole.

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

Probably I'm also not understanding correctly your idea - sorry if this is the case.. :cheers:

#10 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 15 October 2007 - 03:23 PM

What I meant:
If this procedure runs well:
Procedure run&#40;&#41;;

	begin

	  statement;

	end;
Than it cannot be that
Procedure run&#40;&#41;;

	 begin

	 if somecondition then

		   statement;

	 end;
only runs after modification of statement.
Peter

#11 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 15 October 2007 - 06:05 PM

Each command should know how many components it will use - however this won't be possible when adding parameters on the run/exec commands or even on the if commands since these are not static to a few known parameters.

:cheers: The if command can not have any number of sections, it's very clearly defined. And the run and exec commands can not have other WB commands following them. or can they? :cheers:

:cheers:

#12 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 15 October 2007 - 06:24 PM

:cheers: The if command can not have any number of sections, it's very clearly defined. And the run and exec commands can not have other WB commands following them. or can they? :cheers:

:cheers:


Nice questions raised - but I'm really worried about the way how comma would be processed.

Please let me finish some of the new beta requests and I'll start working alongside with you and Peter to see if this is feasable.

:cheers:

#13 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 15 October 2007 - 07:35 PM

Nice questions raised - but I'm really worried about the way how comma would be processed.

Please let me finish some of the new beta requests and I'll start working alongside with you and Peter to see if this is feasable.

:cheers:

I don't want to pressure you into anything, just show you a path you couldn't see before.

:cheers:

#14 smiley

smiley

    Silver Member

  • .script developer
  • 905 posts
  •  
    Greece

Posted 15 October 2007 - 08:21 PM

Hi there,

I may be wrong but I think that the actual problem is that when winbuilder separates a line into arguments , it splits the line even if a comma is between quotes.

I mean that a line like this:
If,%pCheckBox6%,Equal,true,IniWriteTextLine,&#34;%PreISOScript%&#34;,&#34;Process&#34;,&#34;Exec,%ScriptFile%,pre-ISO1&#34;
is splitted currently like this:
1&#41; If  2&#41; %pCheckBox6%   3&#41; Equal  4&#41; true  5&#41; IniWriteTextLine  6&#41; &#34;%PreISOScript%&#34;  7&#41;  &#34;Process&#34;  8&#41; &#34;Exec 9&#41;%ScriptFile% 10&#41;pre-ISO1&#34;

but it should be like this:
1&#41; If  2&#41; %pCheckBox6%   3&#41; Equal  4&#41; true  5&#41; IniWriteTextLine  6&#41; &#34;%PreISOScript%&#34;  7&#41;  &#34;Process&#34;  8&#41; &#34;Exec,%ScriptFile%,pre-ISO1&#34;


#15 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 15 October 2007 - 08:33 PM

but it should be like this:

1&#41; If  2&#41; %pCheckBox6%   3&#41; Equal  4&#41; true  5&#41; IniWriteTextLine  6&#41; &#34;%PreISOScript%&#34;  7&#41;  &#34;Process&#34;  8&#41; &#34;Exec,%ScriptFile%,pre-ISO1&#34;


:cheers:

And that is the issue I'm trying to 'demand'

Peter

#16 smiley

smiley

    Silver Member

  • .script developer
  • 905 posts
  •  
    Greece

Posted 15 October 2007 - 08:40 PM

:cheers:

And that is the issue I'm trying to 'demand'

Peter


Then the solution you suggested wasn't the best :cheers: . The best would be to write a new function that splits the line in arguments and skip a comma if it is between quotes.

Edit: Forgot to mention that If this change is aplyed, winbuilder will no more need to find and replace #$c and #$s (that are VERY time consuming)

#17 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 15 October 2007 - 08:56 PM

Then the solution you suggested wasn't the best :cheers: . The best would be to write a new function that splits the line in arguments and skip a comma if it is between quotes.

Edit: Forgot to mention that If this change is aplyed, winbuilder will no more need to find and replace #$c and #$s (that are VERY time consuming)

Here how I handle in my programs:
function handleQuotes(const inp: string): string;var  TempString: string;  TempList: Tstringlist;  I: integer;  inQuotes: boolean;  tmp: string;begin  TempList := TstringList.Create;  TempString := &#39;&#39;;  inQuotes := false;  tmp := inp;  repeat    I := Pos(&#39;"&#39;, tmp);    if i > 0 then    begin      TempString := copy(tmp, 0, i - 1);      if inQuotes then        tempString := AnsiReplaceText(tempString, &#39;,&#39;, &#39;|&#39;);      TempList.Append(tempString);      tmp := copy(tmp, i + 1, Length(tmp));      inQuotes := not inQuotes;    end;  until i = 0;  TempList.Append(Trim(tmp));  tempString := TempList.Strings[0];  for i := 1 to TempList.Count - 1 do  begin    tempString := tempString + &#39;"&#39; + TempList.Strings[i];  end;  tmp := inp;  handleQuotes := tempString;end;function split(input, delim: string): Tstringlist;var  TempString: string;  TempList: Tstringlist;  I: integer;begin  TempList := TstringList.Create;  TempString := &#39;&#39;;  if delim = &#39;,&#39; then    input := handleQuotes(input);  repeat    I := Pos(delim, input);    if i > 0 then    begin      TempString := Trim(copy(input, 0, i - 1));      TempString := AnsiReplaceStr(tempString, &#39;|&#39;, &#39;,&#39;);      TempList.Append(TempString);      input := copy(input, i + 1, Length(input));    end;  until i = 0;  TempList.Append(Trim(AnsiReplaceStr(input, &#39;|&#39;, &#39;,&#39;)));  split := tempList;end;

Peter

#18 smiley

smiley

    Silver Member

  • .script developer
  • 905 posts
  •  
    Greece

Posted 15 October 2007 - 09:04 PM

Here how I handle in my programs:

Peter


And this is how I handle it with vb6:
Function StringSplit(line As String, out() As String, delimiter As String) As StringDim b() As ByteDim CharIndex As IntegerDim OldPos As IntegerDim qchar As IntegerDim dchar As IntegerDim index As IntegerDim temp As Integerqchar = Asc("""")dchar = Asc(delimiter)OldPos = 0b() = StrConv(line & delimiter, vbFromUnicode)ReDim Preserve out(0)CharIndex = 0Do&#39;loop until a quote or delimiter is foundIf b(CharIndex) = qchar Then&#39;Quote found. Loop until its pair is foundtemp = CharIndexDoCharIndex = CharIndex + 1If CharIndex > UBound(b ) ThenCharIndex = temp + 1Exit DoEnd IfLoop Until b(CharIndex) = qcharElseIf b(CharIndex) = dchar Then&#39;Delimiter found. Alocate a new string and copy in it the contentsindex = UBound(out) + 1ReDim Preserve out(index)out(index) = String(CharIndex - OldPos, 0)MoveMemory out(index), ByVal VarPtr(b(0)) + OldPos, CharIndex - OldPosOldPos = CharIndex + 1End IfCharIndex = CharIndex + 1Loop Until CharIndex > UBound(b )End Function


#19 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 15 October 2007 - 10:06 PM

You're a tough audience - I've lost any arguments to keep as it is.. :cheers: :cheers: (thanks!)


Peter, does the split function works exactly as you expect on this case? :cheers:

I'm still finishing some work in other areas but I'll keep this in mind or please "bump" to refresh the memory, would really like to add this as soon as possible.

Smiley, thanks for the code snippet.

:cheers:

#20 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 16 October 2007 - 07:32 AM

Peter, does the split function works exactly as you expect on this case? :cheers:

Yes, it does. because it does not split on comma inside a quote pair.

Peter




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users