I need a data type which can hold multiple different data types

Hello, what data type can hold multiple different data types? For example, what data type would I create if I wanted to hold a string (“John”) and an integer (20) in a single reference variable? And how would I add data to this reference variable? Thanks

1 Like

Since everything in Vb.NET ultimately derives from object, you can declare your variable as object and assign different types of data to it. However, you’d need to cast it back to the original type when retrieving the value. For example, if you want to print your VAR, you need to write VAR.ToString , if you need to retrive an integer for operation you need to parse it like this : CInt(VAR)
Hope this helps.

Thanks but how do you add data to My_Object?

The advice above is quite outdated.
Coded Source Files have been a thing in UiPath for a couple of years now.

If you want a custom data type just go ahead and make yourself a class with the properties of the appropriate data type you want.
There is no need to mess around with casting data types, just make a strongly typed object.

A variable of type system.object can store any kind of data
You can add from the variable panel or use assign activity and add the value you want
Then if you want to retrieve you need to parse it as mentioned previously @lomasd12

so. you mean writing code to define a class using an invoke code activity in studio or using an invoke script activity? Just be mindful, I’m a newbie at .NET

No, Invoke Code is gross and outdated.

Coded Workflows were introduced a while ago to allow you to write workflows purely in C# code instead of XAML, but you aren’t limited to only making ‘workflow’ classes, you can also make ‘Coded Source Files’ which is basically just building a class in C# that will then be a data type you can use anywhere in your project, so you can very easily make a ‘person’ class with a string property for FirstName, string property for LastName and integer property for Age.

You should not use the base data type of ‘object’ and make an anoymous data type now like is being proposed in the other posts, its bad coding practice to use anonymous types when you can quite easily build a strongly typed object.

Can you tell us WHY you want to do this? I notice you said a string John AND an integer 20 in a variable. Everyone is interpreting it as you wanting a variable that can sometimes hold John and sometimes hold 20, but it sounds more like you want to store John and 20 at the same time.

You might want to use a dictionary(of string, object) so that you could assign personDict(“Name”) = “John” and personDict(“Age”) = 20. Then you get them back out with personDict(“Name”).ToString and it gives you John, or personDict(“Age”).ToString and it gives you 20 as a string, or CInt(personDict(“Age”).ToString) gives you 20 as an integer.

If you want to store more than one person at a time, that’s a datatable with columns of Name and Age.

So tell us what it is you’re trying to accomplish.

Paul, why on Earth do it in this outdated way when you can just make a class…?

Stop it. Not everyone is a high level professional programmer. These methods are tried and true and work fine and I use them every day. You’re giving advanced level advice to a novice. If they’re so outdated, why is a queue item’s specificcontent still literally just a string,object dictionary?

Stop gatekeeping people from learning new things that are standard in UiPath. This person is asking to learn and you are trying to hold them back for some reason, if you don’t want to use any new features fine, but stop discouraging others.

Making a class is the most basic thing you can do in programming, making a person class is literally the first lesson in any object oriented beginners class and its even easier than ever cause we have AUTOPILOT.

You dont even need to really know how to make the class, just open a coded source file, ask Autopilot to make you a class with the fields you want and you are done.

After that its no harder that using any other object, like a dictionary or datatable, infact its easier because you dont need to learn how to cast data types.

As for the queue item still being string object, thats largely due to legacy reasons and it being in the cloud, but pay attention, they have already done stuff there to make it into a concrete object when you define the queue schema, just like they do when you deserialize a JSON now, you can get a concrete type instead of a JObject since its easier to work with, its how all the integrations work.

Its everywhere, there is no reason to not learn it and its wrong to discourage people from doing so since its so useful, so please stop this attitude.

I’m not gatekeeping him from learning new things, I’m literally teaching him a new thing - dictionaries - a tried and true type of object. I’m helping a novice who doesn’t understand a basic thing to understand the next level of advancement in his knowledge, taking him from step 1 to step 2 instead of trying to jump to step 9. Let him learn how dictionaries work before you start throwing classes and stuff at him.

Guess what? Not everyone has access to Autopilot either. You operate in the mindset that everyone else knows as much as you and uses the same tools as you. You should spend some time teaching a formal class to gain some perspective.

He didnt ask about Dictionaries, he specifically asked about making an object.
Its awful to teach somebody the wrong thing because you want to keep it ‘legacy’ or ‘simpler’.

If someone comes to you and says they want to learn to use a computer would it make sense you teach them all about MS-DOS in order to ‘keep it simple and start at step 1’.

You are always complaining of not having access to any feature thats out there. Its really a you problem and you shouldnt assume people don’t, its far more constructive to think the best of someone, that they are smart and able to learn these new concepts cause they aren’t hard and assume they have access to new tools and features, they can say they dont if they don’t.

I have done plenty of teaching, I know how to do it well.
You should spent some time getting out of the rut you seem to have put yourself in and try out any of the new features made in the last 4 years, you might also get some perspective that RPA has been moving on from the way you work.

The new UiPath features are good, people should be encouraged to use them, even if you don’t want to.

He didn’t ask about making an object. He asked what datatype can hold multiple different datatypes. That’s pretty much the definition of a dictionary or datatable. He gave an example of holding a string “John” and an integer 20 in a single reference variable. That’s a dictionary, dude. Just stop it. I’m not going to continue arguing with you. We are all very impressed with your advanced knowledge but you need to work on understanding how to get people from his level to your level incrementally.

I use plenty of new features and am not in a rut. I simply have perspective on how to help someone progress in their knowledge without skipping the stuff that helps them understand WHY they’re doing things.

I don’t know how to values/items to the object

Let me show you how easy it is Demetrius.

In your project add a coded source file.

We’ll call it ‘Person’, it will already make an empty object, but its easier to start from scratch with Autopilot.

The image displays a coding interface with a prompt to generate a person object with a full constructor and properties for FirstName, LastName, and Age, using UiPath Studio. (Captioned by AI)

Then you need to use the object in a workflow. This is super easy, look.
You make a variable of the ‘Person’ data type, this matches the name autopilot gave it inside the coded workflow, it was on line

So in a normal workflow we need to assign a value to the ‘test’ variable just made, this is called ‘instantiating the class’, its very easy also and autopilot can help you here too if you aren’t sure.

A UIPath Expression Editor window is prompting to create a new instance of the person class with the name "John Doe" and age 30. (Captioned by AI)

After this you get the great benefit of the intellisense helping validate you don’t make any spelling errors and as you can see, the data types are good! The age is already an integer so no casting.

By contrast, the other proposals for you to try to make an anoymous object or dictionary are fraught with areas where you can go wrong, dictionaries can have confusing data typing, and can be a hassle to create, you also can easily make a spelling mistake, if you type a key wrong anyway you are screwed but you wont know until your code runs, then there is data typing, if you don’t do strong data typing you have to do casting.
Its a headache.

It is something of a standard since we didnt always have the capabilities we do now but its a legacy mindset to think of them first now. If you are learning, learning the new stuff, the latest way of working!

Might be good to ask him what he’s trying to accomplish overall, before suggesting a solution. Notice I was the only one who did that. A dictionary, datatable, class etc might not be the right solution.

Never mind they’re used in activities all over the place and are a good thing to understand. And it might have been good to ask if he’s even on a version of Studio that supports what you’re telling him to do. If he’s not, now he’s just…confused.

Ok Paul, lets all act like 2020 is the baseline. Lets propose he uses Windows-Legacy projects, and classic activities. Cause we should follow your lead and never ever try to use the latest features or assume people have a version from 2023 that supports coded workflows… We should assume nobody ever upgrades right and never provide incentive to upgrade by showing them how good the new features are…

Your strawman is not convincing. The problem is you act like everything YOU are using is the baseline for everyone else. Guess what, it’s not. We shouldn’t assume nobody ever upgrades - what I actually said is we shouldn’t assume everyone HAS upgraded. There are lots of posts on the forums from people on older versions for various reasons. Heck, some of us aren’t even on cloud and it’s entirely out of developers’ control. Go away.