Solved

Type mismatch

Posted on 2004-09-16
8
1,130 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
Comment Utility
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
Comment Utility
>     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
Comment Utility
- 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
Comment Utility
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
Comment Utility
before converting.. make sure the value that is returned is not null.

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now