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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For next loop with array?

Status
Not open for further replies.

KM8888

Programmer
Nov 21, 2011
69
US
Hi all, I have kind of a newbie question. I am using the PCOMM application for my vb scripts and searching how to do this has left me with a bit of a headache.

Basically I want to set an array, have it loop through certain rows and columns while using gettext to grab the data from each row and column. I then want to try and match all of those gettext values with another spot on the screen and if any of them match up then I would create a msgbox indicating "match found for ..." I know a For Next loop is involved with this but its a bit hard for me to grasp so far.

I was wondering if this was possible and if anybody had a bit of sample code with some description on it? I was confused by most examples I found that were using excel since there seemed to be some discrepancies. If anybody has any tips for how I can do something like this I will be in your debt! Thanks.
 

hi,
loop through certain rows and columns
... of WHAT application? Excel, Access, other???

Please post your code, as most of us have not idea what PCOMM object properties & methods are available.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi, sorry. Well a lot of the code in PCOMM can be related to Excel... I don't really have a code written up because I'm struggling as to where to start with it. Basically the main change is that instead of cells in excel PCOMM has fields with lengths. I'm not sure that helps so much, if not I can see what I can throw together as a brief example. Thanks
 
Here's a link that addresses a connection to PCOMM.


You really need to define more information regarding what is happening in Excel (mapping) with rows & columns with respect to PCOMM rows and columns, if I understand what you intend to do. We can help you after you get the connection stuff established.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
My apologies again, I'll try and post some sample code from my session. So like your link has it starts out with this bit of code at the start

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]

so an example of having the macro type something at a specific row and column would be

.SendKeys "this is a test", 3, 1

This function would type "this is a test" at row 3, column 1.

Basically I want to make an array with the gettext feature to store a bunch of values that I can later match up so if I did

.Gettext (.CursorposRow, .CursorposCol, 5)

So doing that gets the text at my current cursor position for 5 characters.

Generally I would set a value for that like

Dim myValue

myValue = .Gettext (.CursorposRow, .CursorposCol, 5)

so if I replaced the .CursorposRow, .CursorposCol with 3,1 like the first example I'd get the text from 3,1 instead.

So using 3, 1 I am basically asking how can I set a bunch of values to one array if I started the loop at 3,1 and gottext for every 3rd row starting from 3,1 so it would go like

.Gettext (3,1,5)
.Gettext (6,1,5)
.Gettext (9,1,5) etc...

Does this help at all? If not I will try and just paste a whole code of an example and point out various areas of it like what I attempted to do here. Sorry if I'm not the best at describing :(

 


So lets assume that you have an array with values to put in a row & column on the sheet, then something like this...
Code:
  with sheets("YourSheetName")
    for lRow = 0 to Ubound(YourArray, 1)
       for iCol = 0 TO Ubound(YourArray, 2)
          .cells(lrow+1, icol+1).value = YourArray(lrow, icol)
       next
    NEXT
  end with


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Looks like it's on a track for what I am trying to do, I guess this is where my real newbieness comes in, when I see examples like that I'm not sure what the numbers stand for like

for lRow = 0 to Ubound(YourArray, 1)
for iCol = 0 TO Ubound(YourArray, 2)

What exactly are these saying if I may ask? Thank you btw!
 


lRow & iCol are variables used in a For...Next loop that incriments the variable by 1 between the x To y values.

In this case, these two For...Next loops are incrimenting thru an array named YourArray, with 2 dimenstions, defining data in a 2-dimentional table. The first elements' indices in VB defaults to ZERO and the last elements' indices can be determined by the UBound() function for each dimension.

Check out VBA Help for a more comprehensive definition of For..Next, Arrays and LBound() & UBound().


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
You're looking for info on VB Script for PCOMM, this is a VBA forum. These are two different animals.

That said, I'm not sure exactly what you're trying to do but you can use Excel to completely control and automate pretty much everything in PCOMM. I know because I've done it. You can control up to 26 sessions at once, reading and writing. It's been awhile though and the code is on another PC. If you're interested, let me know and I'll dig it up. There is some really bad code out there that does it the hard way.

Here's a link to what ubound is

Basically, ubound gets the highest value of your array so the for-next loop knows where to stop. The number is optional, you only need it if you have a multi-dimensional array. If you're a newbie, just stick with one dimension. An arguably better way is to use

For i = lbound(array) to ubound(array). That way you won't miss the first element.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top