×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Macro question

Macro question

Macro question

(OP)
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.

RE: Macro question

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.

RE: Macro question

Are you using Visual Basic 6?

Bradley

RE: Macro question

(OP)
I ONLY HAVE THE VB PACKAGE THAT CAME WITH SOLIDWORKS. NOT SURE WHAT VERSION THAT IS.

RE: Macro question

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

RE: Macro question

(OP)
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.

RE: Macro question

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

RE: Macro question

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

RE: Macro question

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.

RE: Macro question

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

RE: Macro question

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources