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 28-02-2008, 08:24
bprice's Avatar
bprice bprice is offline
Member
 
Join Date: Oct 2006
Location: Edmundston, New Brunswick, Canada
Posts: 87
Default change form text

hi all!

quick question! in a textbox in a form I have (example) \test1\test2\test3\test4 .... and I want to only keep whats after test2 ... so \test2\test3\test4 ... so it'll search the text for "text2" and remove everything ahead of it in the text box... regardless of how much text appears before "test2"...

is this possible?
Reply With Quote
  #2  
Old 28-02-2008, 08:43
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

case INsensitive compare
Code:
textbox1=mid$(textbox1, instr(1, textbox1, "\test2", vbTextCompare)+1)
case SENSitive - you can use a shortened form of instr:
Code:
textbox1=mid$(textbox1, instr(textbox1, "\test2")+1)
Reply With Quote
  #3  
Old 28-02-2008, 08:56
bprice's Avatar
bprice bprice is offline
Member
 
Join Date: Oct 2006
Location: Edmundston, New Brunswick, Canada
Posts: 87
Default very nice!

hahaha i have no idea how it works... but it does! your the man! thanks again! hopefully someday I'll get good enough with this stuff that I can help others like you do, instead of asking asking asking!
Reply With Quote
  #4  
Old 28-02-2008, 11:47
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

you'll certainly want to befriend with these core string manipulation functions: mid, left, right, instr, ucase, lcase, trim/rtrim/ltrim, instrRev, chr/chrw, asc/ascw, space, string - and their advanced siblings: format, FormatNumber, FormatDateTime, replace, split, join, strcomp, strconv
Reply With Quote
  #5  
Old 28-02-2008, 11:54
bprice's Avatar
bprice bprice is offline
Member
 
Join Date: Oct 2006
Location: Edmundston, New Brunswick, Canada
Posts: 87
Default

it's funny you just wrote a reply... I was just getting ready to make another post! your code earlier worked great... but I just discovered I need to do something different!

example \test1\test2\test3\test4

i need to not only remove \test1 (your earlier code took care of this) but now I need to remove \test4 as well... resulting in my textbox only containing text2\test3

I was able to use left$ rather then mid$, and it worked for removing \test4 ... but I don't know what to write to remove both test1 and test4 at the same time, leaving just test's 3 & 4...
Reply With Quote
  #6  
Old 28-02-2008, 12:00
bprice's Avatar
bprice bprice is offline
Member
 
Join Date: Oct 2006
Location: Edmundston, New Brunswick, Canada
Posts: 87
Default

nevermind... i just figured it out! hahaha i'm just messing around till i find something that works... and I got it!
Reply With Quote
  #7  
Old 28-02-2008, 12:26
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

once I'm here :-) it's MID with three params
Reply With Quote
  #8  
Old 28-02-2008, 12:43
bprice's Avatar
bprice bprice is offline
Member
 
Join Date: Oct 2006
Location: Edmundston, New Brunswick, Canada
Posts: 87
Default

Quote:
Originally Posted by wOxxOm View Post
it's MID with three params
hahaha don't feel to embarrassed for me when I write this... but is this what you mean?

Code:
Platefilename = Mid$(platepathtext, InStr(1, platepathtext, "\fs", vbTextCompare) + 1)(platepathtext, InStr(1, platepathtext, ".", vbTextCompare) - 1)
i'll tell you what i am doing... I have a textbox called platepathtext (that has a full path & filename in it returned from a getfilebox) that I in turn want to strip all text before "\fs" and after the "." in the filename... I can make one or the other work... remove the \fs or anything after the "." ... but I can't make it remove both! I thought I had it earlier... but I didn't!

the other other problem is... if I manually modify text in the box after it removes either of those things (i've removed all the text needed... but need to modify the pathname that already exists)... the next time i get an error because it's not removing anything, because obviously they aren't there (nothing before \fs or after the "." *because i've removed the dot*)....

So I'm interested in your "mid with three parameteres"... i'm not sure how to write it! argh... i hate being a beginner! lol
Reply With Quote
  #9  
Old 28-02-2008, 12:57
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

when instr can't find a substring it returns 0. And nor MID, nor LEFT/RIGHT functions don't like the starting symbol to be 0 or less - which is the case when you decrease the instr.

Use an intermediate index variable:

Code:
dim posFS&, posDot&
posFS = InStr(1, platepathtext, "\fs", vbTextCompare)
posDot = InStr(platepathtext, ".") 'no need to use case insensitivity for non-alphabet
Platefilename = _
      Mid$(platepathtext, _
           posDot+1, _
           iif(posFS=0, 999, posFS-posDot-1))
here MID takes the text as 1st param, starting position as 2nd, and length of the chunk to be copied as the 3rd. Length may be 0 but not negative, if the length is larger than original text then everything up until its end is copied starting with the position specified in 2nd param.

iif is a handy shortcut for inplace decision making, here it is used to handle the case when no \FS found and posFS = 0 - we sure can't feed negative value to MID, that's what 999 takes care of

Last edited by wOxxOm; 28-02-2008 at 12:59.
Reply With Quote
  #10  
Old 28-02-2008, 13:28
bprice's Avatar
bprice bprice is offline
Member
 
Join Date: Oct 2006
Location: Edmundston, New Brunswick, Canada
Posts: 87
Default doesn't work

if i simply find any file in any directory... i get the files extension as a result in my text box!

if I choose the directory containing \fs in the name... i get Run-Time Error '5': invalid proceedure call or arguement

i kind of understand what you are doing with this code... but not enough to determine the problem!
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Text ... then Curve/Line segments to same color dungbtl CorelDRAW/Corel DESIGNER VBA 4 22-02-2008 08:02
Striping a word down to the first letter only knowbodynow CorelDRAW/Corel DESIGNER VBA 9 19-04-2007 15:14
Select specified text, change font size? fiddler2b CorelDRAW/Corel DESIGNER VBA 3 23-04-2006 08:11
Find and Replace Text with Form RVogel CorelDRAW/Corel DESIGNER VBA 1 24-03-2005 09:37
simple example chinkyk CorelDRAW/Corel DESIGNER VBA 3 19-10-2004 14:50


All times are GMT -5. The time now is 01:16.


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