Solved

convert coldfusion to vb.net

Posted on 2014-07-22
3
277 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
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now