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.
1 1575
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. -
Dim strFinal As String
-
Dim strTemp As String
-
Dim strDashString
-
Dim intFirst As Integer
-
Dim intLast As Integer
-
Dim intDashPos As Integer
-
Dim intCount As Integer
-
Dim strSubString As String
-
-
intCount = 0
-
strTemp = Me.yourTextBox
-
-
Do Until Len(strTemp) = 0
-
'Check for commas in the string
-
If InStr(strTemp, ",") > 0 Then
-
strSubString = Left(strTemp, InStr(strTemp, ","))
-
Else
-
'If there are no commas the string is at it's lowest substring
-
strSubString = strTemp
-
End If
-
-
'Check for dashes in the sub string
-
intDashPos = InStr(strSubString, "-")
-
-
'If there's a dash find the starting and ending number for the range
-
If intDashPos > 0 Then
-
strDashString = Left(strSubString, intDashPos - 1)
-
intFirst = Mid(strDashString, InStrRev(strDashString, ",") + 1)
-
strDashString = Right(strSubString, Len(strSubString) - intDashPos)
-
intLast = Mid(strDashString, 1, InStr(strDashString, ",") - 1)
-
'Loop through the range adding each number to the string
-
For intCount = intFirst To intLast
-
strFinal = strFinal & intCount & ","
-
Next
-
Else
-
'No dash simply add the substring
-
strFinal = strFinal & strSubString
-
End If
-
-
'If there's commas left trim down the string to the next number
-
If InStr(strTemp, ",") > 0 Then
-
strTemp = Right(strTemp, Len(strTemp) - InStr(strTemp, ","))
-
Else
-
strTemp = ""
-
End If
-
Loop
-
-
MsgBox strFinal
-
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
...
|
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,...
|
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,...
|
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...
|
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...
|
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>
|
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...
|
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...
|
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)
...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
| |