Solved

Type mismatch

Posted on 2004-09-16
8
1,141 Views
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)

Code:
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.
0
Comment
Question by:kopibean
8 Comments
 
LVL 19

Expert Comment

by:madheeswar
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)
0
 
LVL 24

Expert Comment

by:HemanthaKumar
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

~Hemanth
0
 

Expert Comment

by:Mehzuku
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...
0
 

Author Comment

by:kopibean
ID: 12099049
now,

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))
            
          'Health
            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))
            
          'Replac
            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))
            
          'Unpaid
            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))
            
          'Reserv
            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))
            
          'Medica
            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))
            
          'Marria
            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))
            
          'Compas
            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))
            
          'Matern
            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))
            
          'Patern
            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))
            
            'Childa
            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
            
      Next      
      
End Sub

Please advise!
Thanks!
0
 
LVL 24

Accepted Solution

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

0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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