Página 1 de 1

Why don't the string or number comparisons work?

Publicado: Lun Jul 24, 2017 6:06 pm
por DC
Hi,

In the code below, the problem is that the string and number conversions don't work. Below, we assign 5 to n_Number; and "test" to s_String. But when we run it, the condition is never executed.

I tried setting the 's_BreakPointString := s_BreakPointString' lines as breakpoints, and it never gets there. I also tried stepping through, and the condition is ignored; it just skips to the next line, after the endif.

Código: Seleccionar todo

METHOD TestThis( oSender ) CLASS frm_Test
   Local n_Number := 5
   Local s_String := "test"
   Local s_BreakPointString := "Breakpoint"

   If n_Number == 5
      s_BreakPointString := s_BreakPointString
   Endif

   If s_String == "test"
      s_BreakPointString := s_BreakPointString
   Endif


   s_BreakPointString := s_BreakPointString

RETURN Nil

Re: Why don't the string or number comparisons work?

Publicado: Lun Jul 24, 2017 6:24 pm
por ignacio
Hi,

All the IF..ENDIF conditions are true and its internal code is evaluated. Please try this version of your code and see on the debugger windows how the logdebug() calls are excuted.

Regards

Código: Seleccionar todo

METHOD Button1Click( oSender ) CLASS TForm1

   Local n_Number := 5
   Local s_String := "test"
   Local s_BreakPointString := "Breakpoint"

   If n_Number == 5
      s_BreakPointString := s_BreakPointString
      LogDebug( "1" )
   Endif

   If s_String == "test"
      s_BreakPointString := s_BreakPointString
      LogDebug( "2" )
   Endif

   s_BreakPointString := s_BreakPointString
   LogDebug( "3" )

RETURN Nil

Re: Why don't the string or number comparisons work?

Publicado: Lun Jul 24, 2017 7:27 pm
por DC
If the LogDebug() statements are thrown in, then they are executed.

But the statement

s_BreakPointString := s_BreakPointString


is never reached. It's just skipped over.

It looks like Harbour is just ignoring trivial statements that assign variables to themselves.

Anyway, I seem to have the main program working now, so it doesn't matter now. It was related to some Sql Server tables that were generating an error when they were opened, specifically when the load() method was executed.

If any further problems, I'll check in, thanks.

Re: Why don't the string or number comparisons work?

Publicado: Mar Jul 25, 2017 1:12 pm
por ignacio
Hello,

Compilers, at least, MingGW simply ignores useless code on a lot of circunstancies. Is a really smart guy! :)

Regards,