TabSritp & Multipage

M

Maperalia

Waht is the different between TabStrip and Multipage?. When do I know which
one to use?..
I have a form with two pages. Each page has label, Textbox, and OK button.
However, I do not know how to setup the code to allow the following:
1.- When click "Page 1" run the "macro 1"
1.- When click "Page 2" run the "macro 2"

Could you please help me with this code?

Thanks in advance.
Maperalia
 
P

Peter T

Waht is the different between TabStrip and Multipage?. When do I know
which
one to use?..

A Multipage is a "container" object, like a Frame. You can place other
controls on each page and the control's parent is the multipage.

A Tab strip can be made to look like a MultiPage but placing other controls
on it merely places them over it, you can't have separate controls per tab
(though you might toggle their visibility depending on the selected tab).
I have a form with two pages. Each page has label, Textbox, and OK button.
However, I do not know how to setup the code to allow the following:
1.- When click "Page 1" run the "macro 1"
1.- When click "Page 2" run the "macro 2"

Put a MultiPage and a Tabstrip on a userform

Private Sub MultiPage1_Change()
With MultiPage1
Me.Caption = .Value & " " & .Pages(.Value).Name
End With
End Sub

Private Sub TabStrip1_Change()
With TabStrip1
Me.Caption = .Value & " " & .Tabs(.Value).Name
End With
End Sub

Regards,
Peter T
 
M

Maperalia

Peter;
Thanks for your quick response.
According to the information you just gave me. Mlutipages is the more
suitable for me. I copied the code to use this form. Correct me if I wrong, I
understood that since I have two pages I will use the following:

'###Start of 1st Page ###################
Private Sub MultiPage1_Change()
With MultiPage1
Me.Caption = .Value & " " & .Pages(.Value).Name
End With
End Sub
'#### End of 1st Page ###################

'### Start of 2nd Page ###################
Private Sub MultiPage2_Change()
With MultiPage1
Me.Caption = .Value & " " & .Pages(.Value).Name
End With
End Sub
'#### End of 2nd Page ##################


In addition, could yiou please tell me what statement I need to write in my
module to recognize this form?

Thanks.
Maperalia
 
P

Peter T

I guess(?) you mean you have one Multipage control, named "MultiPage1",
which has two pages. Your concept is wrong, you trap events for the entire
MultiPage, not individual pages. The code I gave you will tell you which
page the user has selected, if indeed you actually need to know that. So

Note the current page is indicated by the MultiPage's Value property, the
first page has value 0, the second page is 1, etc

Normally you will place additional controls on each page and trap their
events as needed.
In addition, could yiou please tell me what statement I need to write in
my
module to recognize this form?

I don't follow this, what do you want to "recognize", where from and when.

Regards,
Peter T
 
M

Maperalia

Peter;
You are absolutely right I did not interpret it correctly. I sorry my skills
level of VBA is low. I have done simple macros; however, this is first time
I am working with forms.
This is the code of my object that I current have:

'#### Start Object's Code ########
Public Vertical_Line As Double
Public Horizontal_Line As Double
Public Distance As Double
Public Angle As Double

Private Sub bOK_Click()
Make sure the user is entering numbers and not text
If IsNumeric(txtDistance.Text) And IsNumeric(txtAngle.Text) Then
Distance = txtDistance.Text
Angle = txtAngle.Text
Hide
Else
MsgBox "You must enter numeric values for all fields"
End If
End Sub
'#### End Object's Code ########


The multipages form, page1 and page2 will use the same object's code (shown
above). The different is that page1 uses horizontal values in my drawing and
page2 uses vertical values in my drawing. Could you please tell me how to
trap it the event?.
Also, in my macro I do not know how to make it work. Basically, when:
1.- I click page 1 and enter the values I want it to go to specific
statement in my module.
2.- I click page 2 and enter the values I want it to go to other specific
statement in my module.

This is the statement I have in my module for the form:
'#### Start User form ################################
Dim RevolveDistance As Double
Dim RevAngle As Double
Dim newForm As New frmRevolve

newForm.Caption = "Enter Values in Inches"
newForm.Show
RevolveDistance = newForm.Distance / 39.37008
RevolveAngle = newForm.Angle / 57.29577951 'Converting From Radians to
Degrees
Set newForm = Nothing
'#### End User form #####################################


Kind regards.
Maperalia
 
P

Peter T

I'm afraid I don't follow what you are trying to do. You say page1 and page2
both use the same object's code (the OK button's code), but pages don't
"use" anything.

What controls do you have on each page and what's their objective. Better
still what's the overall objective.

Regards,
Peter T
 
M

Maperalia

Peter;

I do apologize for giving you a hard time. I believe that I am not choosing
the right path to accomplish what I am looking for.
Let me explain you what exactly I have and what I want to achieve.

I recorded a macro using VBA in Solid Works. Solid Works is a 3D CAD solid
modeling. The macro I recorded has the followed steps to create the solid
part I need:
1.- Draw a sketch. It has lines and arcs.
2.- Draw a centerline in horizontal position This centerline is located 5
inches from the center of the sketch (is called distance).
3.- Revolve the sketch with angle of 90 degrees selecting the horizontal line.
4.- Draw a centerline in vertical position. This centerline is located 5
inches from the center of the sketch (is called distance too).
5.- Revolve the sketch with angle of 90 degrees selecting the vertical line.

The sketch is a constant (WILL NEVER CHANGE). However, the location
(distance) of the horizontal centerline and vertical centerline line will
change along with the angle.

Basically, what I want to achieve is the following:
1.- Have window message where I will have an option to choose in what
direction I want to revolve. Could be call:
* “Revolve with Horizontal Centerline†or
* “Revolve with Vertical Centerlineâ€.
If I choose revolve with horizontal centerline just this statement will work
and I want the statement which has revolve with vertical centerline blocked.
In another hand, If I choose revolve with vertical centerline just this
statement will work and I want the statement which has revolve with
horizontal centerline blocked.

2.- After I selected which direction to revolve. I need to entry the values.
The form will ask me for:
* Distance, and
* Angle.

The form to entry the values was created already (see the previous post I
sent you). However, I do not know how to create the option to select revolve
with vertical or horizontal centerline.
Do you think you can help me to create this option? I will really appreciate
it.

Kind regards.
Maperalia
 
P

Peter T

Sounds like a pair of Optionbuttons is what you are after. These are
mutually exclusive, so with only two only need to trap the change event of
one of them.

Try the following in a new project, code in a userform with controls as
indicated and code "Sub Test()" in a normal module

'''''''' code in Userform1
' with two "wide" option buttons
' named OptionButton1 & OptionButton2
' and a commandbutton

Public gbCtrLineHoriz As Boolean


Private Sub CommandButton1_Click()
' the OK close button
' set Cancel = True in properties
' do any validate stuff here

Me.Hide
End Sub

Private Sub OptionButton1_Change()
gbCtrLineHoriz = OptionButton1.Value

End Sub


Private Sub OptionButton2_Click()

End Sub

Private Sub UserForm_Initialize()
Me.OptionButton1.Value = True

OptionButton1.Caption = "Revolve with Horizontal Centerline"
OptionButton2.Caption = "Revolve with Vertical Centerline"

End Sub
''''' end userform code

'''' code in a normal module
Sub test()
Dim frm As UserForm1
Dim bCtrLineHoriz As Boolean

Set frm = UserForm1 ' triggers initialize event
frm.Show
' modeless form, code waits here
' until user hides or closes the form

' then code reverts here with the form and
' properties still in memory

bCtrLineHoriz = frm.gbCtrLineHoriz

Unload frm
Set frm = Nothing

If bCtrLineHoriz Then
MsgBox "Horizontal"
Else
MsgBox "Vertical"
End If

End Sub

''' end code normal module

From what I gather, the Multipage and its pages is not directly relavant as
far as any code is concerned.

Regards,
Peter T
 
M

Maperalia

Peter;

OHHH!! My God you are amazing. You read my mind in this theme. This is
exactly the form I was looking for. Thank you very much. I know now that I
was completely lost. I ran it and I got the message I need without problem.

However, I would like to know how to point the selection (horizontal or
vertical) directly to the statement because when I choose horizontal in the
form I got horizontal revolve and when I choose vertical in the form I got
horizontal revolve too.

These are the statements I have to revolve the sketch using the horizontal
or vertical direction:

'######## Select Horizontal Centerline and Sketch1 to Revolve it ############
'Select Horizontal Centerline
boolstatus = Part.Extension.SelectByID2("Line2", "SKETCHSEGMENT",
-0.04111859620927, -0.1015753044947, 0, False, 4, Nothing, 0)
'Part.Parameter("D2@Sketch1").SystemValue = RevDistance ' CHANGED THIS TO MY
VAR
'Select Sketch1
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0,
True, 0, Nothing, 0)
'Revolve it
Dim myFeature As Object
'Part.FeatureManager.FeatureRevolve RevAngle, False, 0, 0, 0, 1, 1, 1 '
CHANGED THIS TO MY VAR
Set myFeature = Part.FeatureManager.FeatureRevolve(1.570796326795, False,
0, 0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False
'#######################################################################


'######## Select Vertical Centerline and Sketch1 to Revolve it ############
'Select Vertical Centerline
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT",
0.142235, 0.044925, 0, False, 4, Nothing, 0)
'Part.Parameter("D2@Sketch1").SystemValue = RevDistance ' CHANGED THIS TO MY
VAR
'Select Sketch1
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0,
True, 0, Nothing, 0)
'Revolve it
'Dim myFeature As Object
'Part.FeatureManager.FeatureRevolve RevAngle, False, 0, 0, 0, 1, 1, 1 '
CHANGED THIS TO MY VAR
Set myFeature = Part.FeatureManager.FeatureRevolve(1.570796326795, False,
0, 0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False
'#######################################################################


What statement should I have to target the selection I got in my form for
horizontal or vertical?

Kind regards
Maperalia
 
P

Peter T

I'm glad the previous suggestion worked for you, based on what you had
described it didn't need too much mind reading!

But this time I have no idea what you are trying to say, all the code you
quote does not mean anything to me.

If, and this is just a guess, you want to do something when user changes an
OptionButton -

Private Sub OptionButton1_Change()
gbCtrLineHoriz = OptionButton1.Value

If gbCtrLineHoriz Then
' call routine to do horizontal stuff
Else
' call routine to do vertical stuff
End If

End Sub


Previously in the form's Initialize event I suggested you do
Me.OptionButton1.Value = True

but don't do that, instead do

gbCtrLineHoriz = True

and ensure OptionButton1 is selected (its Value property = True) at design
time.

Regards,
Peter T
 
M

Maperalia

Peter;
Thanks for the additional code. I added in my macro and after I ran I got
the following error message:

Run-time error '424':
Object Required

Then I click debug and it is highligthing at the following statement:

gbCtrLineHoriz = OptionButton1.Value

What does is mean? and how can I fix it please ?..

Kinr regards.
Maperalia
 
P

Peter T

It probably means you do not have an Optionbutton named "OptionButton1" on
the form.

Regards,
Peter T
 
M

Maperalia

Peter;
Thanks for your quick response. I followed your advise and is fixed it.
I added the following in the code you sent me:

Private Sub OptionButton1_Change()
gbCtrLineHoriz = OptionButton1.Value
If gbCtrLineHoriz Then
Call macro1
Else
Call macro2
End If
End Sub

However, after I ran I got the following error message:

Run-tim error '91':
Object variable or with block variable not set.

Then when I click debug. It is highligthing at:
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False,
0, Nothing, 0)

This statement is located in the macro1 which is:


'###### START OF MACRO1 #############

Sub Revolve_Horizontal_Center()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim myFeature As Object


Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc


boolstatus = Part.Extension.SelectByID2("Line33", "SKETCHSEGMENT",
0.003588671546553, -0.03123281095829, 0.02897111198368, True, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Line33", "SKETCHSEGMENT",
0.003588671546553, -0.03123281095829, 0.02897111198368, False, 4, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, True,
0, Nothing, 0)

Set myFeature = Part.FeatureManager.FeatureRevolve(1.570796326795, False, 0,
0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False

Part.ClearSelection2 True
Part.ShowNamedView2 "*Trimetric", 8

End Sub
'###### END OF MACRO1 #############

Could you please tell me how to fix it?
Thanks
Kind regards.

Maperalia
 
M

Maperalia

Peter'
I plotted the wrong macro. Please discard the previous one.

The macro1 is:


'### START OF MACRO1 ########
Sub Revolve_Vertical_Centerline()

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim myFeature As Object

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False,
0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line34@Sketch1",
"EXTSKETCHSEGMENT", 0.08887711938888, -0.01670467080663, 0, True, 0, Nothing,
0)
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False,
0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line34@Sketch1",
"EXTSKETCHSEGMENT", 0.08887711938888, -0.01670467080663, 0, True, 4, Nothing,
0)

boolstatus = Part.Extension.SelectByID2("Sketch1<2>", "SKETCH", 0, 0, 0,
True, 0, Nothing, 0)
Set myFeature = Part.FeatureManager.FeatureRevolve(1.570796326795, False, 0,
0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False

Part.ClearSelection2 True
Part.ShowNamedView2 "*Trimetric", 8


End Sub
'### END OF MACRO1 ########
 
M

Maperalia

Peter;
I sorry I sent the wrong Macro. Please discard the previuos one.
The Macro1 is the followinG:

' ##### START MACRO1 #####
Sub Revolve_Vertical_Centerline()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim myFeature As Object

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False,
0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line34@Sketch1",
"EXTSKETCHSEGMENT", 0.08887711938888, -0.01670467080663, 0, True, 0, Nothing,
0)
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False,
0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line34@Sketch1",
"EXTSKETCHSEGMENT", 0.08887711938888, -0.01670467080663, 0, True, 4, Nothing,
0)

boolstatus = Part.Extension.SelectByID2("Sketch1<2>", "SKETCH", 0, 0, 0,
True, 0, Nothing, 0)
Set myFeature = Part.FeatureManager.FeatureRevolve(1.570796326795, False, 0,
0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False

Part.ClearSelection2 True
Part.ShowNamedView2 "*Trimetric", 8


End Sub
' ##### END MACRO1 #####
 
P

Peter T

If I follow the problem is here
Run-tim error '91':
Object variable or with block variable not set.
Then when I click debug. It is highligthing at:
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0,
False,
0, Nothing, 0)

Effectively earlier you had done
Set Part = Application.SldWorks.ActiveDoc
so presumably ' Part ' fully refers to ActiveDoc

Trouble is I know nothing about "SldWorks" and "ActiveDoc" or even which
application you are running this VBA. As a guess I'd look to see if
"Extension" exists as a child object of Part (ie ActiveDoc)

Dim obj as Object
' code
Set Part = etc
Set obj = Part.Extension
msgbox Not obj Is Nothing

I could be on the wrong track, maybe you need to do something else when user
switches Optionbuttons and just before calling those macros.

Regards,
Peter T
 
M

Maperalia

Peter;
I got help from other source and the y told the following:

Set Part = swApp.ActiveDoc line is returning Nothing, meaning the instance
of SW that your program is hooking to has no open/active document. Change
CreateObject() to GetObject() to hook to an active SW not create a new
instance.

I did ths however, I got the following error message that you may know what
does is means:
Run-time error '-2147221020(800401e4)':
Automation error
Invalid Syntax

After I click "DEBUG" it is highlighting at the following statement:

Set swApp = GetObject("SldWorks.Application")

Could you please tell me what is the syntax error I have?
 
P

Peter T

That error is generic, appears when an attempt to automate an object (eg
application) fails.

It's difficult to comment further because I don't know what you are doing,
or anything about "SldWorks", you haven't shown the relevant code, or even
which application the VBA code is running in.

However, maybe you need to do something like this

On error Resume next
' attempt to find and attach to a running instance
Set swApp = GetObject( , "SldWorks.Application") ' note the comma

If swApp Is Nothing Then
' start a new instance
Set swApp = CreateObject( "SldWorks.Application") ' no comma in this
End If

' Attempt to attach to the active doc
Set Part = swApp.ActiveDoc '
If Part Is Nothing Then
' syntax might be completly wrong
Part = swApp.documents.add
End If

On Error Goto 0

Regards,
Peter T
 
M

Maperalia

Peter;

Thanks very much, I added the coma and it is working perfectly!!!!. Despite,
you do not have knowledge in SW. You were able to help to accomplish this
macro.I really appreciate your helping me with this matter.

For you information, I will describe what I have so you can have an idea
what I am doing.
Basically, it is a circle part that is revolved in SW. The circle part has
two dimensions to control it which are:
1.- The "Angle†to revolve the circle, and
2.- The "Distance†from the center of the circle to the center of the angle .

I setup the "angle" and "distance" to be typed in the excel spreadsheet. The
reason I did this is because I want the people in my team that do not have
knowledge in SW to update the revolve part with the new dimensions without
using SW tools. The only problem is that they have to open excel and SW files
to run it. I have not figured it out how to include in my excel macro to open
the SW part automatically. If you have any idea how to do it I will really
appreciate it.

Well, the data I have in the excel cells are:
1.- In the cell "A1" I have the "Angle" description in the cell "B1" I have
the "Angle" value.
2.- In the cell "A2" I have the "Distance" description in the cell "B2" I
have the "Distance" value.

The excel macro that reads this data and update the revolve part's dimension
in SW is:

' &&& START MACRO &&&&
Sub Circle_Dimensions()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Set swApp = GetObject(, "SldWorks.Application")
Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID("D1@[email protected]",
"DIMENSION", -0.09850135091876, -0.1943853516059, 0.08935038736053, False, 0,
Nothing)
Part.Parameter("D1@Revolve1").SystemValue = Excel.Range("B1") / 57.29577951

boolstatus = Part.Extension.SelectByID("D2@[email protected]",
"DIMENSION", -0.03077633012788, -0.11670139381, 0.09386013938138, False, 0,
Nothing)
Part.Parameter("D2@Sketch1").SystemValue = Excel.Range("B2") * 0.0254
End Sub
'&&& END MACRO &&&&

I hope this information will help you for future matters.

Kind regards.
Maperalia
 
X

XP

I was wondering if you know what all the inputs in the
Part.Extension.SelectByID2() and Part.FeatureManager.FeatureRevolve() mean of
if you are aware of a source that describes them.

Thanks
XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top