Valid Textbox

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Valid Textbox

Post by franco »

I am trying to validate entry on a textbox.
I am sure I seen valid some where. This is what I am using but there must be an easier way. I need Blank, A, B, C or D for valid enter.
This is from text_1 samples in .3.4.4 and I have modified text_2

Code: Select all

		@ 10,10 TEXTBOX Text_1 ;
			VALUE 123 ;
			TOOLTIP 'Numeric TextBox' ;
			NUMERIC ;
			MAXLENGTH 5 ;
			RIGHTALIGN ;
			ON LOSTFOCUS if ( This.Value < 100 , This.SetFocus , Nil)


		@ 40,10 TEXTBOX Text_2 ;
			VALUE ' '; //'Hi All' ;
			TOOLTIP 'Character TextBox' ;
			DISABLEDBACKCOLOR { 0,255,0 } ;
			DISABLEDFONTCOLOR { 255,255,255 };
			ON LOSTFOCUS if( 'A'  $  This.Value, Nil, if(len(alltrim(This.Value)) = 0,Nil, ;
				if('B' $ This.Value,Nil, if('C' $ This.Value,Nil,if('D' $ This.Value,Nil,(msgbox('Must Enter BLANK,A,B,C,D'),This.Setfocus))))));
			ON ENTER Form_1.Text_1.SetFocus 

Any ideas
Franco
All The Best,
Franco
Canada
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Valid Textbox

Post by AUGE_OHR »

hi,

for a "single Key" i use ONCHANGE which will "be fired" when press a Key.

Tip :
i do write a "extra" Function after Command while you can´t "debug" it that Way you use it.
have fun
Jimmy
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Valid Textbox

Post by SALINETAS24 »

franco wrote: Mon Jan 11, 2021 10:28 pm I am trying to validate entry on a textbox.
I am sure I seen valid some where. This is what I am using but there must be an easier way. I need Blank, A, B, C or D for valid enter.
This is from text_1 samples in .3.4.4 and I have modified text_2

Code: Select all

		@ 10,10 TEXTBOX Text_1 ;
			VALUE 123 ;
			TOOLTIP 'Numeric TextBox' ;
			NUMERIC ;
			MAXLENGTH 5 ;
			RIGHTALIGN ;
			ON LOSTFOCUS if ( This.Value < 100 , This.SetFocus , Nil)


		@ 40,10 TEXTBOX Text_2 ;
			VALUE ' '; //'Hi All' ;
			TOOLTIP 'Character TextBox' ;
			DISABLEDBACKCOLOR { 0,255,0 } ;
			DISABLEDFONTCOLOR { 255,255,255 };
			ON LOSTFOCUS if( 'A'  $  This.Value, Nil, if(len(alltrim(This.Value)) = 0,Nil, ;
				if('B' $ This.Value,Nil, if('C' $ This.Value,Nil,if('D' $ This.Value,Nil,(msgbox('Must Enter BLANK,A,B,C,D'),This.Setfocus))))));
			ON ENTER Form_1.Text_1.SetFocus 

Any ideas
Franco

Hola Franco, y porqué no pruebas con un COMBOBOX

Code: Select all

@ 40,10 	COMBOBOX Combo_1 ;
			WIDTH 100 ;
			ITEMS {  '  | Espacio' ,   'A | Letra A' , 'B | Letra B' , 'C | Letra C' } ;
			VALUE 1 ;
			ON ENTER MsgInfo ( Str(Form_1.Combo_1.value) ) ;
			FONT 'Courier' SIZE 12
 
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Valid Textbox

Post by bpd2000 »

Refer code it may help you

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002 Roberto Lopez <roblez@ciudad.com.ar>
 * http://www.geocities.com/harbour_minigui/
*/

#include "hmg.ch"

#xtranslate VALID <condition> [ MESSAGE <message> ] ;
=> ;
ON LOSTFOCUS _DoValid ( <condition> , <message> )

Function Main

	Public _HMG_IsValidInProgres := .F.

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 480 ;
		TITLE 'Harbour MiniGUI Demo, Valid entry if < 20' ;
		MAIN 

		@ 10,10 TEXTBOX Text_1 ;
			VALUE 20 ;
			NUMERIC ;
			VALID Form_1.Text_1.Value < 20 
      
      
		@ 40,10 TEXTBOX Text_2 ;
			VALUE 9 ;
			NUMERIC ;
			VALID Form_1.Text_2.Value < 10	;
			MESSAGE 'Only values < 10 !'

	END WINDOW

	Form_1.Activate

Return Nil

Function _DoValid ( Expression , Message )

		If ValType ( Message ) = "U"
			Message := "Invalid Entry"
		EndIf

    If !Expression
       MsgStop (Message,'')
       thiswindow.setfocus
       This.SetFocus
    endif

Return Nil

BPD
Convert Dream into Reality through HMG
User avatar
dragancesu
Posts: 930
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: Valid Textbox

Post by dragancesu »

You can solve with validation function
it's same but clear code

Code: Select all

		@ 10,10 TEXTBOX Text_1 ;
			   VALUE 123 ;
			   TOOLTIP 'Numeric TextBox' ;
			   NUMERIC ;
		 	   MAXLENGTH 5 ;
			   RIGHTALIGN ;
			   ON ENTER check_text_1()   ON LOSTFOCUS check_text_1()
			
			@ 40,10 TEXTBOX Text_2 ;
			VALUE ' '; //'Hi All' ;
			.
			.
			.
						
			FUNCTION check_text_1()
			
			if  <formname>.text_1.Value < 100 
   			   <formname>.text_1.SetFocus
                        Else
   			   <formname>.text_2.SetFocus
                        EndIF

			RETURN  .T.
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Valid Textbox

Post by franco »

Thank you all,
This is what I came up whith from all you examples.
With this I can put MYLIST procedure in my main program procedure file and use from any program or procedure in any large program by
sending the paramaters I want pick.
I used this a another large electric motor project and use foe action from buttons as well as below.
Hope this is useful for others. Saves making a lot of list boxes in programs.

Code: Select all

/*
 * HMG - Harbour Win32 GUI library Demo
 *
 * Copyright 2002 Roberto Lopez <mail.box.hmg@gmail.com>
 * http://www.hmgforum.com//
*/

#include "hmg.ch"

Function Main
PRIVATE MLAR := '', MLR := ''
	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 480 ;
		TITLE 'HMG Demo' ;
		MAIN 

		@ 10,10 TEXTBOX Text_1 ;
			VALUE 123 ;
			TOOLTIP 'Numeric TextBox' ;
			NUMERIC ;
			MAXLENGTH 5 ;
			RIGHTALIGN ;
			ON LOSTFOCUS if ( This.Value < 100 , This.SetFocus , Nil)


		@ 40,10 TEXTBOX Text_2 ; 
			VALUE ' '; 
			TOOLTIP 'Character TextBox' ;
			DISABLEDBACKCOLOR { 0,255,0 } ;
			DISABLEDFONTCOLOR { 255,255,255 };
			ON ENTER Form_1.Text_1.SetFocus ;                             // the parameter 4 is the number of items which sets height if list box
			ON LOSTFOCUS  If (len(alltrim(This.Value)) <> 0,{This.Value:= '', MLAR:={'  ','A','B','C','D'},This.Setfocus,MyList(' ',4),;
						 This.Value:= MLR},{Form_1.Text_1.Setfocus})    // In this case 0 (blank) is my prefered value

	END WINDOW

	Form_1.Center

	Form_1.Activate

Return Nil

Procedure MyList(ML,HI)
Local LA := 0,  HIT := 160, HIT1:=0
HIT1:= HIT+(HI*8)
HIT := (HIT1)
MLR := ALLTRIM(ML)
	IF .NOT. ISWINDOWACTIVE(WMYLIST)
	  DEFINE WINDOW WMYLIST ;
		AT 160,790 ;
		WIDTH 300 ;
		HEIGHT hit +120 ; //520 ;  //250 ;
		TITLE 'Pick Item ** Escape Will Exit' ;
                MODAL ;
		SYSMENU .F.
		
		ON KEY ESCAPE OF WMYLIST ACTION {WMYLIST.RELEASE}
		DEFINE LISTBOX LIST1
			ROW		2     //2
			COL		100
			WIDTH		100
			HEIGHT		hit + 40    //440
			ITEMS		MLAR   
			on dblclick {||{la:=Wmylist.list1.value},{ mlr:=(Wmylist.list1.item(la))}, {Wmylist.release}}
		END LISTBOX
		
		DEFINE button button_1                  // FOR BUTTON TO CLICK TO EDIT CUSTOMER
			ROW    hit + 60   //460
			COL    120
			WIDTH 60
			HEIGHT 20         // 20
		 TOOLTIP 'Exit With No Change'
		 CAPTION 'E&xit'
		 ACTION {wmylist.release}
		 
		 
		END button

	  END WINDOW

	 	WMYLIST.activate
	ELSE
		MSGINFO('Already in Use')
	ENDIF
Return

All The Best,
Franco
Canada
Post Reply