Solved

convert coldfusion to vb.net

Posted on 2014-07-22
3
281 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SqlServer no dupes 25 38
Write to a printer using vb.net 9 43
vb.net winforms sizing/resolution? 4 46
VB.NET 2008 - SQL Timeout 9 34
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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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