How do I use a shape's ID from another field to define beginX - vba

Background: Novice user and VBA programmer - be gentle, please.
Scenario:
Using a Visio (2010) straight line connector;
Currently 1-D Endpoints.BeginX is as follows:
=PAR(PNT(Milestone.40!Connections.X1,Milestone.40!Connections.Y1))
What I have:
A data field in the same shape called BeginItem that contains the Visio ID (e.g. 87) of Milestone.40! above.
What I need to know:
If possible, how to change the formula in 1-D Endpoints.BeginX to something like:
=PAR(PNT(BeginItemValue!Connections.X1,BeginItemValue!Connections.Y1))
and if not possible, is there an alternative way of doing this?
Thanks!

Thanks for helping all. A combination of all advice led me to an alternative solution.
Instead of trying to refer to the field in the Shapesheet that does contain the BeginItemValue, I built the entire string (in VBA) by concatenating the parts and then updated the BeginX value with it.
shpObj.Cells("BeginX").Formula = "=PAR(PNT(" & BeginItemValue & "!Connections.X1," & BeginItemValue & "!Connections.Y1))"
That worked well, although I'm sure there are easier ways of doing it.

Related

VBA - Is there a way to get a Constant value from a variable String?

I have created few Constants (VBA identifiers declared with the key word Const) that look like Rg_Euro, Rg_Usd, Rg_Cad, ... to define specific regions into my workbook.
As I have these "extensions" (Euro, Usd, Cad, ...) in the DataBase that I'm working with, I tried to get the values of my constant by creating a string like this : Str = "Rg_" & extension(i)
But I can't seem to find a workaround to call the Constant and get its value from it... I'm googled it but didn't found what I was looking for and I'm starting to think that it might not be possible directly...
I thought of a User Defined Function with a Select Case on the String to return the right value, but it is just going to add another function, so I'm looking for a more direct solution if there is one!
I'm not a pro and my answer it's only what I've done to solve a similar problem, anyway, I hope it helps:
You can add controls (for example Textbox) named as your constants and set the value you need, then you'll be able to catch any value with this:
Me.Controls("RG_" & extension(i)).text

Creating a self test program with save/import functions (images, description inside)

I'm basically trying to create a program that will allow me to use textboxes to input questions and associated answers to test myself. Mostly, I just want to practice some things I've been learning for vb.net while taking an extra step forward.
Here's a mockup:
Any tips on how to do this? What I'm especially not sure about is how to have the textfile save/import work with adding back into comboboxes and making sure the correct questions and answers are associated with one another. I was thinking also that I could have some sort of check when I import a save file that shows me which questions and answers refer to one another
Update on form design:
Some things I'm trying to practice:
Using arrays
Saving/Opening files (text files in this)- in order to import into program
importing into program
Using the progress bar
Having a way to undo entries
Randomizing sort order in the combo box
Maintaining references between variables (like which answer
corresponds with which question) regardless of sort order or using
the undo function
Some posts in stackoverflow I'm thinking of using as reference:
Compare String with Strings in array
Best way to associate two strings of text in VB.NET
Array to combo box?
Update: Trying to be more specific on my question. Basically, I'm trying to use a list to account for all the inputted questions and answers, however I've only used really basic arrays before, like:
val(1) = "test"
val(2) = "this"
val(3) = "string"
Or the kind where you use a For x to z loop. Based on some stackoverflow posts I've gotten to the point where the code works in that (I think?) the list is updated and the combobox for questions and answers reflect what is on the list. However, I can't connect the two so that I can select things in the comboboxes and check if they are correct.
In terms of saving as a text file. I figured it would be simpler. Basically, have it output sort of like
"question goes here" ; "answer goes here"
"next question goes here" ; "answer goes here"
and so on. Then I can use the semicolon as reference in the code when importing. I've never done it before, but it's generally what I do for Microsoft Access or Excel text imports so I figured it was possible.
Code that I have so far (reddit post link): http://redd.it/2716tw

Beginner with OO CLI to generate PDFs and Uno.Any issue in VB.Net

I'm a beginner in writing code that allows us (my company) to generate reports using the OpenOffice DLL allowing the generation of PDFs. I'm using ASP.NET, writing in VB. I need to be able to modify the cell of a table using the xPropertySet member/functions. So I have a variable named Property which is of the the xPropertySet and references the cell that I want. I'm assuming that I need to use the setPropertyValue function but I'm not entirely sure what arguments I should give it. The end result I want is the following:
Description: ________________
I need to figure out how to make the cell that I have above with the underscores just a border on the bottom. Because I'll have some fields that will be pre-populated. As a test I tried doing objCell.Property.setPropertyValue("CharColor", 255), but I get an error saying that Integer cannot be casted to an uno.Any type. Which, unfortunately I know nothing about. Any help would be greatly appreciated. Thank you.
Alright, sorry all I figured it out finally. All I did is created a border variable of type BorderLine like follows
Dim border As New unoidl.com.sun.star.table.BorderLine
Then I set the outerWidth like so:
border.OuterLineWidth = 1
Then I use the setPropertyValue method for the specific cell that I need So something like this:
objCell.Properties.setPropertyValue("BottomBorder", New uno.Any(border.GetType, border))
Of course Properties between ObjCell and Properties is the xPropertySet of the cell. Anyway, hope this helps someone else.

How to fit VERY long condition in conditional formatting

I have a very long condition, about 3,000 characters. Access has only space for about one tenth of that.
Is there some other way to set conditional formatting on a textbox besides through the dialogue, or can I do it in VBA and, if so, HOW?
I have conditional formatting on a bunch of textboxes that trigger when the report is opened.
Would be curious to know if the VBA approach worked?
Another idea: create a hidden field on the form and set it's value based on your 3000-character condition. If you are just trying to have 1 conditional expression, you could give this hidden field a false/true or 0/1 value; if you want mulitple conditions, you could give it a value of 0, 1, 2, or 3 corresponding to the conditions you want applied. In either case, your conditional expression test(s) is(are) now trivial: [HiddenFieldName]=ConditionValue
According to Access' Help topic, the FormatConditions Collection has methods (Add, Delete, Modify) which should allow you to adjust your FormatConditions with VBA code. I've never tried, so offer no opinion as to whether this would be a practical approach for you.
I also tried to find out if there is a capacity limit for the number of characters FormatConditions can accept. I didn't find anything there.
Yes, you can manipulate Format Conditions in VBA. There's a full detailed article knowledgebase article at http://support.microsoft.com/kb/304104.
Code snippet here showing a basic example. Refer to the above link to get the VBA for AddFormats:
Public Function HighLightForeignKeys(argFieldName As String, argFieldValue As Integer)
Dim FormatCondition As String
Dim CodeReception As Integer
FormatCondition = "[" & argFieldName & "] = " & ArgFieldValue
With Me.ID
.FormatConditions.Delete
.FormatConditions.Add acExpression, , FormatCondition
.FormatConditions(0).BackColor = 16510422
AddFormats Me.ID, Me
End With
End Function
I dont know if this is what you were after, since you mentioned there was only a tiny box to enter all of your conditional text. Others have shown you VBA solutions - since you asked if that was one way to achieve it.
I have always resorted to using the "zoom" feature which is accessible via the SHIFT-F2 keystroke. Is that what you were after? I think it goes back several Access versions too.
A good set of Access shortcut keystrokes is here:
http://www.joyedaniels.com/keys_access.htm

Calculate a percentile using EPPlus

I'm trying to use either PERCENTILE.EXC, PERCENTILE.INC or PERCENTILE.
Looking at FormulaParserManager.GetImplementedFunctionNames() these are not implemented functions.
I wondered if I could set the formula and leave it to Excel to calculate. So far I've not got this to work and I get a #NAME? and "The formula contains unrecognized text". Merely clicking in the formula bar causes the formula to be calculated correctly.
Inspecting the internals of the Excel file I am creating (via EPPlus):
_xludf.PERCENTILE.EXC(B14:B113,0.95)
whereas in Excel I get:
_xlfn.PERCENTILE.EXC(A14:A113,0.95)
I think this is user defined function vs function. I've tried prefixing "_xlfn." to my formula string.
This is as far as I've got I think I either need to roll my own percentile calculation in code or manipulate the xml in the Excel file maybe.
Any help appreciated.
Doh! I spend all afternoon stuck, post a question here and then immediately suss the answer...
Anyway in case anyone is interested:
var row95 = percentile95RowLookup[profileKey];
var percentileRange = sheet.Cells[row, i, row+ profileCollection.Profiles.Count-1, i];
sheet.Cells[row95, i].Formula = $"_xlfn.PERCENTILE.INC({percentileRange.Address},0.95)";
With the important proviso that workbook.CalcMode is not Manual.