Solved

convert coldfusion to vb.net

Posted on 2014-07-22
284 Views
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, ',')#">
``````
0
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
• 2

LVL 21

Accepted Solution

Randy Poole earned 500 total points
ID: 40211766
Here you go:
``````        Dim numbers() As Integer
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) = ""
startAt = 0
ReDim numbers(maxPosition)
For pos = 0 To maxPosition
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))
``````
0

Author Closing Comment

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

LVL 21

Expert Comment

ID: 40212120
Lol thanks, no problem :)
0

Featured Post

Question has a verified solution.

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

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll