forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Another search and replace question...

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
MarkTrubo
Contributor
Contributor


Joined: 27 May 2001
Posts: 148
Location: Long Island, NY

PostPosted: Sun Sep 01, 2002 10:57 pm    Post subject: Another search and replace question... Reply with quote

OK, so I wrote a program a while back for doing mail merged e-mails. The program makes four component files that are then send with a program called Windmail. I suppose I could just send them directly with a .dll, but that is besides the point.

Anyway, my data has a header line that defines the variables, like [EMAIL]|[FNAME]|[LNAME]|[ADDRESS], etc. I load the data list, parse the headers, then load the body copy template into a list and go through it line by line look if there is a place holder that matches one of the header variables (like Dear [FNAME]), find the position and length of the place holder and replace it with the data for that variable. When I am done with each line of the body copy, I save the file and move to the next record in my database. Windmail assembles four files that I build for each e-mail - a body file, a header file, and attachment file, and a distribution list file for cc's. It works fine, but my program is both slow and a resource hog that eventually drains the resources of the computer it is running -- if there are too many records in the data. Once the four files are build for each record, windmail sends them out pretty fast, so my troubles are just on the VDS side.

Any suggestions how to do this more efficiently to pick up speed and stop sucking resources?
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1565

PostPosted: Mon Sep 02, 2002 3:19 am    Post subject: Reply with quote

Try this one out, its a modified search and replace script I posted about a week ago. This one should handle any type of search and replace needed:


Code:

dialog CREATE,New Dialog,-1,0,578,281

  dialog ADD,LIST,LIST1,18,11,542,244
  dialog SHOW

  list add,list1,"[FNAME] says: Yes my first name is: [FNAME]"
  list add,list1," "
  list add,list1,"Yes my email address is [EMAIL] !"
  list add,list1,"Let's not get too personal but my last name is [LNAME], yes it's [LNAME]"
  list add,list1,"Why do you want to know my address?"
  list add,list1,"Okay no need to pull out the warrant, here it is you ..."
  list add,list1,"[ADDRESS]"
  list add,list1,"is that good enough for you?"
  list add,list1,"okay okay i'll go over with it one more time, you better listen this time"
  list add,list1,"Name: [FNAME] [LNAME] Email: [EMAIL] Address: [ADDRESS]"
  list add,list1,"happy?????????"

  rem Set the %%SearchReplaceVar holds the character you
  rem want replaced then | then the actual new characters you want, for example
  rem I use [FNAME] then I replace it with 'John'
  %%searchreplacevar = "[FNAME]|John"
  gosub searchreplaceroutine
  %%searchreplacevar = "[LNAME]|Doe"
  gosub searchreplaceroutine
  %%searchreplacevar = "[EMAIL]|none@none.com"
  gosub searchreplaceroutine
  %%searchreplacevar = "[ADDRESS]|1234 West Nonayabusiness@chr(10)@chr(13)My City, NA 10101"
  gosub searchreplaceroutine
   
  wait event






:searchreplaceroutine
  option fieldsep,|
  list create,1
  list create,2
  parse "%%BeforeChar;%%AfterChar",%%SearchReplaceVar

  rem HERE ASSIGN FROM THE LISTBOX YOU WANT TO READ FROM, I'M USING LIST1
  rem IN THIS EXAMPLE AND ASSIGNING IT TO 1.
  list ASSIGN,1,LIST1

  %%index = 0
  repeat
    %%word = @item(1,%%index)
    %%fullword = @trim()
    repeat
      %%pos = @pos(%%BeforeChar,%%word)
      if @greater(%%pos,0)
        if @not(@equal(%%pos,1))
          %%fullword = %%fullword@substr(%%word,1,@pred(%%pos))%%AfterChar
        else
          %%fullword = %%fullword%%AfterChar
        end
        %%word = @strdel(%%word,1,@sum(%%pos,@pred(@len(%%BeforeChar))))
      end
    until @equal(%%pos,0)
    %%fullword = %%fullword%%word
    list add,2,%%fullword
    %%index = @succ(%%index)
  until @equal(%%index,@count(1))
  rem HERE ASSIGN FROM THE LISTBOX YOU WANT TO READ FROM, I'M USING 2
  rem IN THIS EXAMPLE AND ASSIGNING IT BACK TO LIST1.
  list ASSIGN,LIST1,2
  list close,2
  list close,1
  exit


:close
  exit
Back to top
View user's profile Send private message
MarkTrubo
Contributor
Contributor


Joined: 27 May 2001
Posts: 148
Location: Long Island, NY

PostPosted: Mon Sep 02, 2002 11:32 am    Post subject: Reply with quote

That looks promising! I can't wait to go to work on Tuesday and try it on a good sized database! Thanks for putting in the time to give me such a detailed answer!

I think mine was being such a hog since, now that I look at it, I am loading the body copy file for each record rather than loading it once and assigning it to another list then saving it after the work is done. In hind sight, that was pretty dumb of me. Also, your search and replace looks to be more efficient.

I will post the results on Tuesday!!!

Regards,

Mark
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group