New topic: 

Learning Real Studio: Loop Question

<http://forums.realsoftware.com/viewtopic.php?t=47274>

         Page 1 of 1
   [ 11 posts ]                 Previous topic | Next topic          Author  
Message        mikecotrone          Post subject: Learning Real Studio: Loop 
QuestionPosted: Tue Mar 12, 2013 8:22 pm                         
Joined: Tue Mar 05, 2013 2:33 pm
Posts: 8                Hi All,

I have been working with arrays and files today learning Real Studio. I have a 
road block which I am sure "how to" to, but I can't get it to work 

Basically I have a file I am splitting into rows. That is working. When I am 
populating a 4 column listbox this is working for the first 4 Rows in my file. 
I can't get it to continue on to Row 5.

Basically I have put it into a for loop and I only get the same 1-4 rows x 
times. Its not rolling to the next row #5 onward. Help?  When I try a do loop 
my app just hangs and never responds.

  FileByLineArray = Split(TextFile, EndOfLine)

  Listbox1.AddRow(FileByLineArray)
  Listbox1.Cell(Listbox1.LastIndex,0) = FileByLineArray(Counter+1)
  Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+2)
  Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+3)
  Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+4)

Thank you in Advance!     
_________________
Mike Cotrone - CCIE #8411 R&S, CCIE #8411 Voice
Chief Technology Officer 
Onepath Systems, LLC

Real Studio 2012 Mac OS, Windows, Ubuntu Linux  
                             Top                markmark          Post subject: 
Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 8:41 pm         
                
Joined: Fri Sep 24, 2010 6:12 pm
Posts: 33                And your for loop looks like?   
                             Top                mikecotrone          Post 
subject: Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 8:45 
pm                         
Joined: Tue Mar 05, 2013 2:33 pm
Posts: 8                markmark wrote:And your for loop looks like?

This was based on other web examples. So I know the UBound(FileByLineArray) has 
a value of -1 since I declared it as FileByLineArray()

I know I need to bump the row number but no matter what I do in the for loop I 
just repeat the same 4 rows on and on until the loop stops. I have even trying 
a manual stop integer for testing.  I have also tried for 0 to countlines and 
no avail.

  Countlines = Countlines + CountFields(TextFile, EndofLine)

  For Counter = 0 to ubound(FileByLineArray)
  Listbox1.AddRow(FileByLineArray)
  Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1)
  Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
  Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
  Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
  next

Here is a screen shot when I move my "For Counter = 0 to 15" (It kind of works 
but check the duplicate entries)
https://www.dropbox.com/s/8h3w8edtvsw5mpy/Screenshot-Realstudiotest.png


** Update: I found that even though my Countlines reports me 24 lines the For 
Counter = 0 to Countlines always gives me an out of bounds exception. through 
trial and error I can safely get all rows (with some duplicate entries per 
column) and it stops at 16 (For  Counter = 0 to 16).

Thoughts? (Below is my source text file)
��������
User Access Verification

Username: mcotrone
Password: 
cot-rtr1#term len 0
cot-rtr1#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
   D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
   N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
   E1 - OSPF external type 1, E2 - OSPF external type 2
   i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
   ia - IS-IS inter area, * - candidate default, U - per-user static route
   o - ODR, P - periodic downloaded static route

Gateway of last resort is 10.10.100.2 to network 0.0.0.0

   10.0.0.0/24 is subnetted, 3 subnets
C   10.10.5.0 is directly connected, FastEthernet0/1.5
C   10.10.10.0 is directly connected, FastEthernet0/1.10
C   10.10.100.0 is directly connected, FastEthernet0/1.100
S* 0.0.0.0/0 [1/0] via 10.10.100.2
cot-rtr1#      
_________________
Mike Cotrone - CCIE #8411 R&S, CCIE #8411 Voice
Chief Technology Officer 
Onepath Systems, LLC

Real Studio 2012 Mac OS, Windows, Ubuntu Linux  
                             Top                DaveS          Post subject: 
Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 8:56 pm         
                        
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4668
Location: San Diego, CA                You posted this in GENERAL, but elluded 
to the fact this was a WEB project??

The code you posted should work just fine (at least in the Desktop Model)....

Are you sure it is not adding the rows, and you might need to scroll to see 
them?

This is of course also assuming that uBound(FileByLineArray) is in fact > 4

And you are placing the lines from FilebyLineArray in BOTH rows and COLUMNS.

Assuming your data was the letters A-M (one letter per line for example)
you would end up with 

A B C D E
B C D E F
C D E F G
etc.

Also.... your ADDROW.... doesn't that give you an error? as you failed to 
provide an index to the Array.




EDIT : ARRAYS ARE ZERO BASED...... So it is 0 to 9  not 1 to 10 that may be the 
source of your out of bounds error      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                DaveS          Post subject: 
Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 9:00 pm         
                        
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4668
Location: San Diego, CA                For Counter = 0 to 
ubound(FileByLineArray)
  Listbox1.AddRow(FileByLineArray)
  Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1) <--- OUT OF 
BOUNDS HERE WHEN COUNTER=UBOUND(FILEBYLINEARRAY)
  Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
  Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
  Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
next


you will get this error... because COUNTER+1 exceeds your loop maximum      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                mikecotrone          Post 
subject: Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 9:02 
pm                         
Joined: Tue Mar 05, 2013 2:33 pm
Posts: 8                DaveS wrote:You posted this in GENERAL, but elluded to 
the fact this was a WEB project??

The code you posted should work just fine (at least in the Desktop Model)....

Are you sure it is not adding the rows, and you might need to scroll to see 
them?

This is of course also assuming that uBound(FileByLineArray) is in fact > 4

And you are placing the lines from FilebyLineArray in BOTH rows and COLUMNS.

Assuming your data was the letters A-M (one letter per line for example)
you would end up with 

A B C D E
B C D E F
C D E F G
etc.

Also.... your ADDROW.... doesn't that give you an error? as you failed to 
provide an index to the Array.




EDIT : ARRAYS ARE ZERO BASED...... So it is 0 to 9  not 1 to 10 that may be the 
source of your out of bounds error


Sorry this is a desktop app not Web also I have enabled Vertical and Horizontal 
scrolling. No dice  My data when I manually add the end integer in my for loop 
is doing exactly what you suggested above with the Letters. How do I get that 
to stop?  I do get an error with the ubound as the stop integer. Since I am 
reading in a text file with this information that varies how would you 
recommend I do this? I am reading the lines with countfields, but it gives me 
21 like my array depth but with the above situation is causing the lines to 
look like 16 causing an out of bounds exception when I count with my for loop 
to countlines (variable for Countfields).      
_________________
Mike Cotrone - CCIE #8411 R&S, CCIE #8411 Voice
Chief Technology Officer 
Onepath Systems, LLC

Real Studio 2012 Mac OS, Windows, Ubuntu Linux      

    Last edited by mikecotrone on Tue Mar 12, 2013 9:17 pm, edited 2 times in 
total.   
                             Top                markmark          Post subject: 
Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 9:06 pm         
                
Joined: Fri Sep 24, 2010 6:12 pm
Posts: 33                For Counter = 0 to ubound(FileByLineArray)
Listbox1.AddRow " "
Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1)
Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
next

Now, what's the result?

And because I'm old-school:

xx = ubound(FileByLineArray)
For Counter = 0 to xx - 4
Listbox1.AddRow " "
Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1)
Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
next     

    Last edited by markmark on Tue Mar 12, 2013 9:08 pm, edited 1 time in 
total.   
                             Top                mikecotrone          Post 
subject: Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 9:07 
pm                         
Joined: Tue Mar 05, 2013 2:33 pm
Posts: 8                DaveS wrote:For Counter = 0 to ubound(FileByLineArray)
  Listbox1.AddRow(FileByLineArray)
  Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1) <--- OUT OF 
BOUNDS HERE WHEN COUNTER=UBOUND(FILEBYLINEARRAY)
  Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
  Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
  Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
next


you will get this error... because COUNTER+1 exceeds your loop maximum

Yes and thanks that is what I am getting. I did add this at the top of my loop 
(Before the Addrow) and then after the last cell last index 
(Debugging.TextArea1.AppendText "# of Lines: " + Str(CountLines) + EndofLine)

At the top of my loop the Ubound array value is -1 and at the bottom it is 21. 
Sorry still working through this as my brain is still not thinking like a 
programmer yet.      
_________________
Mike Cotrone - CCIE #8411 R&S, CCIE #8411 Voice
Chief Technology Officer 
Onepath Systems, LLC

Real Studio 2012 Mac OS, Windows, Ubuntu Linux  
                             Top                mikecotrone          Post 
subject: Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 9:11 
pm                         
Joined: Tue Mar 05, 2013 2:33 pm
Posts: 8                markmark wrote:For Counter = 0 to 
ubound(FileByLineArray)
Listbox1.AddRow " "
Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1)
Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
next

Now, what's the result?

And because I'm old-school:

xx = ubound(FileByLineArray)
For Counter = 0 to xx - 4
Listbox1.AddRow " "
Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1)
Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
next

Since by Ubound begins at -1 I had to manually change my "For counter = 0 to 
16" for testing. I did what you asked and it just leaves Column 0 empty while 
continuing on to cell 1 through 3 with data. If you see my screen shot above in 
this thread you can see my rows are duplicating from column to column. I know 
if I run this block without the loop it is clean  with the first four rows 
(lines) of my file in Columns 0 - 3.      
_________________
Mike Cotrone - CCIE #8411 R&S, CCIE #8411 Voice
Chief Technology Officer 
Onepath Systems, LLC

Real Studio 2012 Mac OS, Windows, Ubuntu Linux  
                             Top                mikecotrone          Post 
subject: Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 11:37 
pm                         
Joined: Tue Mar 05, 2013 2:33 pm
Posts: 8                mikecotrone wrote:markmark wrote:For Counter = 0 to 
ubound(FileByLineArray)
Listbox1.AddRow " "
Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1)
Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
next

Now, what's the result?

And because I'm old-school:

xx = ubound(FileByLineArray)
For Counter = 0 to xx - 4
Listbox1.AddRow " "
Listbox1.Cell(Listbox1.LastIndex,1) = FileByLineArray(Counter+1)
Listbox1.Cell(Listbox1.LastIndex,2) = FileByLineArray(Counter+2)
Listbox1.Cell(Listbox1.LastIndex,3) = FileByLineArray(Counter+3)
Listbox1.Cell(Listbox1.LastIndex,4) = FileByLineArray(Counter+4)
next

Since by Ubound begins at -1 I had to manually change my "For counter = 0 to 
16" for testing. I did what you asked and it just leaves Column 0 empty while 
continuing on to cell 1 through 3 with data. If you see my screen shot above in 
this thread you can see my rows are duplicating from column to column. I know 
if I run this block without the loop it is clean  with the first four rows 
(lines) of my file in Columns 0 - 3.

Ok guys I simplified my code and also re-understood what i was really trying to 
do. Basically I had setup my listbox as you would for a multi-dimensional array 
when I was needing a single dimensional array. Anyhow here is what I was 
needing as many of you suggested. Now I have a regular expression that I need 
to search through every array element using "\b(?:\d{1,3}\.){3}\d{1,3}\b".  Any 
advice would be appreciated. 

  
FileByLineArray = Split(TextFile, EndOfLine)

for counter = 0 to UBound(FileByLineArray)
  Listbox1.AddRow FileByLineArray(Counter)
next


Thank you Everyone for the help.      
_________________
Mike Cotrone - CCIE #8411 R&S, CCIE #8411 Voice
Chief Technology Officer 
Onepath Systems, LLC

Real Studio 2012 Mac OS, Windows, Ubuntu Linux  
                             Top                timhare          Post subject: 
Re: Learning Real Studio: Loop QuestionPosted: Tue Mar 12, 2013 11:48 pm        
                 
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12144
Location: Portland, OR  USA                Why aren't you just doing
for counter = 0 to ubound(FileByLineArray)
  Listbox1.AddRow FileByLineArray(counter)
next


If that doesn't do what you want, then please explain what you want the listbox 
to look like when you're done.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 11 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to