?
Solved

convert coldfusion to vb.net

Posted on 2014-07-22
3
Medium Priority
?
291 Views
Last Modified: 2014-07-22
This code below is exactly what I am trying to do in vb.net.
I need help converting it to understand it....

<!--- always sort first so the ranges make sense --->
<cfset numbers = listToArray("1,2,3,4,6,7,8,9,10,11,12,15,19,21,22")>
<cfset arraySort(numbers, "numeric")>

<cfset startAt = 1>
<cfset maxPosition = arrayLen(numbers)>
<cfset ranges = []>

<cfloop from="1" to="#maxPosition#" index="pos">
        <!--- check difference between current and next number --->
	<cfset offset = pos lt maxPosition ? 1 : 0>
	<cfset gap = numbers[pos+offset] - numbers[pos]>

	<!--- there was a jump in sequence OR this is the last element --->
	<cfif gap gt 1 OR pos eq maxPosition>
		<cfif startAt lt pos>
			<!--- range --->
			<cfset arrayAppend(ranges, numbers[startAt] &"-"& numbers[pos])>
		<cfelse>
			<!--- single value --->
			<cfset arrayAppend(ranges, numbers[pos])>
		</cfif>
		<cfset startAt = pos + 1>
	</cfif>
</cfloop>

List of Ranges: <cfdump var="#arrayToList(ranges, ',')#">

Open in new window

0
Comment
Question by:taviaf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 total points
ID: 40211766
Here you go:
        Dim numbers() As Integer
        Dim numberss() As String
        Dim ranges() As String
        Dim list As String = "1,2,3,4,6,7,8,9,10,11,12,15,19,21,22"
        Dim startAt, maxPosition, pos, offset, gap As Integer
        ReDim ranges(0)
        ranges(0) = ""
        numberss = list.Split(",")
        startAt = 0
        maxPosition = numberss.Length - 1
        ReDim numbers(maxPosition)
        For pos = 0 To maxPosition
            numbers(pos) = CInt(numberss(pos))
        Next
        Array.Sort(numbers)
        For pos = 0 To maxPosition
            If pos < maxPosition Then offset = 1 Else offset = 0
            gap = numbers(pos + offset) - numbers(pos)
            If gap > 1 Or pos = maxPosition Then
                If ranges(0) <> "" Then Array.Resize(ranges, ranges.Length + 1)
                If startAt < pos Then
                    ranges(ranges.Length - 1) = CStr(numbers(startAt)) & "-" & CStr(numbers(pos))
                Else
                    ranges(ranges.Length - 1) = CStr(numbers(pos))
                End If
                startAt = pos + 1
            End If
        Next
        MsgBox(String.Join(",", ranges))

Open in new window

0
 

Author Closing Comment

by:taviaf
ID: 40212109
Would give an A+ if I could..... Thank you a million times
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40212120
Lol thanks, no problem :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question