473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with delimiters

Greetings everyone,

I have set up a text box to accept a string of numbers seperated by commas. The numbers are seperated and each runs through a query. I would like to also be able to seperate the numbers with a dash, and have those numbers treated like a range of numbers. For instance, when I put in 34,37,48-54, I'd like to change that into 34,37,48,49,50,51,52,53,54.
Thanks in advance.
Jul 17 '07 #1
1 1575
JKing
1,206 Expert 1GB
Hi, I think this will properly handle your question. Thought it seems a bit long and there may be a more efficient way to do this.

Expand|Select|Wrap|Line Numbers
  1. Dim strFinal As String
  2. Dim strTemp As String
  3. Dim strDashString
  4. Dim intFirst As Integer
  5. Dim intLast As Integer
  6. Dim intDashPos As Integer
  7. Dim intCount As Integer
  8. Dim strSubString As String
  9.  
  10. intCount = 0
  11. strTemp = Me.yourTextBox
  12.  
  13. Do Until Len(strTemp) = 0
  14.     'Check for commas in the string
  15.     If InStr(strTemp, ",") > 0 Then
  16.         strSubString = Left(strTemp, InStr(strTemp, ","))
  17.     Else
  18.         'If there are no commas the string is at it's lowest substring
  19.         strSubString = strTemp
  20.     End If
  21.  
  22.     'Check for dashes in the sub string
  23.     intDashPos = InStr(strSubString, "-")
  24.  
  25.     'If there's a dash find the starting and ending number for the range
  26.     If intDashPos > 0 Then
  27.         strDashString = Left(strSubString, intDashPos - 1)
  28.         intFirst = Mid(strDashString, InStrRev(strDashString, ",") + 1)
  29.         strDashString = Right(strSubString, Len(strSubString) - intDashPos)
  30.         intLast = Mid(strDashString, 1, InStr(strDashString, ",") - 1)
  31.         'Loop through the range adding each number to the string
  32.         For intCount = intFirst To intLast
  33.             strFinal = strFinal & intCount & ","
  34.         Next
  35.     Else
  36.         'No dash simply add the substring
  37.         strFinal = strFinal & strSubString
  38.     End If
  39.  
  40.     'If there's commas left trim down the string to the next number
  41.     If InStr(strTemp, ",") > 0 Then
  42.         strTemp = Right(strTemp, Len(strTemp) - InStr(strTemp, ","))
  43.     Else
  44.         strTemp = ""
  45.     End If
  46. Loop
  47.  
  48. MsgBox strFinal
  49.  
  50.  
This code loops through the textbox string and seperates it into substrings adding them to a new string. Upon finding a substring with a dash it grabs the numbers on either sides of the dash and runs a for loop between those numbers adding each one to the new string. The code will work whether or not the user ends the string with a comma.

If 35,40,45-50,65 was entered in the textbox strFinal would display 35,40,45,46,47,48,49,50,65.

If you need help applying the numbers to your query using the code I wrote up, I can help with that too.
Jul 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Justin L. Kennedy | last post by:
I am looking for a function that takes in a string and splits it using a list of other strings (delimiters) and can return the delimiters as well as the extra parts of the string. I was trying the...
1
by: nilsonj | last post by:
Trying to set up an admin page for an online training registration page. I am having trouble with a sql statement. Here is the info on the tables. I have two tables: classPerson and reglist ...
8
by: Keith Robinson | last post by:
Hi I wonder if anyone could help me with my grand-daughters home work? We are using a form to add data about personnel who work for our imaginary company. Each record has the employee's ID,...
2
by: Bill Moran | last post by:
I'm having some problems using \copy I have a directory full of test data that I want to be installed automatically when "make database" is issued. While the Makefile rules would seem simple,...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
13
by: ern | last post by:
I'm using strtok( ) to capture lines of input. After I call "splitCommand", I call strtok( ) again to get the next line. Strtok( ) returns NULL (but there is more in the file...). That didn't...
9
by: electrixnow | last post by:
Can anyone tell me who sizeof &tokens only return a int of 4 no matter how many strings that are in the token. thanks, Grant #include <cstring>
1
by: electrixnow | last post by:
I use a code snippet called tokenize that works quite well. But I need to modify it so it returns an empty string if two commas are found together: ie. string test="1,2,,4,5" I would like to...
4
by: nnguyec | last post by:
Hi, I'm trying to write a small code for an assignment which the void String Tokenizer will get a line input, and take out those delimiters from the original string. Then pass each string without the...
5
by: gpaps87 | last post by:
hi, i wanted to know whether we can use strtok command to mark delimiters as tokens as well.In Java,we have a command: StringTokennizer(String str, String delimiters, boolean delimAsToken) ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.