Set Collection in TrackBar - Visual Basic - vb.net

Is it possible to set a series (Collection) of fixed values so that the trackbar output only the values defined in the series? From the properties it seems you can only set min, max and TickFrequency, not the single possible values
Thanks

Natively, the TrackBar control is purely numeric.
If you want to use it for something else, you must set it to have bounds of 0 and one less than the count of items, and then map the selection to the index in the collection yourself, while also using a label or similar to provide feedback to the user on what they chose. There is no automation here; you must do all of the plumbing for this on your own.
What you can do if this will be a common pattern in your application is make a custom control to build this logic once, and use instances of that same custom control in more than one place.

Related

How to modify an output value in LabVIEW?

I am very new to LabVIEW and what I want is to know if it's possible to modify an indicator. I have a loop, and in every iteration I want to add a new value (given by the user via a control) to that string indicator, and to display it? I tried many ways, but since it is an output none of them worked. Is it possible to do that? Thank you.
I have also tried using a feedback node, but I think this somehow gives me an infinite loop.
In LabVIEW, an indicators state will be updated every time that it receives a new value.
By far the easiest way to do this is to simply run a data-flow wire into an indicator terminal.
Beyond that you have local variables, and property nodes which add additional concerns.
In your case it looks more to be an issue with the logic associated with your display update than with your actual updating of the value.
(Additionally, why are you using a string display to indicate a numeric value? Using a numeric suddenly simplifies all of your logic.)
To keep a running total - or similar value - in a loop, use a shift register.
This is just a minimal example in which the loop repeats every second until you click the stop button, but you can adapt it to how you want the control flow to work.

Add custom control to toolbox and have its properties show up in the properties window

To illustrate what I'm asking, let's say I have a custom TextBox that has 2 modes. Mode 1 only allows numbers, and mode 2 only allows dates in a particular format.
Using a class module I can create this custom TextBox, and I can use a loop when the userform initialises to set which TextBoxes are custom.
What I'd like to happen is have the custom TextBox, or what ever custom control I want, show up in the toolbox. And I also want its custom properties, if they exist, to show up in the property window.
So far, I've been unable to find a way to do this. In fact, I've been unable to find out if it's even possible. It seems, to me anyway, that it's something that should be possible, but maybe I'm barking up the wrong tree. If it's possible I'd really appreciate being pointed to a resource.

How to make and use list of labels in VB.NET, WinForms?

How can you make and use a list of labels in VB.NET, WinForms?
I want a 4x4 grid of labels that can be used and interacted with just like an array, e.g. Public somearray(3,3) as Integer. I want to be able to programmatically create, change the text of, and the location of these labels, without having to use repetitive code (if possible).
Also, as a by-question, is there some programmatic way of finding out how much space a label will take up, so as to centre it within a certain area?
Use a TableLayOutPanel for your grid of labels. The labels can be access directly by their name like any other control you add to your form. You can also add all the labels to an Array or List if you like and access by index.

VBA OOP extending existing classes

I'm a rookie at VBA(Excel) but I know some OOP stuff from java. What I want to do is extend the class MSForms.TextBox to add my own constructors and properties. I've tried using the implements keyword but my class won't compile. It would also be helpful to add these fields into some kind of container variable since they're arranged in a 9x9 pattern. Here's what I want my custom textbox to do. (It's for a game)
I need to be initiate it and place it on the form and put initial text into the box based on what is passed to the constructor. I also would like to have it check the values at runtime with an event to make sure they comply with the game rules. If it does not comply I would like to change the background color to red.
I'm able to do all of this when I just make a bunch of form controls the old fashioned way and use a sub controlled by a button to check the text box values.
Any help on extending classes would be much appreciated.
Thanks
I don't think you can do that in VBA. I would keep two arrays, one array of TextBox and one array of a new class representing your extended properties. Then you keep them in sync. e.g. Textbox #71 and extended properties #71.
You can look at the following link for making and working with control arrays.
http://www.siddharthrout.com/index.php/2018/01/15/vba-control-arrays/

referring to different textboxes on each iteration

I'm making a Visual Basic program. I have a page where I want to be able to scale anywhere from 1 set of two textboxes and a label all the way up to 30. I'd really like to keep the display as simple as possible, So I'm trying to make buttons like add batch and remove batch that lets me adjust the boxes shown from 1 to 30.
I know that I can use a case statement or a if statement or even making a function that does one of those for me so I don't clutter up the main code, but that just seems so klunky. Any suggestions on a way that I can refer to one set at one time and another set at one time?
I ended up creating a class that and passed references ByRef to the class. Created methods of Show*( and Hide() that show and hide all objects that were passed to the class (just changing the Visible property)
Created one object of my new class for each batch set. Made an array with those objects in it, now I can call BatchGroups(3).Show() and iterate through my batches.
Still a bit of setup in my FormLoad event, but BatchGroup(txtBat1,txtBatQty1,lblBat1) and filling an array with those objects allows me to iterate through my batches whether I am adding, removing, adding 5 at a time, removing all but one... take your pick.
Could probably build an array with groupboxes as easily to refer to the whole group at once, but groupboxes would have looked somewhat tacky in this situation, I preferred to create my own object oriented groups.