vMix Forums
»
General
»
General Discussion
»
VBA scripts: integer vs string variables
Rank: Newbie
Groups: Registered
Joined: 12/21/2022(UTC) Posts: 8 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
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 10/31/2020(UTC) Posts: 158 Thanks: 3 times Was thanked: 33 time(s) in 33 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.
|
1 user thanked kross for this useful post.
|
|
|
Rank: Newbie
Groups: Registered
Joined: 12/21/2022(UTC) Posts: 8 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.)
|
|
|
|
vMix Forums
»
General
»
General Discussion
»
VBA scripts: integer vs string variables
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.
Important Information:
The vMix Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close