OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-04-2012, 15:38
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default Splict funtction parts retrieval

I need to know how to increment the parts of a SPLIT FUNCTION within a for each loop
Code:
i = 0
    If optBoth Then
        For Each exp In Split(s, ",")
            Set nameShp = ActiveLayer.FindShape("name")
            nameShp.Text.Story = exp(i)
            i = i + 1
            Set numShp = ActiveLayer.FindShape("number")
            numShp.Text.Story = exp(i)
            i = i + 1
            Set sr = d.ActiveLayer.Shapes.All
            Set MyPage = ActiveDocument.InsertPages(1, False, ActivePage.Index)
            sr.CopyToLayer MyPage.ActiveLayer
        Next exp
    End If
"s" is a comma separated string consisting of a last name and number
(i.e. WARING,6,TINSLEY,16,RAINES,7,MARTEL,18,MARKS,9,KARRER,17,HUNTEBRINKER,5,HUNTEBRINKER,21,GREENWELL,11,FORBES,2,FELTS,12,AUTRY,32)
I want nameShp.text.story to equal the first part of "s", then numShp.text.story to equal the next part and so on through the loop.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 05-04-2012, 17:15
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Split

This will be easier if you use a For Next loop. Also you need to remove one of the i = i + 1 as the loop will advance itself. So something like this should work:
Code:
    Dim exp As Variant
    
    exp = Split(s, ",")
    
    For i = 0 To UBound(exp)
        Set nameShp = ActiveLayer.FindShape("name")
        nameShp.Text.Story = exp(i)
        i = i + 1
        Set numShp = ActiveLayer.FindShape("number")
        numShp.Text.Story = exp(i)
        Set sr = d.ActiveLayer.Shapes.All
        Set MyPage = ActiveDocument.InsertPages(1, False, ActivePage.Index)
        sr.CopyToLayer MyPage.ActiveLayer
    Next i
Best of luck,

-Shelby
Reply With Quote
  #3  
Old 06-04-2012, 07:30
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Code:
Dim exp As Variant
    
    exp = Split(s, ",")
    
    For i = 0 To UBound(exp)
        Set nameShp = ActiveLayer.FindShape("name")
        nameShp.Text.Story = exp(i)
        nameShp.OrderToFront
        i = i + 1
        Set numShp = ActiveLayer.FindShape("number")
        numShp.Text.Story = exp(i)
        numShp.OrderToFront
'if exp is empty then Exit For
        Set sr = d.ActiveLayer.Shapes.All
        Set MyPage = ActiveDocument.InsertPages(1, False, ActivePage.Index)
        sr.CopyToLayer MyPage.ActiveLayer
    Next i
OK, that works. So, how do I check if exp is empty so that I don't create an extra unused page at the end of my doc? Currently, (in my sample file), there are 12 names and numbers, but I end up with 13 pages.

Never mind. I answered my own question by adding watches to certain variables and came up with this...
Code:
If optBoth Then
        exp = Split(s, ",")
        For i = 0 To UBound(exp)
            Set nameShp = ActiveLayer.FindShape("name")
            nameShp.Text.Story = exp(i)
            nameShp.OrderToFront
            i = i + 1
            Set numShp = ActiveLayer.FindShape("number")
            numShp.Text.Story = exp(i)
            numShp.OrderToFront
            If i = UBound(exp) Then Exit For
            Set sr = d.ActiveLayer.Shapes.All
            Set MyPage = ActiveDocument.InsertPages(1, False, ActivePage.Index)
            sr.CopyToLayer MyPage.ActiveLayer
        Next i
    End If
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.

Last edited by ddonnahoe; 06-04-2012 at 07:42.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:51.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com