Control Shape Data with a Combo Box, *VERY* new to VBA

Started by Michelle, November 20, 2012, 09:19:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Michelle

I have tried & tried to avoid it, but it looks like I need to learn VBA to make the boss happy!  What he'd really love to see is a shape that uses a combo box as user interface (instead of shape data which I was using) to control the shape.

He's like to see the listbox populated with the choices the user can make , then when they select one it needs to make the appropriate change tot he shape data so a report run on the drawing page lists the correct equipment. 

I can find the Combo box, and the scroll bar object to scroll it, but how do I put info into the box?  and how do I make the scroll bar work?  And tie it to Shape Data?  I don't ask much, LOL

Please be kind... when I say new to VBA, I mean as in I have never before today gone into "design mode".  Any help or direction you can give is much appreciated!

I don't know if it will help, but I will attach a shape that I created using Shape Data as the control...
Michelle

wapperdude

Visio 2019 Pro

Jumpy

Should the combobox be part of the shape, or should you create a form that pops up if you select the shape? That would be the same like ShapeData. Have you and your boss looked at the ShapeData-Window or do you only know the dialog?

Michelle

I guess Ideally the combo box would pop up when the shape is placed on the page, then the user can make their selection and dismiss the box so only the shape shows.  Down the road (if I can get down that road) it'd be awesome to have a box on the page where the user can make their choices and the choices would place shapes on the page. I don't need to get there for quite some time (if ever), though. 

We were previously using the shape data window, but boss showed me a screen shot from an excel ordering solution that he worked on, and pointed to the form (combo box) on the page and said "Can you do this?" 

Wapperdude, I had found that article from VisioGuy yesterday in my searches, but even that is above my head.  :(  It looks like a similar idea, but I can't decipher where in the code he's putting the pages in the pull down, or where he's telling it to take you to that page when clicked on. I certainly don't understand enough to try and adapt it to pulling my info in.  (Can I just enter items into the box for the user to choose, or must it be compiled froma source like excel?)  I have a friend who knows that stuff, and plan to ask for help, but I need to start trying to learn this stuff myself.  Are there some good books/websites you can recommend for someone who is truly truly a newbie at this?  Is this stuff taught at colleges or online?

Thanks for your help!
Michelle

Jumpy

If you don't use the ShapeDataWindow, but the ShapeDataDialog you can select/define a ShapeData for your Shape. Here you can select "FixedList" as DataType and add a List in Form of a string seperated by semicolons for example: "Item 1;Item 2;Item 3;...". In the ShapeData Dialog you will now get an ComboBox for that Data field.

Michelle

I may have to go back to that. :(  Problem is that my descriptions are going to be very long.  Enough to run right off the combo box display capabilities.  I need the descriptions to at least appear as if they have colums as well.  Each description will have a part number, space, description, space, cost.  Each "column" needs to line up as if it actually were a column for the list to look decent.  I figured I could accomplish this better in a user form. Can I control the size of the SHape Data dialog?

For now I am going to try using the Shape Data Dialog... not the fix I wanted, but for now I just need to get a solution that works.  Hopefully later I can come out with a really great one.

Question... can I show data in the dialog that the user can see, but not interact with?  Such as if they choose a description a Cost field shows them the price, but they cannot interact with that price field to mess it up? 

Michelle

Michelle

Scratch that!  Just went into the first shape, and the descriptions are just WAY too long, with no way to pare them down enough to make a difference.  :(  I will have to use the shape data window.  :(

I have seriously just got to learn how to pull my excel info into a combo box user form.
:'(

Jumpy

OK the Steps you need to learn about:

1) Create a Userform with the Combobox or a Listbox and maybe an OK and Cancel Button.
2) Set the Font of the Combobox to SansSerif or sth. similar where all characters have the same width.
3) The Form needs a global variable type shape (Public Dim formshp as Visio.Shape).
4) In the OnShow-Event of the form place the code to:
  -Open Excel
  -Read the cells you need and create a String for each row
  -Add the string for each row to the combobox
  -Close Excel
  -Look what the shape (reference placed in formshp variable) has for a ShapeData value and set the combobox to that value
 
5) In Cancel Button Event place just a me.hide
6) In OK Button place code to hide the form and to push the selected value in the combobox to the ShapeData of the formshp.

7) In another VBA-modul you need a code, to call the form:
Public Sub CallForm(shp as Visio.Shape)
  Set Form.formshp 0 shp
  Form.Show
End Sub

8) In the shapes, in for example the EventDblClcik cell place formula to call the VBA procedure:
=Callthis("CallForm")

Michelle

Jumpy,
Thank you for spelling it all out for me!  This looks like what I need, even though I really still don't understand!   ???

I am determined, though.  I have a friend and a brother in law who know VBA, and they both tell me how easy it is, and that with a little bit of traiing I'll be up and running.  So I plan to sit down with both of them and see if they can't get me started learning my new language.  :)

Thanks again, I'll keep you posted as to progress, as I'll surely be back here with lots of questions as I learn.

Michelle

msn81

Hi All,

I've browsed these forums and learned a lot over the last few weeks.  I've come a bit stuc and this topic is exactly what I want to do also... well, almost, so thought I'd respond even though it's a few years old.

I too am very new to VB and have only just started playing with the shapesheet, so would really appreciate if someone could spell out the solution - step by step (ideally click-by-click)!

What I'm trying to do:
Visio 2013, Pro.

I have two Shapes - call them Source and Result, and I assume I would also use a combobox.

In the combobox I'd like to have the user select one of the following six string values:

"Less Than"
"Less Than Or Equal To"
"Equal"
"Greater Than"
"Greater Than Or Equal To"
"Does Not Equal"

Where ideally the above six String Values would be 'Looked-Up' from the Source shapedata.  (Alternatively - how do I just add them to the combobox as fixed values?)

The selection would then be populated in the Result shapedata  <<< mandatory requirement!

If there is a thread with this already - apologies, please point me!  Or Thanks in advance for any advice!
Mark

Yacine

I've hesitated before answering.
The matter is:
1) there are many examples in the forum showing how to get data from one shape to another. Either a direct reference to the source, or the source writing by SETF/GetRef to the target.
2) Unless the shapes are sub-shapes of a "super" shape it is not recommended to build up separate shapes linked together. One of them may get deleted and the "smartness" is lost.

You may want to describe a little more what your final intend is.
Yacine

msn81

Thanks Yacine for responding.

I guess a picture paints 1,000 words  (see attached)



What I am trying to achieve - I'm creating a "Drag and Drop" for business users to create their own IVR (call centre menus/options etc), the business want something pretty they can fill in  ;D

The business user will input string in some files, others I need them to select the options from a fixed list (which I can update periodically - hence the 'source').  The Combo Box will 'belong' to a 'supershape'.  Once the business have finished going nuts filling in the required fields, I'd export the shape data to Excel, to manipulate and upload into the IVR system.

That's the context.... hope this makes sense.

Thanks
Mark

Yacine

Sorry for being so stubborn, but I did not yet understand why Visio and how it is intended to be used.

Anyway here are some thoughts.
1) don't use OCX controls on the drawing. Yes they work, but they tend to lose there connection to the code when copied and pasted. I do recommend to use VBA forms - or if you happen to have a visual studio licence, write an addin.
Altenatively use a visio shape dropdown. There are several topics in the forum handling this issue.
2) if you build up a page as input form, then use the custom properties of the page. That means, your source shape (Rectangle.27) is not really needed. Put the relevant data in an according custom field, as semi-colon separated field. Eg: prop.sourceValues = "Less Than;Less Than Or Equal To;Equal;Greater Than;Greater Than Or Equal To;Does Not Equal"
The target shape could then have a field prop.myValue, set as fixed list and its format cell would have the formula: thepage!prop.sourceValues

There's an old example where I tried to do something similar: http://visguy.com/vgforum/index.php?topic=1775.0

Let me know if these abstruse explanations could get you started.
Yacine

msn81

Thanks Yacine

You're not being stubborn, understanding the problem yields better solutions - I should have explained this a bit better.  there's a bit more context of my problem at the bottom if you're so interested :)

I've used a combination of using the page data as you suggested, plus using info I've extracted from:  http://visguy.com/vgforum/index.php?topic=1272.msg5436#msg5436  (the download helped here.  This has definitely helped, I've achieve something close to where I wanted to get to.  I realised that I don't need the Source shape as you mention: 

What I've landed with is (and may help other beginners like me) :

In my shape (e.g. Rectangle.4) - Right Click, Define Shape Data
In the Dialogue Box:
> Label = [RESULT]
> Name = [SourceData]
> Type = [FixedList]
> Format = [Less Than;Less Than Or Equal To;Equal;Greater Than;Greater Than Or Equal To;Does Not Equal]
> Prompt ["Chose your expression"]  <<< If required

Then I went on the shapesheet for Rectangle.4, Right Click and select Insert Section...
> Tick Actions

In the Actions Section, row 1 I've included:
Action = DOCMD(1312)
Menu = "Chose your expression"  <<< Something meaningful
the rest of the fields leave as is.

I've also protected the shape (Rectangle.4) from editing text - Protection Section in the shape sheet -( LockTextEdit = 1)

Then back on the page I've added another shape telling the user to Right click the shape (Rectangle.4) and select "Choose your Expression", where they get a dialogue box to fill in/ drop-down.

-------
I guess I could have got the user to select the value in the shape data window - but like the OP, it's not what the boss' are used to/wanted to see, so - albeit more cumbersome this will probably be a better solution - go figure!

What seems strange to me (and excuse my ignorance if this is possible without VBA), is that Visio does not have the functionality like Excel to insert a combobox, select properties and key in the "input range" (i.e. define the shape data [prop.input  format =  aaaa;bbbb;cccc;dddd) and "cell link" (i.e. define the shape data prop.input Value) and displaying this as a combobox on the page  ???
See Image 3 from Excel

-----------

For Context of my problem:

I've created IVR Maps for the business after inputting the configuration data into Excel, importing that data to Visio and using data-graphics to display the configuration in pretty "Call-Flow" diagrams for the business to understand.  See Image 4

The business asked/tasked me to reverse the process, where they can drag & drop the shapes on the page, "Fill In" a few fields (shapes) with info and export the shape data (shape reports) from Visio to the 25 odd sheet Excel Workbook with all configuration data ready to load to the IVR system (Sigh - how little they understand :) ).  I'm trying to create this, but the few fields they refer to are not all string, so I'm trying to recreate the IVR system configuration fields in Visio, reducing the input errors and handling referential integrity etc.  Unfortunately the business found it too challenging to fill in the spreadsheet either, as it wasn't pretty enough.  (My boss takes paper, pencil-case to a meeting... and can be found at the scanner shortly afterwards emailing the notes to himself)!

Thanks again!
Mark

wapperdude

Are you trying to create Visio functionality similar to this by Conceptdraw?  http://www.conceptdraw.com/solution-park/computer-networks-IVR

Seems like there would be a lot of specialized shapes along with code development.  I would suspect this is akin to Visio's Org Chart feature, or even timeline feature.  There is a lot of add-in code to make those features work.

What would be really cool, each time a user response is selected, the resulting paths and options highlight.

Wapperdude
Visio 2019 Pro