• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

problem with code ..

Hi, when i use this code it works with 1 TEDIT fine.. but not with a multiple ones
i need it so that, if it finds any of the text inside the edit boxes.. dont add and show the message.
When i test it with 1 edit, it worked, but if something was in the database as "DUML" it wouldnt add a word called DUMLB"

can we fix that too?

here is my code:

      if Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString=edit1.text + flatedit1.text + flatedit3.text +  flatedit5.text + flatedit7.text + flatedit9.text + flatedit10.text + flatedit11.text + flatedit8.text then
 begin
  Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
   exit;
  end
  else begin

REST OF THE CODE

also.. do i need the exit??


I think iam using + and it should be or? but it doesnt compile.

0
boycoder
Asked:
boycoder
  • 10
  • 7
1 Solution
 
boycoderAuthor Commented:
so it has find an exact match..

so if GFAAA-FFFGB-GGGGG is in the databse and if i try and add

DFAAA-FFFGB-GGGG let it add it.
0
 
jimyXCommented:
There are many ways to do that, here is one which is by using Stringlist and add all your Editboxes and look for your data in there:
procedure TForm1.Button1Click(Sender: TObject);
var
  Str:TStringlist;
begin
  Str:=TStringlist.Create;
  try  // if the case sensitivity is an issue use uppercase()
    Str.Add(edit1.text);
    Str.Add(flatedit1.text);
    Str.Add(flatedit3.text);
    Str.Add(flatedit5.text);
    Str.Add(flatedit7.text);
    Str.Add(flatedit9.text);
    Str.Add(flatedit10.text);
    Str.Add(flatedit11.text);
    Str.Add(flatedit8.text);
    if Str.IndexOf(Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString) >= 0 then
      begin
        Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
      end;
  finally
    Str.Free;
  end;
end;

Open in new window

0
 
jimyXCommented:
What you were trying to do actually is:
procedure TForm1.Button1Click(Sender: TObject);
var
  s:String;
begin
  s:=Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString;         // I used string variable instead of using the DB record every time
  if (s=edit1.text) or
     (s=flatedit1.text) or
     (s=flatedit3.text) or
     (s=flatedit5.text) or
     (s=flatedit7.text) or
     (s=flatedit9.text) or
     (s=flatedit10.text) or
     (s=flatedit11.text) or
     (s=flatedit8.text then
  begin
     Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',  MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
  end;
end;

Open in new window

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
boycoderAuthor Commented:
Thanks jim, but it must be a problem with my original code, as it doesnt seem to work. Here is the update button of the code.

what happens is, when i paste 10 serial numbers into memo1.text it auto puts them into the 10 edit boxes on MEMOCHANGE.

this is the in the button that adds the serials to the database but something isnt right.




procedure Tmassserials.goClick(Sender: TObject);

  var
  i : integer;

  Str:TStringlist;

begin
  Str:=TStringlist.Create;
  try  // if the case sensitivity is an issue use uppercase()
    Str.Add(edit1.text);
    Str.Add(flatedit1.text);
    Str.Add(flatedit3.text);
    Str.Add(flatedit5.text);
    Str.Add(flatedit7.text);
    Str.Add(flatedit9.text);
    Str.Add(flatedit10.text);
    Str.Add(flatedit11.text);
    Str.Add(flatedit8.text);
    if Str.IndexOf(Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString) >= 0 then
      begin
        Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;



   end else begin
  if LastDelimiter('SsUu5$&%.$£nNoOAalIiL`;_?iI', Memo1.text) <> 0 then
 begin
  Windows.MessageBox(handle, 'An incorrect subscription was found. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;

  end



  else begin

if
flatedit17.text=('')
then begin
 Windows.MessageBox(handle, 'Mass Upload Error! You must give a folder name!',  'STATUS ERROR!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;

 end;
  if
sales.text=('')
then begin
 Windows.MessageBox(handle, 'Mass Upload Error! You must select a sale type!',  'STATUS ERROR!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning);

 end
 else begin
 if
 sheet.text=('Select a Sheet')
 then begin
  Windows.MessageBox(handle, 'Mass Upload Error! You must select a sheet!',  'STATUS ERROR!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;


 end
else
 begin
                   if
                   memo1.text=('' )
                   then
 begin
  Windows.MessageBox(handle, 'No subscriptions have been added!',  'NOTHING TO ADD!!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;



  end
  else begin




form1.adotable2.Insertrecord([nil,sales.text,edit1.Text,flatedit17.text,sheet.Text]);
form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit1.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit3.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit5.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit7.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit8.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit9.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit10.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit11.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

form1.adotable2.Insertrecord([nil,sales.text,flatedit18.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;


    end;
  end;
    end;
     end;
     end;
  finally
    Str.Free;
  end;
 end;

Open in new window

0
 
jimyXCommented:
I remember you mentioned before that you do not want to use queries DB, may I ask why? Because SQL is really going to help you a lot as it has a really very powerful functionality and can save a lot of your time (not necessarily in this current project but for future projects).
0
 
boycoderAuthor Commented:
ill try that second code jim
0
 
boycoderAuthor Commented:
ive never really got queries to work for me. lets give it a go as i cant get that code to fit in with my other code, must be a problem with my code.
0
 
jimyXCommented:
Sorry took sometime to organize the code. Do you get error(s) or the code works but you do not get the expected result?

procedure Tmassserials.goClick(Sender: TObject);
var
  i : integer;
  Str:TStringlist;
begin
  Str:=TStringlist.Create;
  try  // if the case sensitivity is an issue use uppercase()
    Str.Add(edit1.text);
    Str.Add(flatedit1.text);
    Str.Add(flatedit3.text);
    Str.Add(flatedit5.text);
    Str.Add(flatedit7.text);
    Str.Add(flatedit9.text);
    Str.Add(flatedit10.text);
    Str.Add(flatedit11.text);
    Str.Add(flatedit8.text);
    if Str.IndexOf(Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString) >= 0 then
      begin
        Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
      end
    else
      begin
        if LastDelimiter('SsUu5$&%.$£nNoOAalIiL`;_?iI', Memo1.text) <> 0 then
          begin
            Windows.MessageBox(handle, 'An incorrect subscription was found. No subscriptions have been added!',  'Invalid subscription found!',
            MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
          end
        else
          begin
            if flatedit17.text='' then
              begin
                Windows.MessageBox(handle, 'Mass Upload Error! You must give a folder name!',  'STATUS ERROR!',
                MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;
              end;
            if sales.text='' then
              begin
                Windows.MessageBox(handle, 'Mass Upload Error! You must select a sale type!',  'STATUS ERROR!',
                MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning);
              end
            else
              begin
                if sheet.text='Select a Sheet' then
                  begin
                    Windows.MessageBox(handle, 'Mass Upload Error! You must select a sheet!',  'STATUS ERROR!',
                    MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;
                  end
                else
                  begin
                    if  memo1.text='' then
                      begin
                        Windows.MessageBox(handle, 'No subscriptions have been added!',  'NOTHING TO ADD!!',
                        MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
                      end
                    else
                      begin
                        form1.adotable2.Insertrecord([nil,sales.text,edit1.Text,flatedit17.text,sheet.Text]);
                        form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit1.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit3.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit5.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit7.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit8.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit9.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit10.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit11.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;

                        form1.adotable2.Insertrecord([nil,sales.text,flatedit18.Text,flatedit17.text,sheet.Text]);
                        Form1.ADOTable2.Edit;
                        Form1.ADOTable2.Fields[13].AsString:=sales.Text;
                        Form1.ADOTable2.post ;
                      end;
                  end;
              end;
          end;
      end;
  finally
    Str.Free;
  end;
end;

Open in new window

0
 
boycoderAuthor Commented:
I just dont get the expected result. That seems to work once jim, but after the error message,i cluck submit and it adds them.
then i click clear and try again and adds them as normal even if they are in the databse.
0
 
jimyXCommented:
Still can't imagine what you are doing could you provide more details please?
Also you can replace the following steps:
form1.adotable2.Insertrecord([nil,sales.text,flatedit18.Text,flatedit17.text,sheet.Text]);
Form1.ADOTable2.Edit;
Form1.ADOTable2.Fields[13].AsString:=sales.Text;
Form1.ADOTable2.post ;

Open in new window


With just one line:
form1.adotable2.Insertrecord([null,sales.text,flatedit18.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);
0
 
jimyXCommented:
Let's try this way please:
procedure Tmassserials.goClick(Sender: TObject);
var
  i : integer;
  Str:TStringlist;
begin
    Str:=TStringlist.Create;
    Str.Add(uppercase(edit1.text));
    Str.Add(uppercase(flatedit1.text));
    Str.Add(uppercase(flatedit3.text));
    Str.Add(uppercase(flatedit5.text));
    Str.Add(uppercase(flatedit7.text));
    Str.Add(uppercase(flatedit9.text));
    Str.Add(uppercase(flatedit10.text));
    Str.Add(uppercase(flatedit11.text));
    Str.Add(uppercase(flatedit8.text));
    if Str.IndexOf(uppercase(Form1.ADOTable2.Fieldbyname('Serial Numbers').AsString)) >= 0 then
      begin
        Windows.MessageBox(handle, 'One or more serials already exisit in the database. No subscriptions have been added!',  'Invalid subscription found!',
         MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
      end
    else
      begin
        if LastDelimiter('SsUu5$&%.$£nNoOAalIiL`;_?iI', Memo1.text) <> 0 then
          begin
            Windows.MessageBox(handle, 'An incorrect subscription was found. No subscriptions have been added!',  'Invalid subscription found!',
            MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
          end
        else
          begin
            if flatedit17.text='' then
              begin
                Windows.MessageBox(handle, 'Mass Upload Error! You must give a folder name!',  'STATUS ERROR!',
                MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;
              end;
            if sales.text='' then
              begin
                Windows.MessageBox(handle, 'Mass Upload Error! You must select a sale type!',  'STATUS ERROR!',
                MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning);
              end
            else
              begin
                if sheet.text='Select a Sheet' then
                  begin
                    Windows.MessageBox(handle, 'Mass Upload Error! You must select a sheet!',  'STATUS ERROR!',
                    MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONwarning) ;
                  end
                else
                  begin
                    if  memo1.text='' then
                      begin
                        Windows.MessageBox(handle, 'No subscriptions have been added!',  'NOTHING TO ADD!!',
                        MB_SYSTEMMODAL or MB_SETFOREGROUND or MB_TOPMOST or MB_ICONHAND) ;
                      end
                    else
                      begin
                        form1.adotable2.Insertrecord([null,sales.text,edit1.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit1.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit3.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit5.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit7.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit8.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit9.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit10.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit11.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);

                        form1.adotable2.Insertrecord([null,sales.text,flatedit18.Text,flatedit17.text,sheet.Text,null,null,null,null,null,null,null,null,sales.Text]);
                      end;
                  end;
              end;
          end;
      end;
    Str.Free;
end;

Open in new window

0
 
boycoderAuthor Commented:
that seems to work jimmy thanks mate, but if i close down the form, then reopen it again and do it then, it adds them. is there a way to free it or something so when i open the form again, it allows the protection we have added ?

thanks again

oh by the way, i had to change to first null to Nil as it would let me write into the database but still works.
0
 
boycoderAuthor Commented:
um sorry it didnt work.. it was another error.. is there a simple way to di this like...


if memo1.text matches anything isside adotable.byname'Serial numbers' show error message. ?
0
 
boycoderAuthor Commented:
its ok jimmy mate, it isnt really that important , the chances of me adding the same serial twice is remote. unless we can put that code somewhere else..

can we have it on form 1, if anything is added to the database run this check ?
0
 
jimyXCommented:
It will be much clearer if you give an example of what happens and what you want it to be.
Can use the TeamViewer to give me limited access to your PC?
0
 
boycoderAuthor Commented:
Hi jim, its all working now, sorry about the delay i had to nip out. cheers mate thanks very much!!
0
 
boycoderAuthor Commented:
A
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 10
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now