Checking Null values and Not null values in foxpro9 - visual-foxpro

I got some fields from SQL server into my Foxpro cursor as below.
stra="SELECT cCm_Sgl_TaxInv,cInvNo FROM MIS.dbo.vInvFinalAll where cInvNo=?thisform.txtInvoiceNo.value"
SQLEXEC(hndOps,stra,'TaxInv')
And I need to check null values and not null values using IF condition. I wrote the following code and it does not give the expected result.
SELECT TaxInv
IF NOT ISNULL(cCm_Sgl_TaxInv)
ELSE
ISNULL(cCm_Sgl_TaxInv)
thisform.cmdCreate.Enabled = .T.
MESSAGEBOX("The value is already inserted")
endif
How can I do this?

It is not very clear what you are asking here, checking your code, probably this is what you meant:
IF ISNULL(TaxInv.cCm_Sgl_TaxInv)
thisform.cmdCreate.Enabled = .T.
MESSAGEBOX("The value is already inserted")
endif
EDIT: This could be simpler for what you are trying to do:
text to m.stra noshow
SELECT case when cCm_Sgl_TaxInv is null then 1 else 0 end as txStatus
FROM MIS.dbo.vInvFinalAll
where cInvNo=?thisform.txtInvoiceNo.value
endtext
SQLEXEC(m.hndOps,m.stra,'TaxInv')
if (TaxInv.txStatus = 1)
thisform.cmdCreate.Enabled = .T.
MESSAGEBOX("The value is already inserted")
endif

You only seem to need to do something if the value is null, therefore assuming that:
The 'taxinv' cursor will only have one record.
You want to enable the command button only if the value is null
select taxinv
if isnull(taxinv.cCm_Sgl_TaxInv)
thisform.cmdCreate.Enabled = .t.
else
messagebox("The value is already inserted.")
endif

Related

How i can check if a guid is empty in genexus 15?

I'm trying to check if a variable with data type GUID is empty, but all this way is going to else.
//Defined variable to empty `GUID`
&PRODUTOATRIBUTOVariacao.SetEmpty()
if &PRODUTOATRIBUTOVariacao.ToString().Trim() <> '00000000-0000-0000-0000-000000000000'
GDebug('Not empty')
else
GDebug('Empty')
endif
This way i get the correct Empty log, but don't look the most appropriate way to check this.
I also tried:
if &PRODUTOATRIBUTOVariacao.ToString().Trim() <> GUID.Empty()
GDebug('Not empty') else
GDebug('Empty') endif
This way i get not empty
Use IsEmpty() method:
&PRODUTOATRIBUTOVariacao.SetEmpty()
...
if &PRODUTOATRIBUTOVariacao.IsEmpty()
GDebug('Empty')
else
GDebug('Not empty')
endif

how acess the report column value in oracle-apex?

I need the "elabora prenotazione" button to be shown only when the column "stato prenotazione" is "IN SOSPESO"
I tried to set a condition but I don't know how to pick the column value
If I understand your question, this could help:
For the source of your report:
SELECT
CASE
WHEN stato_prenotazione = 'in sospeso' THEN 'elabora prenotazione'
ELSE ''
END name_of_column,
prenotazione,
username,
nome,
cognome,
viaggio,
stato_viaggio,
data_prenota,
stato_prenotazione,
numero_ospiti
FROM your_table
Then set the column "name_of_column" to type: link, and fill the target.
Wrap a condition around a call to apex_page.get_url within your SQL, so it will only produce a link when relevant
Example of function in use, sans condition:
https://azureoutput.wordpress.com/2017/10/18/custom-hyperlink-in-interactive-report/
Use this to make the button look prettier, and maybe get some other ideas
https://www.grassroots-oracle.com/2015/12/tutorial-include-action-button-in-report.html
See this in regard to escaping special characters, otherwise you'll just see HTML in your report
https://www.grassroots-oracle.com/2017/01/escape-special-characters-apex-demo.html
This could be resolved by a simple case statement as #sara mentioned.
something like:
select (case stato_prenotazione when 'in sospeso' then 'elabora prenotazione' end) as your_column
I would not keep else condition so that the column will simply contain null value if the condition is not met.

How to get record data from locate?

In VFP 6 I have a table called "cars" and inside a button I want to find an ID based on the name. What did I do wrong?
... code
SELECT cars
LOCATE FOR ALLTRIM(UPPER(name)) = variable_read_from_textbox
IF NOT FOUND()
messagebox("not found")
ELSE
messagebox(cars.id_car)
ENDIF
Running the code works ok when the name is not found but when it is found it errors out.
Thanks!
Your code is right in general. Slight modification for safety and fix for error:
SELECT cars
* this implies an exact match, regardless of set exact, and makes casing same
* remember this wouldn't use an index unless there is an index with the same signature
LOCATE FOR ALLTRIM(UPPER(name)) == ALLTRIM(UPPER(m.variable_read_from_textbox))
IF NOT FOUND()
messagebox("not found")
ELSE
messagebox(transform(cars.id_car))
ENDIF
As far as I remember, in VFP6, messagebox() was not yet capable transforming the value to string for you and expects a string (you didn't tell what the error is but that should be it).
A little caution about your search.
ALLTRIM(UPPER(name))
will NOT use an index, unless there is an index with key "ALLTRIM(UPPER(name))". If there is, it would be used, but such an index is actually useless because of the alltrim(). A better index would simply be:
Upper(name)
and then your search would look like:
variable_read_from_textbox = ALLTRIM(UPPER(m.variable_read_from_textbox))
SET EXACT ON
SELECT cars
LOCATE FOR UPPER(name) = m.variable_read_from_textbox
IF NOT FOUND()
...

QTP handling Null values with public functions

I am trying to write a QTP Script which works as follows
* takes a column from table checks if it is null
if yes
it adds that column name in a variable .
Later that column name will be used to display to user that all such fields are left blank .
Something like this:
Set rsRecordset1 = dbConnection.Execute("select formcd,sndrpstlcd,recppstlcd,sndrcntrycd, from test_data where trk in ('"&tin&"')")
If rsRecordset1.EOF = false Then
Blank_field="blank_fields->"
formcd = rsRecordset1("formcd").value
typcd="formcd"
Call validatenull (typcd,Blank_field)
packaging = rsRecordset1("packaging").value
typcd="packaging"
Call validatenull (typcd,Blank_field)
......
Public function validatenull (typcd,Blank_field)
If (isnull(typcd) )Then
Blank_field = Blank_field & " " & typcd &", "
End If
End Function
Value of blank_Field is expected to catch values as "blank_fields->Form_id,packaging (Considering Form_id, Packaging passes Null values) {It shouldnt add values which are not Null to blank_fields}
In simpler words
ss = Null
call nnn(ss)
Public function nnn(ss)
If isnull(ss) Then
msgbox("yes")
End If
End Function
Has Error that msgbox does not populates But,
ss= Null
nnn(ss)
If isnull(ss) Then
msgbox("yes")
End If
Populates Msgbox as Yes
But I want Case 1 to be working and I do not want to add any more variables to the function name.
IF By making an Array we can do it, please suggest .
It appears your function works fine, but you are passing the wrong values. From your code snippet:
formcd = rsRecordset1("formcd").value
typcd="formcd"
Call validatenull (typcd,Blank_field)
When you call 'validatenull', you are passing the variable 'typecd'. On the previous line, you populate this variable with a string, so it will never be null. It appears what you intended to pass was the variable 'formcd'. Your second call to 'validatenull' does the same thing. Here is your first call modified to use the other variable.
formcd = rsRecordset1("formcd").value
typcd="formcd"
Call validatenull (formcd,Blank_field)

Why does recordset.RecordCount equal 1 but recordset.EOF and recordset.BOF both equal True

I have a very simple query that only returns one record. When I try to get the value out of the only column in the only record, I get "Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record." What's going on here? The code that is causing the error doesn't even execute if RecordCount is 0 and I have verified that the recordset does in fact contain a record.
Code is below. Error is thrown when trying to set strDN. It's so dead simple but I can't figure out where I'm going wrong.
EDITED TO INCLUDE COMMAND
<LDAP://DC=something,DC=com>;(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(employeeID=01234567));distinguishedName;subtree
Set adoRecordset = adoCommand.Execute
If adoRecordset.RecordCount > 0 Then
strDN = adoRecordset.Fields("distinguishedName").Value
Set objUser = GetObject("LDAP://" & strDN)
objGroup.add(objUser.ADsPath)
End if
The recordcount property leaves the cursor at the end of the recordset, so you cannot then obtain the record (eof=true), you must movefirst. Use a different cursor type, because the default cursor type is forward only:
'' Assign cursorType that allows forward and backward movement.
adoRecordset.cursorType = 3 ''adOpenStatic
See https://www.w3schools.com/asp/prop_rs_cursortype.asp
I use
If Not adoRecordset.EOF And Not adoRecordset.BOF Then
...
End If
For This Scenario
Try
Set adoRecordset = adoCommand.Execute
If adoRecordset.RecordCount > 0 Then
adoRecordset.MoveFirst 'Move to the first record
strDN = adoRecordset.Fields("distinguishedName").Value
Set objUser = GetObject("LDAP://" & strDN)
objGroup.add(objUser.ADsPath)
End if
-EDIT-
Have a look at the following link. There are some causes listed, and solutions for most of them:
http://classicasp.aspfaq.com/general/why-do-i-get-bof-or-eof-errors.html
[I was wrong about this - thanks, Dave] I believe you need to call adoRecordset.MoveNext (or whatever the call is) before attempting to get the value of a field in the recordset.
Calling adoRecordSet.Requery() after RecordCount request can also help in this situation, if your query isn't that complex to execute it the second time.

Resources