Type mismatch

Posted on 2004-09-16
Last Modified: 2013-12-18
I am editing a database done by a previous designer.

In one of the agents,
there is a sub function call BalanceK and when I try to run, it gives me error msg " Type mismatch" at this line ->old = profile.GetItemValue(fieldname & Cstr(6))(0)

Sub BalanceK(n As Integer)
      old = profile.GetItemValue(fieldname & Cstr(6))(0)
      newbal = Cdbl(old - totaldkotoshi(0))
      Call profile.ReplaceItemValue(fieldname & Cstr(6),Cdbl(newbal))
      Call profile.ReplaceItemValue(fieldname & Cstr(61),Cdbl(newbal))
End Sub

For fieldname, it is declare as Dim fieldname As String
and under Initialize,
leavetype = note.LeaveType(0)
fieldname = Left(leavetype,6)

I do not know where goes wrong.

Anyone can advise??
Thank you.
Question by:kopibean
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 19

Expert Comment

ID: 12081486
u need to make sub into function and pass the value to fieldname.

try this:
Function tmptest(tmpfield As String)
      old = profile.GetItemValue(tmpfield & Cstr(6))(0)
      newbal = Cdbl(old - totaldkotoshi(0))
      Call profile.ReplaceItemValue(tmpfield & Cstr(6),Cdbl(newbal))
      Call profile.ReplaceItemValue(tmpfield & Cstr(61),Cdbl(newbal))
End Function

And in Initialize,
leavetype = note.LeaveType(0)
tmpfield = Left(leavetype,6)

and for calling fn.,
Call tmptest(tmpfield)
LVL 24

Expert Comment

ID: 12084352
>     old = profile.GetItemValue(fieldname & Cstr(6))(0)
Try this instead
     old = profile.GetItemValue(fieldname & "6")(0)

Replace every line with cstr function similar to the one above


Expert Comment

ID: 12085108
- My guess is that the Item <fieldname>6 doesn't exist, so when you deference the "value" using (0) on the end, it fails with a type mismatch.  I would set a NotesItem, check to be sure it's valid, then get its Value.

Dim it As NotesItem
Dim itVal As String

set it=profile.getFirstItem(fieldname+"6")
if(not it is nothing) then itVal=it.values(0) else itVal=""

or something like that.  You could shorten it by using

if(profile.hasItem(fieldname+"6") then itVal=profile.getItemValue(fieldname+"6")

but then you're computing the string twice, and accessing the document twice.  I don't know how that compares, performance-wise, to computing the string once and constructing a NotesItem.
- I would also HIGHLY recommend defining your data types instead of letting LotusScript default to Variant for everything.  I've had no end of quirky bugs with Variants over the years.
- I would also HIGHLY recommend getting rid of all the globals that appear to be in use.  They're going to bite you in the ... uh ... wrong end, in the long run.
-   Hope this helps...

Author Comment

ID: 12099049

another agent is also having the same problem - Type mismatch.
I debug lotusscript and error is at this line->
totalbal = Cdbl(profile.GetItemValue("Childa3")(0))

Under this AlreadyTaken agent, the code for Sub Initialize code ->

Sub Initialize
      Set s = New NotesSession
      Set db = s.CurrentDatabase
      Set collection1 = db.Search("Form = ""MP""",Nothing,0)
      For j = 1 To collection1.Count
            Set profile = collection1.GetNthDocument(j)
          ' Annual
            totalbal = Cdbl(profile.GetItemValue("Annual3")(0))
            balnow = Cdbl(profile.GetItemValue("Annual6")(0))
            future = Cdbl(profile.GetItemValue("Annual5")(0))
            taken = Cdbl(totalbal - balnow - future)          
            Call profile.ReplaceItemValue("Annual4",Cdbl(taken))
            Call profile.ReplaceItemValue("Annual41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Health3")(0))
            balnow = Cdbl(profile.GetItemValue("Health6")(0))
            future = Cdbl(profile.GetItemValue("Health5")(0))
            taken = Cdbl(totalbal - balnow - future)          
            Call profile.ReplaceItemValue("Health4",Cdbl(taken))
            Call profile.ReplaceItemValue("Health41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Replac3")(0))
            balnow = Cdbl(profile.GetItemValue("Replac6")(0))
            future = Cdbl(profile.GetItemValue("Replac5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Replac4",Cdbl(taken))
            Call profile.ReplaceItemValue("Replac41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Unpaid3")(0))
            balnow = Cdbl(profile.GetItemValue("Unpaid6")(0))
            future = Cdbl(profile.GetItemValue("Unpaid5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Unpaid4",Cdbl(taken))
            Call profile.ReplaceItemValue("Unpaid41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Reserv3")(0))
            balnow = Cdbl(profile.GetItemValue("Reserv6")(0))
            future = Cdbl(profile.GetItemValue("Reserv5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Reserv4",Cdbl(taken))
            Call profile.ReplaceItemValue("Reserv41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Medica3")(0))
            balnow = Cdbl(profile.GetItemValue("Medica6")(0))
            future = Cdbl(profile.GetItemValue("Medica5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Medica4",Cdbl(taken))
            Call profile.ReplaceItemValue("Medica41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Marria3")(0))
            balnow = Cdbl(profile.GetItemValue("Marria6")(0))
            future = Cdbl(profile.GetItemValue("Marria5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Marria4",Cdbl(taken))
            Call profile.ReplaceItemValue("Marria41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Compas3")(0))
            balnow = Cdbl(profile.GetItemValue("Compas6")(0))
            future = Cdbl(profile.GetItemValue("Compas5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Compas4",Cdbl(taken))
            Call profile.ReplaceItemValue("Compas41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Matern3")(0))
            balnow = Cdbl(profile.GetItemValue("Matern6")(0))
            future = Cdbl(profile.GetItemValue("Matern5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Matern4",Cdbl(taken))
            Call profile.ReplaceItemValue("Matern41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Patern3")(0))
            balnow = Cdbl(profile.GetItemValue("Patern6")(0))
            future = Cdbl(profile.GetItemValue("Patern5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Patern4",Cdbl(taken))
            Call profile.ReplaceItemValue("Patern41",Cdbl(taken))
            totalbal = Cdbl(profile.GetItemValue("Childa3")(0))
            balnow = Cdbl(profile.GetItemValue("Childa6")(0))
            future = Cdbl(profile.GetItemValue("Childa5")(0))
            taken = Cdbl(totalbal - balnow - future)    
            Call profile.ReplaceItemValue("Childa4",Cdbl(taken))
            Call profile.ReplaceItemValue("Childa41",Cdbl(taken))
            profile.Save True,True
End Sub

Please advise!
LVL 24

Accepted Solution

HemanthaKumar earned 100 total points
ID: 12101813
before converting.. make sure the value that is returned is not null.


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question