vMix Forums
	 » 
	General
	 » 
	General Discussion
	 » 
	Converting string from API.XML to integer
	 
	
        
            
            
    
        
	Rank: Member
  Groups: Registered
 Joined: 11/6/2020(UTC) Posts: 21  Location: Saint-Petersburg Thanks: 6 times Was thanked: 1 time(s) in 1 post(s)
  
	 
	
     | 
    
        
            
		      
                My goal is to write the volume value from XML and convert it from string to integer but at this line interpreter returns error: "Input string was not in a correct format" Code:dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeComma)
 
 replacing a period with a comma nor convert to a double does not help Code:dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
dim WhatISVolume as string = (x.SelectSingleNode("//input[@title='Music']/@volume").Value)
dim WhatISVolumeComma as string = ""
If WhatISVolume.Contains(".") Then
    WhatISVolumeComma = WhatISVolume.Replace(".", ",")
End If
dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeComma)
for i as integer = 0 to WhatISVolumeInt
             API.Function("SetVolume",Input:="Music",Value:=WhatISVolumeInt)
             WhatISVolumeInt = WhatISVolumeInt-1
sleep(8)
next
 
 and yes, I know about SetVolumeFade function =)  
            
	  
         
     | 
    | 
         
             
     | 
    
         
            
         
     | 
    | 
        
	
     | 
        
        
        
            
        
            
            
    
        
	Rank: Advanced Member
  Groups: Registered
 Joined: 3/20/2014(UTC) Posts: 2,719   Location: Bordeaux, France Thanks: 243 times Was thanked: 796 time(s) in 590 post(s)
  
	 
	
     | 
    
        
            
		      
                In case this might help (not sure what you're trying to do) Quote:The Volume level in vMix is linked to amplitude and scales with the following formula:
  Volume = 0 to 100 (used for UI volume bars) Amplitude = 0 to 1 (used for API Meter and Volume values) Decibels = 0 dB to -infinity
  Volume = (Amplitude ^ 0.25) * 100 Amplitude = (Volume / 100) ^ 4
  Example VolumeBar = 50 Amplitude = 0.0625 MeterF = 0.0625 VolumeXML = 6.25
  Martin vMix
  P.S meter values in XML are in Amplitude 0-1, while volume values in XML are in Amplitude 0-100   
            
	  
         
     | 
    | 
         
             
     | 
    
         
            
         
     | 
    | 
        
	
     | 
        
        
        
    
        
            
            
    
        
	Rank: Advanced Member
  Groups: Registered
 Joined: 2/23/2019(UTC) Posts: 618
  Thanks: 63 times Was thanked: 144 time(s) in 130 post(s)
  
	 
	
     | 
    
        
            
		      
                Originally Posted by: svetotehnik  Code:
dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeInt)
 
  Line 13 of your code contains the variable WhatISVolumeInt twice. Doesn't seem right.  
            
	  
         
     | 
    | 
         
             
     | 
    
         
            
         
     | 
    | 
        
	
     | 
        
        
        
            
        
            
            
    
        
	Rank: Member
  Groups: Registered
 Joined: 11/6/2020(UTC) Posts: 21  Location: Saint-Petersburg Thanks: 6 times Was thanked: 1 time(s) in 1 post(s)
  
	 
	
     | 
    
        
            
		      
                Amplitude is not available from API, MeterF is current level value, not Volume 
            
	  
         
     | 
    | 
         
             
     | 
    
         
            
         
     | 
    | 
        
	
     | 
        
        
        
    
        
            
            
    
        
	Rank: Member
  Groups: Registered
 Joined: 11/6/2020(UTC) Posts: 21  Location: Saint-Petersburg Thanks: 6 times Was thanked: 1 time(s) in 1 post(s)
  
	 
	
     | 
    
        
            
		      
                Originally Posted by: dmwkr  Originally Posted by: svetotehnik  Code:
dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeInt)
 
  Line 13 of your code contains the variable WhatISVolumeInt twice. Doesn't seem right.  typo, corrected this way it does not works too Code:dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeComma)
 
  
            
	  
         
     | 
    | 
         
             
     | 
    
         
            
         
     | 
    | 
        
	
     | 
        
        
        
            
        
            
            
    
        
	Rank: Advanced Member
  Groups: Registered
 Joined: 12/27/2012(UTC) Posts: 5,451  Location: Belgium Thanks: 311 times Was thanked: 1008 time(s) in 830 post(s)
  
	 
	
     | 
    
        
            
		      
                Not sure what you are getting at , seems you want the value before the period to return as a single integer ? Code:Dim IWant = Convert.ToInt32(WhatISVolume.Split("."c)(0)) 
 or Code:Console.WriteLine(Math.Ceiling(Convert.ToDecimal(WhatISVolume )))
Console.WriteLine(Math.Floor(Convert.ToDecimal(WhatISVolume )))
Console.WriteLine(Math.Round(Convert.ToDecimal(WhatISVolume )))
 
  
            
	  
         
     | 
    
        
              1 user thanked doggy for this useful post.  
     | 
    
        
     | 
    | 
        
	
     | 
        
        
        
    
        
            
            
    
        
	Rank: Member
  Groups: Registered
 Joined: 11/6/2020(UTC) Posts: 21  Location: Saint-Petersburg Thanks: 6 times Was thanked: 1 time(s) in 1 post(s)
  
	 
	
     | 
    
        
            
		      
                Originally Posted by: doggy  Not sure what you are getting at , seems you want the value before the period to return as a single integer ? Code:Dim IWant = Convert.ToInt32(WhatISVolume.Split("."c)(0)) 
 or Quote:Console.WriteLine(Math.Ceiling(Convert.ToDecimal(WhatISVolume )))     Console.WriteLine(Math.Floor(Convert.ToDecimal(WhatISVolume )))     Console.WriteLine(Math.Round(Convert.ToDecimal(WhatISVolume )))
    Yes, value before period was solution: Code:dim xml as string = API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
dim WhatISVolume as string = (x.SelectSingleNode("//input[@title='Music']/@volume").Value)
Dim WhatISVolumeComma as string = WhatISVolume
If WhatISVolume.Contains(".") Then
   WhatISVolumeComma = WhatISVolume.Substring(0, WhatISVolume.IndexOf("."))
End If
dim WhatISVolumeInt as integer = Convert.toInt32(WhatISVolumeComma)
for i as integer = 0 to WhatISVolumeInt
             API.Function("SetVolume",Input:="Music",Value:=WhatISVolumeInt)
             WhatISVolumeInt = WhatISVolumeInt-1
sleep(8)
next 
 Thank you!  
            
	  
         
     | 
    | 
         
             
     | 
    
         
            
         
     | 
    | 
        
	
     | 
        
        
        
            
        
            
            
    
        
	Rank: Advanced Member
  Groups: Registered
 Joined: 10/6/2020(UTC) Posts: 98  Was thanked: 21 time(s) in 21 post(s)
  
	 
	
     | 
    
        
            
		      
                Does VBscript have support for locales? I've written code in the past which assumed decimal values would include a period, which of course failed the first time it encountered input from a different locale where commas are used as the decimal separator. Just curious how VBscript deals with that. 
            
	  
         
     | 
    | 
         
             
     | 
    
         
            
         
     | 
    | 
        
	
     | 
        
        
        
    
                           
	vMix Forums
	 » 
	General
	 » 
	General Discussion
	 » 
	Converting string from API.XML to integer
	 
	
    
        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