Recent

Author Topic: Help locating program logic  (Read 5293 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Help locating program logic
« Reply #15 on: February 17, 2019, 11:45:17 pm »
I must have something wrong in my code..

Yes, as I said:

The problem in your code is that you're forgetting to reassign iApt to TheWord the second time:
Code: [Select]
iDigits := False;
 iApt := ExtractWord(5, sTest3, [' ']);  //  iApt = NZCB
 Label18.Caption := iApt;
 {*** Here TheWord still contains 'TN04' ***}
 if ContainsDigit(TheWord) then begin iDigits := True;
end
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Help locating program logic
« Reply #16 on: February 18, 2019, 12:20:00 am »
I see there is a possibility that the function created here can falsely report the case.

 if should be "ContainsAllDigits"

 Problem here is the current function is looking any number within the string, so if there happens to be
Letters before or after for example, the function will falsely report a numerical string.

 I know in reality if things are going well the string should be all digits, but in the case of getting software to
work I think it should fail if the string isn't all numerical digits, don't you think ?
The only true wisdom is knowing you know nothing

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Help locating program logic
« Reply #17 on: February 18, 2019, 01:10:00 am »
@lucamar

Yea I finally caught that.
Works in the demo program.

Tahnks
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Help locating program logic
« Reply #18 on: February 18, 2019, 02:03:08 am »
@jamie: Yes, of course, if that were what it is for. But according to specification (in the first post) it just has to return whether there's at least one digit, whatever the rest of the string contains.

Checking whether it's all digits would better be done with TryIntToStr(): if it fails it's not all digits :)
« Last Edit: February 18, 2019, 02:05:10 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Help locating program logic
« Reply #19 on: February 18, 2019, 05:42:48 am »
@jamie: Yes, of course, if that were what it is for. But according to specification (in the first post) it just has to return whether there's at least one digit, whatever the rest of the string contains.

Checking whether it's all digits would better be done with TryIntToStr(): if it fails it's not all digits :)

"it just has to return whether there's at least one digit, whatever the rest of the string contains."

No that's exactly what I need.

I implemented the code in my program and I can't get it to work right.

Still trying. If I can't make it work will post the program and file on Google drive.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018