Recent

Author Topic: Object Pascal: Storing user input into an Integer Array  (Read 4753 times)

Blade

  • Full Member
  • ***
  • Posts: 177
Re: Object Pascal: Storing user input into an Integer Array
« Reply #15 on: August 28, 2020, 05:44:47 am »
Hi there. Sorry, that was a very vague code explanation attempt from me. I am learning about data handling and number conversion in Object Pascal. So, the program I am attempting to make is to take a user’s input of a fixed length. Store the value and then allow them to point to a digit and change just the selected value.

For example user enters 25697 -> value gets stored in an Array (or something more suitable) -> display the array, i.e.:
index1 [2]
index2 [5]
index3 [6]
index4 [9]
index5 [7] 
-> Allow the user to select what number to replace by selecting the index number. -> Then generate a new number showing the changes.

In my earlier code attempt I was trying to say that if the user inputs a 0 as the first number then display and error message. I hope this helps.

For some reason I didn't see this post before.  I suppose the odd thing to me is the need for another array for storage, but your post suggests that you are not so attached to that.  You can simply store the user input into a variable as a string, then display that string in say a separate edit box.  Especially since you are not doing any calculations or math on user input.

You could do simple checks to make sure that 0 is never the first number, no more than 5 digits are given, and that they are all numbers.

The user can simply retype the 5 digit number, if they want to resubmit.  Because the user might want to change multiple numbers, so instead of going crazy with that, just let them retype the entire 5 digit number.  Just have say a second edit box where they can see the original number they typed.

Maybe something like the below:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.         Input: String;
  4.         SeeScan: PChar;
  5.         Count: SmallInt;
  6.         Flag: Boolean;
  7. const
  8.         Numbers = '0123456789';
  9. begin
  10.         Input := Edit1.Text;
  11.         Edit1.Clear;
  12.         Flag := True;
  13.         for Count := Low(Input) to High(Input) do
  14.         begin
  15.                 SeeScan := StrScan(Numbers, Input[Count]);
  16.                 if ((Count = 1) AND (Input[Count] = '0')) OR (SeeScan ='') OR (Count > 5) then
  17.                 begin
  18.                         ShowMessage('Restrictions:' + #10 + '0 not allowed as 1st number' + #10 + 'Must be less than 5 digits' + #10 + 'Only numbers');
  19.                         Flag := False;
  20.                         break;
  21.                 end;
  22.         end;
  23.         if (Flag = True) then
  24.         begin
  25.                 ShowMessage('Is a number and less than 5 digits');
  26.                 Edit2.Text := Input;
  27.         end;
  28. end;
  29.  
« Last Edit: August 30, 2020, 12:57:01 pm by Blade »

lazimiri

  • New member
  • *
  • Posts: 7
Re: Object Pascal: Storing user input into an Integer Array
« Reply #16 on: September 14, 2020, 08:09:32 am »
It´s so cool, that I finally found a Forum where so many people try to help others and only by researching and looking at posts you can learn a lot! So glad I founr lazarusforum!

Greetings

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Object Pascal: Storing user input into an Integer Array
« Reply #17 on: September 14, 2020, 09:14:39 am »
@lazimiri

Which programming topic are you currently researching?

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Object Pascal: Storing user input into an Integer Array
« Reply #18 on: September 14, 2020, 12:57:37 pm »
It´s so cool, that I finally found a Forum where so many people try to help others and only by researching and looking at posts you can learn a lot! So glad I founr lazarusforum!

Greetings

Some of us are simply walking data banks  ;D

There are those hower you need to lift their nose out of the keyboard to quiet the system beep so others can get some sleep.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018