Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Limiting User input for string fields


3 replies to this topic

Ray Gonzales

Ray Gonzales
  • Members
  • 7 posts

Posted 07 February 2002 - 18:51

Greetings!

I'm using IS 6.31 and was wondering if anyone was familiar with limiting the size of a string which a user may enter.  Specifically, I'd like to keep the User Name and Company Name in an SdRegisterUser dialog within 30 - 40 characters.

Any assistance or advice is greatly appreciated.

Best Regards,

Ray Gonzales


Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 07 February 2002 - 20:28

There may be a more direct route, but short of writing a custom dialog, here's one way to do it.

Upon receiving a Next result from the dialog simply check the length of the previously entered information.  It either exceeds your max. length, put up an error message stating such being the case and go back to showing the user info. dialog.

The code would basically be structured as follows:
Dlg_SdRegisterUserEx:
    szTitle = "Enter User Information";
    szMsg   = "Please enter your Name, Company Name, and Serial Number.";
    nResult = SdRegisterUserEx(szTitle, szMsg, svName, svCompany, svSerial);
    if (nResult = BACK) then
         goto Dlg_SdWelcome; // OR WHATEVER THE PREVIOUS DIALOG IS
    else
         if( StrLengthChars (svName) > 40 || StrLengthChars (svCompany) > 40 )
              MessageBox("Your name and/or company exceeds the maximum length of 40 characters", SEVERE);
              goto Dlg_SdRegisterUserEx:
         endif;
    endif;

NOTE: I didn't compiling this to check the syntax, but it should be pretty close.


Ray Gonzales

Ray Gonzales
  • Members
  • 7 posts

Posted 08 February 2002 - 14:55

Thanks for your reply!  That's certainly an option.

Optimally, what I'd like to do is simply prevent the user from entering more than the alloted amount of characters.  Perhaps the custom dialog is the way to go here.

Thanks again very much for your reply!

Regards,


Ide Nentjes

Ide Nentjes
  • Members
  • 222 posts

Posted 13 February 2002 - 11:16

Should you decide to write a custom dialog box, here's how to limit the number of characters a field can contain:

#define EM_LIMITTEXT32        0x00c5
#define EM_LIMITTEXT16        0x0415

use EM_LIMITTEXT32 for 32-bits OS, otherwise EM_LIMITTEXT16.  Inside DLG_INIT put the following:

iMaxChars = 7;  // or whichever number you wish as max
hwndDialog = CmdGetHwndDlg( svDlg );
hwndControl =  GetDlgItem(hwndDialog,ID_MYCONTROL);         
SendMessage( hwndControl, EM_LIMITTEXT32, iMaxChars, 0);


Enjoy, Ide