Solved

Use values on either side of Split(String, "-") as for - to loop

Posted on 2014-01-19
5
256 Views
Last Modified: 2014-01-19
Hi Experts,

I am working on code to break up a record containing weekintervals and/or weeknumber written as text strings separated thus: "6-8; 10-12; 14-15; 17; 19". I need to break it all up in separate records, in order to get a complete list of weeks like this: 6, 7, 8, 10, 11 12, 14, 15, 17, 19.

I so far succeed in splitting the ";" and "-", but fail to find a way of exploding each of the weekintervals (ex: 6-8) in separate lines.

The code I've written so far loks like this:

            <%
            a=Split("6-8; 10-12; 14-15; 17; 19", ";")
            for each x in a

                        b=Split(x, "-")

                              for each y in b
                              response.write( y & "<br />")
                              next
            next

            %>

This gives the following result:

6
8
10
12
14
15
17
19

What i miss is to make it look like this:
6
7
8
10
11
12
14
15
17
19

Thanks for any suggestions

Best regards
MortenWB
0
Comment
Question by:MortenWB
[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
5 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 300 total points
ID: 39792255
Hi Morten,
if you have a "-" then you have to use the two boundary values like:
 <%
	a=Split("6-8; 10-12; 14-15; 17; 19", ";")
	for each x in a
		b=Split(x, "-")
		if UBound(b) > 0 then
			for y = b(0) To b(1)
				response.write( y & "<br />")
			next
		else
			response.write( b(0) & "<br />")
		end if
	next
%>

Open in new window

HTH
Rainer
0
 
LVL 58

Expert Comment

by:Gary
ID: 39792324
<%
            a=Split("6-8; 10-12; 14-15; 17; 19", ";")
            for each x in a

                        b=Split(x, "-")

                              for i=b(lbound(b)) to b(ubound(b)+1)
                              response.write( i & "<br />")
                              next
            next

            %>

edit
Actually I just realised Rainer's solution is the same (just a bit different).
0
 

Author Comment

by:MortenWB
ID: 39792364
Thank You both - Rainers solution went right in, while Cathals return a "Subscript out of range: '[number: 1]'" - error, wich I'm sure is caused by my lack of understanding.

But I am happy up and running again and settle for sharing the points.

Best regards

Morten B
0
 
LVL 58

Expert Comment

by:Gary
ID: 39792370
You need to remove the +1 bit
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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

623 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