Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stuck in Valid Code
Message
From
22/04/2021 02:11:42
 
 
To
17/04/2021 13:21:43
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01679864
Message ID:
01679949
Views:
73
Hi,
I have on my text-, edit-,check- and optionboxes a property: ValuenotEmpty = .F.
Before the update of the data, a procedure 'CheckObligatory' is executed.
With this it checks all the fields for and value=empty and ValueNotEmpty = .T.
Boxes which are empty the bordercolor is red and update prevented.
*********************************************************
* Program....: CHECKOBLIGATORY
* Version....:
* Author.....: Koen Piller
* Date.......: 28 October 2019, 05:10:06
* Notice.....: No Copyright © Use at your own risk.
* Parameters.:
* Called by..:
* Purpose....: check for all obligatory fields with value
**********************************************************
Lparameter oContainer

Local liCtrl As Integer, ;
	llChecked As Boolean, ;
	lnAnswer As Number, ;
	lnCtrlCount As Number, ;
	loControl As Object, ;
	loControlParent As Objectm

m.llChecked = .F.

If Parameters() = 0
	m.loControlParent = Thisform
Else
	m.loControlParent = m.oContainer
Endif

Do Case
	Case Atc("Pageframe",m.loControlParent.BaseClass)#0
		m.lnCtrlCount = m.loControlParent.PageCount
	Case Atc(m.loControlParent.BaseClass,"Optiongroup,Commandgroup")#0
		m.lnCtrlCount = m.loControlParent.ButtonCount
	Otherwise
		m.lnCtrlCount = m.loControlParent.ControlCount
Endcase
lcWrong = ''
For m.liCtrl = 1 To m.lnCtrlCount

	Do Case

		Case Atc(m.loControlParent.Controls[m.liCtrl].BaseClass,"Pageframe") # 0
		SET STEP ON 
			This.checkobligatory(m.loControlParent.Pages[m.liCtrl])
	
		Case Atc(m.loControlParent.Controls[m.liCtrl].BaseClass,"Optionbutton") #0 And This.UserControlMode
			If Pemstatus(m.loControl,"ValueNotEmpty",5) And m.loControl.ValueNotEmpty = .T.
				m.loControl = (m.loControlParent.Buttons[m.liCtrl])
				m.llChecked = .T.
				If m.loControl.Value = 0
					m.lcWrong = m.lcWrong + Chr(10) + Chr(13) + m.loControl.Name
					m.loControl.BorderColor = Rgb(255,0,0)
					m.loControl.BorderStyle = 0
					m.loControl.ToolTipText = "You have not made a selection"
					m.loControl.Refresh()
				Endif
				This.lIncorrect = Iif(loControl.Value = 0,.T., This.lIncorrect)
			Endif

		Case Atc(m.loControlParent.Controls[m.liCtrl].BaseClass,"Optiongroup,Commandgroup") #0 And This.UserControlMode
			This.checkobligatory(m.loControlParent.Controls[m.liCtrl])

		Case Atc(m.loControlParent.Controls[m.liCtrl].BaseClass,"Container") # 0 Or Atc(m.loControlParent.Controls[m.liCtrl].BaseClass,"Page") # 0
			This.checkobligatory(m.loControlParent.Controls[m.liCtrl])

		Case Atc(m.loControlParent.Controls[m.liCtrl].BaseClass,"TextBox") # 0
			m.loControl = (m.loControlParent.Controls[m.liCtrl])
			If Pemstatus(m.loControl, "Valuenotempty",5) And m.loControl.ValueNotEmpty = .T. And loControl.Name=='txtDate'
				m.llChecked = .T.
				If Isempty(m.loControl.Value)
					m.lcWrong = m.lcWrong + Chr(10) + Chr(13) + m.loControl.Parent.Comment
					m.loControl.Parent.Shape.Visible = .T.
					m.loControl.ToolTipText = 'This field cannot be empty'
					m.loControl.Refresh()
				Else
					m.loControl.Parent.Shape.Visible = .F.
					m.loControl.ResetToDefault("Bordercolor")
					m.loControl.ResetToDefault("Tooltiptext")
				Endif
				This.lIncorrect = Iif(Isempty(m.loControl.Value), .T.,This.lIncorrect)
			Else
				If Pemstatus(m.loControl, "Valuenotempty",5) And m.loControl.ValueNotEmpty = .T.
					m.llChecked = .T.
					If Isempty(m.loControl.Value)
						m.lcWrong = m.lcWrong + Chr(10) + Chr(13) + m.loControl.Name
						m.loControl.BorderColor = Rgb(255,0,0)
						m.loControl.ToolTipText = 'Thia field cannot be empty'
						m.loControl.Refresh()
					Else
						m.loControl.ResetToDefault("Bordercolor")
						m.loControl.ResetToDefault("Tooltiptext")
					Endif
					This.lIncorrect = Iif(Isempty(m.loControl.Value), .T.,This.lIncorrect)
				Endif

			ENDIF
			

		Case Atc(m.loControlParent.Controls[m.liCtrl].BaseClass,"TextBox,EditBox") # 0
			m.loControl = (m.loControlParent.Controls[m.liCtrl])
			If Pemstatus(m.loControl, "Valuenotempty",5) AND VARTYPE(m.loControl) <> 'L'
				If m.loControl.ValueNotEmpty = .T.
					m.llChecked = .T.
					If Isempty(m.loControl.Value)
						m.lcWrong = m.lcWrong + Chr(10) + Chr(13) + m.loControl.Name
						m.loControl.BorderColor = Rgb(255,0,0)
						m.loControl.ToolTipText = 'Thia Field cannot be empty'
						m.loControl.Refresh()
					Else
						m.loControl.ResetToDefault("Bordercolor")
						m.loControl.ResetToDefault("Tooltiptext")
					Endif
					This.lIncorrect = Iif(Isempty(m.loControl.Value), .T.,This.lIncorrect)
				Endif
			Endif

		Case Atc(m.loControlParent.Controls[m.liCtrl].BaseClass,"ListBox,ComboBox,Spinner") # 0 And This.UserControlMode
	Endcase

	m.llIncorrect = This.lIncorrect
Endfor


If !Empty(m.lcWrong)
	=Messagebox( m.lcWrong, 0+64+0, "You have some fields without a value", 0 )  &&  OK = 1
Endif
Return llIncorrect
This will warn users to give wrong data.

Stay healthy,
Koen

>Howdy and greetings all:
>
>The thesis of my code is that I want to check particular textboxes against validation (i.e. format, empty etc) and if it fails valiation, then set the lostfocus method of the textbox to light red to give a visual signal to the user. That part works correctly, in my text, I'm checking for empty first name text box, and it fires off and sets the lost focus to light red. I created a method to handle the validation and created a property in the textbox subclass called txt_Box_Valid. When I enter text in the text box, it's like the cursor is stuck and I can't tab to any other field on the form. Here's code as is below:
>
>Form Method: chkTextbox
>parameters lc_WhichBox
>if lcWhichbox = 'txtFirstname'
> check if empty, if empty perform the first name lostfocus event
> set textbox subclass property txt_box_valid to .F.
>else
> set textbox subclass property txt_box_valid to .T.
> return
>endif
>
>FirstName Text box valid method:
>thisform.chk_textbox('txtFirstname')
>
>FirstName Text box lost focus method:
>if this.txt_box_valid = .f.
>dodefault()
>this.backcolor = bright red warning color
>else
>nodefault
>endif
Previous
Reply
Map
View

Click here to load this message in the networking platform