logo

Live Production Software Forums


Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
VasaA-V  
#1 Posted : Friday, November 17, 2023 6:09:17 AM(UTC)
VasaA-V

Rank: Newbie

Groups: Registered
Joined: 12/21/2022(UTC)
Posts: 8
United States
Location: Minnesota

Thanks: 4 times
We have several scripts assigned to shortcuts that do things like move PTZ cameras, start/stop split screen presentations, etc. The scripts are in VBA and are all similar in structure: First read the API.XML, then query info like which input is at the preview, then do the desired function.

My question is a general one: Both of the below statements work. But which one is better--more efficient, more readable, more robust?

dim preview as integer = (xml.SelectSingleNode("//preview").InnerText)
dim preview as string = (xml.SelectSingleNode("//preview").InnerText)

I think I like the declaration as an integer, since the data (in this case) is a number. But is it always a number? Is it better to always leave data as a string and test that way? What do the experienced script writers here do?

-Mark
kross  
#2 Posted : Friday, November 17, 2023 6:13:45 AM(UTC)
kross

Rank: Advanced Member

Groups: Registered
Joined: 10/31/2020(UTC)
Posts: 149
United States

Thanks: 2 times
Was thanked: 28 time(s) in 28 post(s)
I think it depends entirely on what you are going to do with that variable after you set it, which your sample doesn't show. Are you going to do math on it? Then convert it to an integer. Are you going to be feeding it back into another API call? Then keep it as string, since that's what you'll need.

Also keep in mind that the source XML is always string. Converting to an int can be problematic, if the source for some reason has characters in it that won't convert, which could cause errors in your code.

So I would say keep it as string, only convert to int if you need to do math on it.
thanks 1 user thanked kross for this useful post.
VasaA-V on 11/17/2023(UTC)
VasaA-V  
#3 Posted : Friday, November 17, 2023 7:14:04 AM(UTC)
VasaA-V

Rank: Newbie

Groups: Registered
Joined: 12/21/2022(UTC)
Posts: 8
United States
Location: Minnesota

Thanks: 4 times
Thanks kross,
You said "Then keep it as string, since that's what you'll need."
I did not know if this is the case. Experimentally I have found that either of these commands work.

dim GTinput as string = "6"
API.Function("NextTitlePreset", Input:=GTinput)
or
dim GTinput as integer = 6
API.Function("NextTitlePreset", Input:=GTinput)

But, if the underlying vMix code is converting the integer to string, I might as well use the former. (Although, surely at some point the vMix is converting it to an index type.)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.