Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Administrators
Posted

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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (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 by VirusSpore
Posted

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 ...

Posted (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 by VirusSpore
  • Administrators
Posted (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 by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...