I created a program that will create a new file (copy from a seed and place the newly named model in user location) followed by replacing various portions of text throughout a mutli modeled dgn file.
Unfortunately the 'replace' option of the program is hard coded. I would like to allow the user to enter text into a textbox, press a commandbutton and that entered text will populate the CadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING (entered data)" in a portion of code CadInputQueue.SendCommand "MDL silentload KEYIN FINDREPLACETEXT,CHNGTXT CHANGE DIALOGTEXT" . and replace the text in the models. Does that make sense?
I have tried a couple other variations of revising/replace text and the find/replace gives me the preferable outcome, and so far it has been the easiest to follow.
I tried something like this(and a couple other variations), without any success:
CadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING " & ReplaceBox1.Text, True
I am not the most proficient at VBA yet, as I am re-learning as I go, but with some success as I have taken classes about 10 years ago( 02 & 03) and are using the same old class books. I get the 'Compile error: Wrong number of arguments or invalid property assignment' message box and the SendKeyin is highlighted, but not in yellow like during debugging.
Any help on the correct variable syntax would be appreciated or even a 'hey you are barking up the wrong tree with the find/replace tool, use (this) instead."
Thanks for any comments
The problematic portion of the code is here:
If myModel.Type = msdModelTypeNormal Then ' verify that it is a cell If myModel.CanBePlacedAsCell Then ' make the model active myModel.Activate CadInputQueue.SendCommand "MDL silentload KEYIN FINDREPLACETEXT,CHNGTXT CHANGE DIALOGTEXT" CadInputQueue.SendKeyin "FIND DIALOG SEARCHINCELLS True" CadInputQueue.SendKeyin "FIND DIALOG ZOOM False" CadInputQueue.SendKeyin "FIND DIALOG PAN False" CadInputQueue.SendKeyin "FIND DIALOG SEARCHSTRING Full_Name" CadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING (entered data)" 'need to add value from textbox ' CadInputQueue.SendKeyin "CHANGE TEXT FIND" CadInputQueue.SendKeyin "CHANGE TEXT ALLFILTERED" Counter = Counter + 1 End If End If
Unknown said:CadInputQueue.SendCommand "MDL silentload KEYIN FINDREPLACETEXT,CHNGTXT CHANGE DIALOGTEXT"
You need to verify that your proposed command or key-in is valid. If I key-inMDL silentload KEYIN FINDREPLACETEXT,CHNGTXT CHANGE DIALOGTEXTthen I get a MicroStation error MDL loader: could not load application KEYIN.
Since there isn't a KEYIN application, that's seems a reasonable message. It's nothing to do with VBA. TryMDL silentload FINDREPLACETEXT,CHNGTXT CHANGE DIALOGTEXT
Apart from that, your key-ins look good to me.
Regards, Jon Summers LA Solutions
You are correct, the 'keyin' can be deleted and it still functions. Thanks, anytime I can clean up the code I am happy.
To help clarify further, if I change this line: CadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING " & ReplaceBox1.Text, True
to this:
CadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING wicked" 'need to add value
The vba works great. in every model the words Full_Name are replaced with wicked. I would like to be able to have the user add their own text in ReplaceBox1 (VB textbox), click the commandbutton and process the text replacements, without the hard-coded (entered data) is it does now.
BTW - thank you for such a quick response.
Unknown said:I would like to be able to have the user add their own text
First, create a new procedure that contains your existing code...
Public Sub ChangeText (ByVal find As String, ByVal replace As String) ... copy your above code hereEnd Sub
Change the following lines...
CadInputQueue.SendKeyin "FIND DIALOG SEARCHSTRING Full_Name"toCadInputQueue.SendKeyin "FIND DIALOG SEARCHSTRING " & find
CadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING (entered data)" toCadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING " & replace
Add a UserForm to your VBA project. Add two text boxes, one for find (name txtFind) and one for replace (name txtReplace). Add a command button (name cmdChangeText).
Click the command button. VBA creates an event handler for you: cmdChangeText_click. Add code to that procedure...
Sub cmdChangeText () ChangeText txtFind.Text, txtReplace.TextEnd Sub
Test & debug.
Answer Verified By: Jeremy Cswercko
Fantastic! Worked like a champ. Took the variable, dropped it back into my code, works great.
Thank you for your help!