I am having an issue with a Subscript out of range error. I am trying to do two arrays within each other this is my code:If doc.ColdSand(0) <> “” Then
c = Ubound(doc.ColdSand)
Redim Preserve coldsand(c)
For x = 0 To c
coldsand(x) = doc.ColdSand(x)
tmpscold = Cdbl(tmpscold) + Cdbl(Right(coldsand(x),4))
con = Ubound(doc.Condiments)
Redim Preserve condiments(con)
For b = 0 To con
condiments(b) = doc.Condiments(b)
Next
'Call doc.ReplaceItemValue(tmpExtra, condiments(b))
tmpExtra = condiments(b)
tmpDress = “”
tmpDish = coldsand(x)
tmpCategory = “Cold Sandwiches”
Call LunchTicket
Next
End If
I am getting the error on the tmpExtra = condiments(b) line. Any ideas why this is happening.
Thanks for the help
Christy
Subject: Looking for more information
First, you don’t need the For b=0 To con inside your For x=0 To c loop because the value of doc.Condiments never changes while inside the first For loop.
What type of variable is tmpExtra and what do you want to do with the values inside of it later in your code?
Subject: Re: Looking for more info
tmpExtra is a string. I am looking to put the values on a different form that I will be creating. but when you take the value from the condiments field itself you only get the first value. I need to have all of the values.Thanks
Christy
Subject: Ok
You can create the new document and then just set the field equal to the first document. No need to do anything special if that’s all you are needing to do.
newDoc.Condiments = doc.Condiments
Subject: Re: OK
Condiments White Bread
Wheat Bread
Rye Bread.
No Bun
Lettuce
Tomato
Mayo
Mustard
Ketchup
Pickle
Cattleman’s Sauce
Honey Mustard
Tartar Sauce
Cheese
What I have listed above is what is in the condiments checkbox. they are able to pick more than one option. I need to take what they have checked and but it in another document.
When I do just the newdoc.Condiments = doc.Condiments I get only the first item that they have checked. If they have check more than one I don’t get the others. That is why I was trying to loop through the field to grab all of the data. But like I said when I that and try to put it in the field on the new form I get the Subscript out of range error.
Thanks
Christy
Subject: Hmm
Try this then.
Dim item as NotesItem
Set item = doc.GetFirstItem(“Condiments”)
Call newDoc.ReplaceItemValue(“Condiments”,item.Values)
Subject: Re: Subscript out of Range
In the debugger, what does it show as b’s value?
Then look and see if condiments has an array value for whatever that value.
Subject: Re: Subscript out of range
Okay so in the debugger the b is saying 3 but the con is saying 2. not really sure what all of that means. any ideas.Thanks
Christy
Subject: Here’s your problem
This section of the code:
For b = 0 To con
condiments(b) = doc.Condiments(b)
Next
'Call doc.ReplaceItemValue(tmpExtra, condiments(b))
tmpExtra = condiments(b)
The last line executes after b has been through all the possible values. It’s an undocumented feature of “For” loops that, after they’re done, the For variable (in this case, b) is left set to the highest value plus one. So, if condiments has entries 0 to 2, b is left set at 3.
I’m unclear on what you’re trying to do with the code, but you should not be referencing the b variable like this outside of the For loop.
Subject: Re: heres your problem
When I take the (b) off of the line that say tmpExtra = condiments(b) I get a Type mismatch on Condiments any ideas
Thanks
Christy
Subject: What exactly are you trying to set tmpExtra to equal?
tmpExtra = condiments(b)
The above only sets tmpExtra to the single value in condiments. Is that what you are looking to accomplish?
Subject: Re: What exactly are you trying to set tmpExtra to equal?
I am trying to set the tmpExtra = to everything that is in the condiments check box field.