vb6 - Function returns empty result -


i getting empty msgbox when call function . have on code bellow

public function custom(byval tablename string, _     byval employeecode string, byval fieldname string, byval datatocheck string, _     optional byval codefieldname string = empty, optional byval codefieldvalue string = empty) boolean  dim lstrsql1 string dim lrstemp1 adodb.recordset  lstrsql1 = " select  " & fieldname & "   " & tablename & " id_card_no =" & datatocheck & "" 'msgbox (lstrsql1)  if len(trim$(codefieldname)) <> 0 , len(trim$(codefieldvalue)) <> 0    lstrsql1 = lstrsql1 & " , " & codefieldname & " <> '" & codefieldvalue & "'"   end if  set lrstemp1 = cobjdbconn.executesql(lstrsql1)  if lrstemp1 nothing     custom = false elseif not (lrstemp1.bof , lrstemp1.eof)     custom = true elseif lrstemp1.recordcount = 0     custom = false else     custom = false end if  if lrstemp1.state = adstateopen lrstemp1.close set lrstemp1 = nothing  exit function  errorhandle:      custom = false   end function 

the calling code here:

if gobjvalidation.custom(fstrtablename, gemployeecode, "employee_code", _                 trim$(txtidcardno.text)) = true                 msgbox (gemployeecode)                 call messagebox("this id number existing  employee. cannot enter duplicate number!using employee code:" & gemployercode & " ", okonly, information, defaultbutton1, me.caption)                 sstinformationtab.tab = 0 

as @arvo said, need make youre employeecode variable byref, assign value in function custom()

public function custom(byval tablename string, _     **byref employeecode string**, byval fieldname string, byval datatocheck string, _     optional byval codefieldname string = empty, optional byval codefieldvalue string = empty) boolean  dim lstrsql1 string dim lrstemp1 adodb.recordset      lstrsql1 = " select  " & fieldname & "   " & tablename & " id_card_no =" & datatocheck & ""     'msgbox (lstrsql1)      if len(trim$(codefieldname)) <> 0 , len(trim$(codefieldvalue)) <> 0        lstrsql1 = lstrsql1 & " , " & codefieldname & " <> '" & codefieldvalue & "'"     end if      set lrstemp1 = cobjdbconn.executesql(lstrsql1)      if lrstemp1 nothing         custom = false     elseif not (lrstemp1.bof , lrstemp1.eof)         custom = true         **lrstemp1.movefirst**         **employeecode = lrstemp1.fields("employee_code")**     elseif lrstemp1.recordcount = 0         custom = false     else         custom = false     end if      if lrstemp1.state = adstateopen lrstemp1.close     set lrstemp1 = nothing  exit function  errorhandle:     custom = false end function 

the double asterisks highlight changes made original code.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -