Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checking number
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Titre:
Divers
Thread ID:
00391332
Message ID:
00391352
Vues:
10
>one more question if you do not mind, i also want to check to see that a number is not entered more than once. right now i am using lookup to see if the number is already in the table, is there a better (more effecient or faster) way to do this?
>
>Thanks,
>Ryan

Let's be more specific here (you may also check thread Uniqueness of indexes...).
Couple of questions:
1) Do you use buffering or write directly in a table?
IndexSeek should be a function to look.
In our classlibrary I have a class, which called wgUniqueText. This class is responsible for ensure uniqueness. This class has two custom properties: pcFields and pcValidTag, which I initialize to be empty string (None). It has this code in Valid method:
********************************************************************
*  Description.......: wgUniqueText.Valid()
*  Calling Samples...:
*  Parameter List....:
*  Created by........:
*  Modified by.......: Nadya Nosonovsky 06/05/2000 12:08:49 PM
********************************************************************
*--- Checks to see if the value entered is unique.
local lcvalue,llunique,lnaction, lcfield, lcAlias, lcTag
llunique = .t.
lcAlias=alias()
if empty(lcAlias)
     lcAlias=thisform.dataenvironment.InitialSelectedAlias
endif
lcTag = this.pcValidTag && Tag Name, used in validation
lcField=this.pcFields && Field Name or combination of fields in validation
lcValue = iif(type("this.value") = "C", rtrim(this.value), this.value) && Store value entered.

*--- Make sure that it is NOT empty.
if empty(this.value)
     lnaction=messagebox('This field can not be blank! Would you like to try again?',20,'Warning')

     if lnaction = 6               && Return user to field.
          llunique = .f.
*--- Do nothing , false will be returned.

     else
*--- The user choose to cancel the edit or add.  Return them to review mode.
          llunique = .t.
          select (lcAlias)
          thisform.edit()
          thisform.navstand.navupdate()
          thisform.refresh()
     endif

endif

if llunique
*--- Check table.
     if (thisform.addmode and recno()<0) or (not thisform.addmode and oldval(lcfield,lcAlias)<>lcvalue)
*!*               select * from (lcAlias) ;
*!*                    where &lcfield == lcvalue to screen noconsole

*!*     *--- Test results of SELECT-SQL duplicate record check.

*!*               if _tally > 0
*!*                    llunique = .f.
*!*               endif
      if indexseek(lcValue,.f.,lcAlias, lcTag) && Field is duplicate
           llUnique=.f.
      endif     

          if !llunique          &&
               lnaction=messagebox('The value entered is not unique. Would you like to try again?',20,'Duplicate value')

               if lnaction = 6               && Return user to field.
                    llunique = .f.
*--- Do nothing , false will be returned.

               else
*--- The user choose to cancel the edit or add.  Return them to review mode.
                    llunique = .t.
                    select (lcAlias)
                    thisform.edit()
                    thisform.navstand.navupdate()
                    thisform.refresh()
               endif
          endif
     endif
endif
return llunique
HTH
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform