Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro question

Status
Not open for further replies.

CADGemini

Mechanical
May 12, 2004
481
I have downloaded a macro that works with the custom and configuration specific properties in solidworks. My company requires certain data to be entered into both of these fields. I have managed to get the macro customized to where it is somewhat useful to our company. Keep in mind that I am very new to the macro/Visual Basic world. However I want to be able to scroll through the properties that are displayed in the user form by hitting the enter key on my keyboard. The way it is set up now I have to select the field in which I want to modify and then hit the TAB key twice to get to the entry field. I would like to click on the property in which I want to modify and then type the info I need and hit the enter key and it will automatically scroll to the next property and I can type the info again. I hope this makes sense to all you macro users. I can send the file to you if you would like to mess with it. I have tried several things and still can't seem to get it right.
 
Replies continue below

Recommended for you

The "EnterKeyBehavior" of the text box defines what hitting the "Enter" does here: either creates a new line in the text box, or "Tabs" to the next control.

Which control it moves to is defined by the "TabIndex" property.
 
I ONLY HAVE THE VB PACKAGE THAT CAME WITH SOLIDWORKS. NOT SURE WHAT VERSION THAT IS.
 
jkintest,
Do not use CAPS. Sounds like you are yelling.
Try setting your TabIndex in the Properties, in the order you want the “enter” to go. Zero for 1st, 1 for second and etc. If that works, we will go for more.


Bradley
 
Thanks Bradley,

I will try that and get back to you at a later date. have alot on my plate today so maybe sometime next week.
 
jkintest,
Here is the code I used with TabIndex set to 0, 1, 2. Worked better than I thought.

Option Explicit

Private Sub TextBox1_Change()
End Sub

Private Sub TextBox2_Change()
End Sub

Private Sub TextBox3_Change()
End Sub

Private Sub UserForm_Click()
End Sub


Bradley
 
Do you have any code inside the events?

The code you posted above does not do anything... (?)

For example...
Code:
Private Sub TextBox1_Change()
End Sub

Change is the Event that is Fired when you make a change to TextBox1...

If you want to use this event...
(for example forcing Lower Case or Upper Case letters)
You Could Do Something like this:

Code:
Private Sub TextBox1_Change()
  Dim Curs As Integer, CursLen As Integer

  Curs = TextBox1.SelStart      'Preserve Cursor Position
  CursLen = TextBox1.SelLength  'Preserve Selection Length

  TextBox1.Text = UCase(TextBox1.Text) 'Make text UpperCase

  TextBox1.SelStart = Curs      'Restore Cursor Position
  TextBox1.SelLength = CursLen  'Restore Selection Length
End Sub

Private Sub TextBox2_Change()
  Dim Curs As Integer, CursLen As Integer

  Curs = TextBox2.SelStart      'Preserve Cursor Position
  CursLen = TextBox2.SelLength  'Preserve Selection Length

  TextBox1.Text = LCase(TextBox2.Text) 'Make text LowerCase

  TextBox2.SelStart = Curs      'Restore Cursor Position
  TextBox2.SelLength = CursLen  'Restore Selection Length
End Sub

Otherwise, you don't need that code...

When dealing with computers, there are 10 things you need to know: one, zero, and the rest is Binary.
-Josh S

 
The enter key inside a text box has no meaning unless you have a button set to "default". Then when the enter key is pressed, focus will switch to that button. If you want to use the enter key to "tab" to the next field, you must program it. Unfortunately, I too, am hard pressed for time. I know I have an example of the code somewhere, but I could not find it. I think you have to put the code in the keypress or keydown event and look for the enter key code of 13.
 
Regg,
In VB6 you are right, that what I thought for VBA within SolidWorks. Wrote the code above and just pressing “enter key” after typing in some junk text moved me to my next text box. Worked really cool.
SWVB101,
You are right about the events. My example was to show that with the enter key being pressed you would move to the next text box. Now I would wander if I wanted two lines of text in the one text box would I have to hold the control down?


Bradley
 
No...

Right click on the textbox and select properties (if they are not already shown)

Go down to the M's and find MultiLine.
It should be set to False by default.
Double click it to set it to true, then you can use enter to go to the next line, and put as many lines as you want...

When dealing with computers, there are 10 things you need to know: one, zero, and the rest is Binary.
-Josh S

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor