Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing values into a table or array 2

Status
Not open for further replies.

puck2

Programmer
Sep 8, 2003
7
0
0
US
I'm making a script to place notes as one note on the face of a drawing and I'm keeping track of which notes are to have a flag on their number.
I've been able to hard code the positions just fine but I would like to be able to add the position to a table or array to have the flag generated based on the positions returned.

Here is an example of the code

Code:
 AddText = MsgBox("Would you like to add your own flag note?", vbYesNoCancel, "Notes")
	
	If AddText = vbCancel Then
	
	Call PrintNotes(Text_N1, BufferText, PosN8, PosN9, PosN10)
	
	Exit Sub
	
	End If
	
	If AddText = vbYes Then
	
	Text_N10 = InputBox("Type your flag note here.", "Add Flag Note", "Your note")
	
	p = p + 1
	
	f = CStr(p)
	
	PosN10 = Len(BufferText) + 3
	
	Text_N10 = UCase(Text_N10)
	
	BufferText = BufferText & + Chr(10) + _
					 + Chr(10) + _
					 f & "  " & Text_N10
					 
	End If

In this case I would like to add PosN10 to a table or array and then I would only have to pass the table or array instead of passing PosN8, PosN9 and PosN10 etc.

Any ideas?

TIA
 
puck2,
There are several ways to do this. If you know how many parameters you are going to stuff into your array you can explicitly declare the array with the number of parameters:

Code:
Dim arrPos(3)
arrPos(1) = Parm1
arrPos(2) = Parm2
arrPos(3) = Parm3

If you don't know how many parameters you are going to have you can declare your array dynamically, then add parameters as you need to:

Code:
Dim arrPos()

' More code

x = x + 1
Redim Preserve arrPos(x)
arrPos(x) = ParmX

Using the "Preserve" keyword does not clear out the exisiting array parameteres.

Or another slick command is "Array". Do this to add all of your parameters at once:

Code:
Dim arrPos     ' no array brackets

' More code

arrPos = Array(Parm1, Parm2, Parm3)

Zy
 
Great, method 2 is what I'm pursuing now because I don't know the number of parameters.

The only problem I have now is getting the parameters back out of the array one at a time.
I'm trying this method.

Code:
If UBound(arrPos) <> 0 Then
For i = 0 to arrPos.Count - 1

Text.SetParameterOnsubString catBorder,i , 1, 7

Only problem here &quot;i&quot; is obviously the position in the array and not the value that was stored.
I need the parameter retreived in place of &quot;i&quot;.

Any ideas?

Thanks
 
puck2,
To retrieve the value of the array, use the syntax that is similar to stuffing the array:


Code:
If UBound(arrPos) <> 0 Then
For i = 0 to arrPos.Count - 1
    Text.SetParameterOnsubString catBorder, arrPos(i), 1, 7
Next


Or if there is a problem reading the array, you may have to add an interim step:


Code:
If UBound(arrPos) <> 0 Then
For i = 0 to arrPos.Count - 1
    x = arrPos(i)
    Text.SetParameterOnsubString catBorder, x, 1, 7
Next


Zy
 
Thanks
I'll give this a try.
And yes there was a problem reading the array so I will use the interim step.
Thanks Again
puck2
 
You've just gotten slightly confused between JScript/JavaScript and VBscript:

arrayObject.count is JavaScript
UBound(arrayObject) is VBscript

so try:
Code:
If UBound(arrPos) <> 0 Then
For i = 0 to UBound(arrPos)
    Text.SetParameterOnsubString catBorder, arrPos(i), 1, 7
Next

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Even more confusing this actually CATScript.
It's based on VB Script but the API's are poorly written and not always up to date.

I've tried the Ubound method and it seems to produce the same result in this case. (It was actually the first method I tried for that line of code.)

Thanks to everyone,
This is a great forum!!!
puck2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top