Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


cstump
2011-01-28T20:07:38Z
How do I convert a string to an integer?

For example, I have a string {USERVAR(Index)} that contains a number. The number was parsed out of a larger string using a SUBSTRING command.

I need to use that number in several places
1) a string.IndexOf operation
2) as a value passed to a BIGINT parameter on a SQL stored procedure

Both cases throw exceptions. In some cases the conversion error crashes vcron.

I am using version 5.6.9

Thanks
Sponsor
Forum information
ErikC
2011-01-31T08:12:54Z
I tested this for you and yes, I also have some troubles with this.

If I create a Int32 variable, using the set variable task, and uses a SUBSTRING function to get a number out of a string, translate to constant checked, I get this error in VC:

Unhandled error in RemoveVariable: There is an error in XML document (1, 2).

System.InvalidCastException: Conversion from string "{STRING(Substring|{TASK(1b77c767" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in a correct format.
   at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
   --- End of inner exception stack trace ---
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
   at UCTaskSetVariable.FillTask()
   at ODNKNCFDHHPJPCMOFFIIHIOEPAPDAKPENFKF.LADALDFPFLGCECIEIGFGOAAGDBJAEJBJHCJK.FillTask()
   at ODNKNCFDHHPJPCMOFFIIHIOEPAPDAKPENFKF.LADALDFPFLGCECIEIGFGOAAGDBJAEJBJHCJK.INMILFFHMDCABENGMNDEIPJAKDHHMBEBPHHA(Object , EventArgs )
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at Infragistics.Win.UltraControlBase.OnClick(EventArgs e)
   at Infragistics.Win.Misc.UltraButtonBase.OnClick(EventArgs e)
   at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


The substring I create contains only numbers.
The client crashes after this and it is aking me to restart the client.

I even tried to add the substring to a value 0 with a MATH function, same problem.

System.InvalidCastException: Conversion from string "{MATH(Add|Integer|0|{TASK(1b77c7" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in a correct format.
   at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
   --- End of inner exception stack trace ---
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
   at UCTaskSetVariable.FillTask()
   at ODNKNCFDHHPJPCMOFFIIHIOEPAPDAKPENFKF.LADALDFPFLGCECIEIGFGOAAGDBJAEJBJHCJK.FillTask()
   at ODNKNCFDHHPJPCMOFFIIHIOEPAPDAKPENFKF.LADALDFPFLGCECIEIGFGOAAGDBJAEJBJHCJK.INMILFFHMDCABENGMNDEIPJAKDHHMBEBPHHA(Object , EventArgs )
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at Infragistics.Win.UltraControlBase.OnClick(EventArgs e)
   at Infragistics.Win.Misc.UltraButtonBase.OnClick(EventArgs e)
   at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


The funny thing is, when I test the MATH.ADD in the variable window, it works fine.
{MATH(Add|Integer|0|{TASK(1b77c767-390e-4d01-aa22-69d5d70cea96,StdOut)}|0)}


After having this error, I can't edit the user defined variable anymore in the variable window. It crashes imediately.

When the variable to add the substring to is a string however, the MATH.ADD went fine, no errors.

Something to look at I think.

Regards
Erik
Uses Visualcron since 2006.
cstump
2011-02-01T01:56:10Z
That is what I am getting too.

Anybody have any suggestions/ideas?

Thanks,

Chuck
ErikC
2011-02-01T09:12:44Z
Hi cstump,

Why don't you use a string variable instead of a number?
This will work if you are not doing any math stuff.

Regards,
Erik
Uses Visualcron since 2006.
Support
2011-02-01T16:45:04Z
Thanks for the report. This issue should now have been fixed for the next version.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
cstump
2011-02-01T17:30:10Z
I tried to use a string variable, but the stored procedure call from VC will not allow it since the SQL parameter on the stored procedure is an Integer. Generates a type mismatch error.


Support
2011-02-01T17:32:30Z
Did the integer variable work?

cstump wrote:

I tried to use a string variable, but the stored procedure call from VC will not allow it since the SQL parameter on the stored procedure is an Integer. Generates a type mismatch error.




Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
cstump
2011-02-01T18:20:46Z
Since the SQL parameter is a bigint, I can not pass it a string. It gives a type mismatch error. Hence my initial question on how to convert string to an int.

Chuck
Support
2011-02-01T18:50:45Z
Is it MSSQL? Using Direct or ODBC or OLEDB?

cstump wrote:

Since the SQL parameter is a bigint, I can not pass it a string. It gives a type mismatch error. Hence my initial question on how to convert string to an int.

Chuck



Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
cstump
2011-02-01T19:07:05Z
MSSQL using a direct connection I think.

From the connection wizard:

Storage Type: database
Database Type: SQL server
Data Pvovider: MSSQL

Support
2011-02-03T22:42:35Z
We just tested this. You can add any string value to the parameters in the SQL Task. As long as you specify BigInt in this case it will be properly converted.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Support
2011-02-03T22:53:33Z
We fixed another error regarding this (using server Variables like User Variables as input). The validation did not like those. Will be fixed for next version.

Thank you for the report.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top