Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Type mismatch

Posted on 2004-09-16
8
Medium Priority
?
1,168 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
[X]
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
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 400 total points
ID: 12101813
before converting.. make sure the value that is returned is not null.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

688 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