3 Replies - 1013 Views - Last Post: 20 May 2014 - 09:29 PM Rate Topic: -----

#1 enasuico18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-February 09

Need help

Posted 19 May 2014 - 08:56 AM

Hi. i have a problem with my code. the situation is even if i already went to stop the code to proceed if there is no value, it will still detect that has no value. the code is

dim temp as integer
dim transnum as integer

if rsD!cuADTransnum = null then

   temp = 1

else

   temp = rsD!cuADTransnum

end if

'the checktransnum will check if there is a existing transnum in the database

if checkTransnum(transnum) = true then

   transnum = 1 + temp

else

   transnum = temp

end if




thats the code. also, the cuADTransnum is the index for the database.

any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Need help

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4361
  • View blog
  • Posts: 12,180
  • Joined: 18-April 07

Re: Need help

Posted 19 May 2014 - 10:25 AM

Well from what I remember of vb6 days VB understood nulls as vbNull when working with database values for one thing. From the code you show here you are simply checking if that field is null and if so, setting temp equal to 1, otherwise set it to the cuADTransnum value. No where do you stop anything there.

On top of that you don't seem to set "transnum" to a value prior to checking it with checkTransnum. Meaning that transnum is always zero when you go to run checkTransnum. I am not sure that is what you want. You are essentially running if checkTransnum(0) = true then each time.

:)
Was This Post Helpful? 0
  • +
  • -

#3 enasuico18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-February 09

Re: Need help

Posted 19 May 2014 - 06:46 PM

thanks. will update this once i tried it at school. thank you for the enlightenment.
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Need help

Posted 20 May 2014 - 09:29 PM

You'll need to use the IsNull function, so:

if IsNull(rsD!cuADTransnum) then


The reason that you can't use "if x = Null" or whatever is because any value compared to Null returns Null, not True. For example, if you go to the Immediate window and type "? Null = Null" the answer will be Null. So you will find that your expression never evaluates to True even if the field contains a null value.

This post has been edited by BobRodes: 20 May 2014 - 09:31 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1