VirusSpore Posted July 23, 2004 Posted July 23, 2004 Hi, this might seem like a dumb question, i was wondering if there a way to convert Char to Int ... my codes are below ... ======================================================== Dim getReportInfo As New TaServiceRpt.localhost7.TaEditGetReportId Dim getUserName As New TaServiceRpt.localhost11.Common Dim intReportId As Integer Dim arrReportId Dim ReportId As Integer Dim arrReportInfo As Array arrReportId = Request.QueryString("RptId") Dim counter As Integer counter = 0 Dim n As Integer n = 0 For Each ReportId in arrReportId ReportId = arrReportId(n) <= * Error occurs here * arrReportInfo = getReportInfo.getSearchReportId(ReportId) For counter = 0 to arrReportInfo.GetUpperBound(0) step 6 n = n + 1 ===================================================== This the main part of the code which i need to perform the casting ...RptId is a String containing a range of values, as generated by the user's search criteria ... In this particular instance, i have opted for the largest possible one. I've tried using CInt, but it doesn't work ... Does anyone hav any suggestions as to how i can overcome this ? Thanks Quote
Administrators PlausiblyDamp Posted July 23, 2004 Administrators Posted July 23, 2004 What data type is arrReportId as you haven't specified one when you declare the variable. If it is an array of strings then you should declare it as such (it's always a good idea to put Option Strict On at the top of you code to catch these things). If you are converting from a string to an integer the easiest way is integer.parse(...) - however I'm not sure that is the problem in this case as with the line arrReportId = Request.QueryString("RptId") you are assigning a single string but later on ReportId = arrReportId(n) you are treating it as an array Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
VirusSpore Posted July 26, 2004 Author Posted July 26, 2004 (edited) What data type is arrReportId as you haven't specified one when you declare the variable. If it is an array of strings then you should declare it as such (it's always a good idea to put Option Strict On at the top of you code to catch these things). If you are converting from a string to an integer the easiest way is integer.parse(...) - however I'm not sure that is the problem in this case as with the line arrReportId = Request.QueryString("RptId") you are assigning a single string but later on ReportId = arrReportId(n) you are treating it as an array ======================================================== Oops, think i left out something ... after arrReporId = Request.QueryString("RptId") ' comes this line arrReportId = split(allReport,",") <== additional line i left out Here's the query codes for RptId : ====================================================== cmdGetReportId = New OleDbCommand(strQuery, conn) conn.Open() dtrReader = cmdGetReportId.ExecuteReader While dtrReader.Read arrSearchReport = arrSearchReport & dtrReader("intReportIdRT") & "," End While conn.Close() dtrReader.Close() arrSearchReport = CStr(arrSearchReport) Return arrSearchReport ================================================== So what i did was bascially assign arrSearchReport as RptId ... If u were wondering what i'm doing, i'm just using another guy's logic; only diff is, instead of a chunk of integers, he passes a chunk of strings( also in Array format ) so the conversion for him is more straight forward ... I was trying to see if this was applicable for int ( i was gonna use CInt to convert the values to int ) but i've been running into errors, or the app can run but no values are displayed ... i'll try the integer.parse() and see if it works. Thanks ! :D Edited July 26, 2004 by VirusSpore Quote
VirusSpore Posted July 28, 2004 Author Posted July 28, 2004 Hey PlausiblyDamp, isn't integer.parse() from Java, or JavaScript? ( I'm using VBScript here, on a version 2002 Development Environment ... ) I was surfing around but i can't find any references for integer.parse() for VBScript ... Quote
Administrators PlausiblyDamp Posted July 28, 2004 Administrators Posted July 28, 2004 Not part of VBScript but part of VB.Net. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
VirusSpore Posted August 3, 2004 Author Posted August 3, 2004 (edited) Not part of VBScript but part of VB.Net. Hi, i tried using Integer.Parse() like u said, and here is the error msg : System.FormatException: Input string was not in a correct format. ( i think its the same as when i use CInt ) Does anybody have any other alternatives ? PS : i was re-reading my posts, and i think i might not have been clear enuff on what i'm trying to do ... I trying to pass a concatenated string of numbers ( seperated by a ',' ) from another page into this page, where the method will receive the String and then break it down and assign it into an array ... (The input string looks something like this : 3,9,12,35,34,23,67,68,456,457,458,56,76,66,67,90 .... each no. is the ID of a report ) Then later on, at the FOR EACH ... NEXT portion, i trying to retrieve individual values to query the database ... Here is where the CInt/ Integer.Parse() comes in ... I'm trying to convert the values( in String ) to Int but it keeps returning the same error ... Edited August 3, 2004 by VirusSpore Quote
Administrators PlausiblyDamp Posted August 3, 2004 Administrators Posted August 3, 2004 (edited) If the string contains a delimited list then you will not be able to simple turn it into a single integer - you will have to split the string down into individual items and parse each in turn. The following will turn a list of numbers into an array of ints Private Function GetNumbers(ByVal s As String) As Integer() Dim nums() As String = s.Split(",") Dim ints(nums.Length - 1) As Integer For i As Integer = 0 To nums.Length - 1 ints(i) = Integer.Parse(nums(i)) Next Return ints End Function Call it like Dim s As String = "3,9,12,35,34,23,67,68,456,457,458,56,76,66,67,90" Dim numbers() As Integer numbers = GetNumbers(s) Edited August 3, 2004 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
VirusSpore Posted August 4, 2004 Author Posted August 4, 2004 hmm, looks kinda straightforward ... I'll try it and see it how it goes. Thanks :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.