Solved

convert coldfusion to vb.net

Posted on 2014-07-22
3
272 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
Comment Utility
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
Comment Utility
Would give an A+ if I could..... Thank you a million times
0
 
LVL 21

Expert Comment

by:Randy Poole
Comment Utility
Lol thanks, no problem :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

6 Experts available now in Live!

Get 1:1 Help Now