Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18013
Number of posts: 55386

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Numbers with in a String Posted by drkajun on 17 Dec 2004 at 8:55 AM
Hay Guys,
I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.

Any Ideas?


Thanks,
DrKajun

Report
Re: Numbers with in a String Posted by infidel on 17 Dec 2004 at 10:44 AM
: Hay Guys,
: I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
:
: Any Ideas?

You'll have to be more specific. Is it the only thing in the string? What is the range of possible values? What other "noise" characters might be there?


infidel

$ select * from users where clue > 0
no rows returned


Report
Re: Numbers with in a String Posted by Muneeb Shakoor on 21 Dec 2004 at 12:32 AM
: : Hay Guys,
: : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
: :
: : Any Ideas?
:
: You'll have to be more specific. Is it the only thing in the string? What is the range of possible values? What other "noise" characters might be there?
:
:
: infidel
:
:
: $ select * from users where clue > 0
: no rows returned
: 

:
:


You can do this if you have good programming logics because there are some problems which can only be solved by pure programming. The solution immediately comes in my mind is:

dim i as integer
dim str as string
dim formednumber as long
dim tempstr as string

str = txtstring.text

for i = 1 to len(str)
if isNumeric(mid$(str,i,1)) then tempstr = tempstr & mid$(str,i,1)
next

formednumber = clng(tempstr)

Report
Re: Numbers with in a String Posted by Muneeb Shakoor on 21 Dec 2004 at 12:32 AM
: : Hay Guys,
: : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
: :
: : Any Ideas?
:
: You'll have to be more specific. Is it the only thing in the string? What is the range of possible values? What other "noise" characters might be there?
:
:
: infidel
:
:
: $ select * from users where clue > 0
: no rows returned
: 

:
:


You can do this if you have good programming logics because there are some problems which can only be solved by pure programming. The solution immediately comes in my mind is:

dim i as integer
dim str as string
dim formednumber as long
dim tempstr as string

str = txtstring.text

for i = 1 to len(str)
if isNumeric(mid$(str,i,1)) then tempstr = tempstr & mid$(str,i,1)
next

formednumber = clng(tempstr)



Report
Re: Numbers with in a String Posted by Ase_Cooper on 17 Dec 2004 at 9:32 PM
: Hay Guys,
: I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
:
: Any Ideas?
:
:
: Thanks,
: DrKajun
:
:

Well, my best guess, what what you've given me (and assuming some other things) is that you want to use a variable that counts whats happening. For this example, use "c" as your counter variable. Make the changing variable add whatever to it (eg. c = c + 1) and declare it Globally. Now, finding the number within the string is the easy part. Simply do something like this:

 Public somethingrather (1 to c) As String 


c is the always changing variable. As long as its decalred Globally in a module (Project, Add Module Command) you should have no problem. I hope I helped.

Report
Re: Numbers with in a String Posted by pseudocoder on 17 Dec 2004 at 9:41 PM
: Hay Guys,
: I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
:
: Any Ideas?
:
:
: Thanks,
: DrKajun

I'm not that familiar with VB, but couldn't you loop through the string using the mid function, and apply isnumeric along the way?

for i=1 to len(string)
   if isnumeric(mid(string, i, 1)) then
      ' keep track of current pos
      ' loop through while there's a number
   
      cpos = i
      epos = cpos

      while isnumeric(mid(string, epos, 1))
         epos = epos + 1
      wend

      nstr = mid(string, spos, epos - spos)

      ' nstr has a number of n consecutive values if they exist
      exit for
   end if
next


Report
Re: Numbers with in a String Posted by MicroDot on 18 Dec 2004 at 6:33 AM
This message was edited by MicroDot at 2004-12-21 10:5:35

: Hay Guys,
: I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
:
: Any Ideas?
:
:
: Thanks,
: DrKajun
:
:

Hi,
Try something like this:


Private Function ExtNum(ByVal strValue As String) As Integer
    Dim strNum As String
    Dim i As Integer

    On Error Resume Next

    For i = 1 To Len(strValue)
        If IsNumeric(Mid(strValue, i, 1)) Then strNum = strNum & Mid(strValue, i, 1)
    Next i

    ExtNum = CInt(strNum)
End Function






//MicroDot



Report
Re: Numbers with in a String Posted by drkajun on 21 Dec 2004 at 8:50 AM
: : Hay Guys,
: : I need help with something. I need to find a number with in a string. Now this number may be double digits and changes all the time. I want to extract the number from the string.
: :
: : Any Ideas?
: :
: :
: : Thanks,
: : DrKajun
: :
: :
:
: Hi,
: Try something like this:
:
:
: 
: Private Function ExtNum(ByVal strValue As String) As Integer
:     Dim strNum As Integer
:     Dim i As Integer
: 
:     On Error Resume Next
: 
:     For i = 1 To Len(strValue)
:         If IsNumeric(Mid(strValue, i, 1)) Then strNum = strNum & Mid(strValue, i, 1)
:     Next i
: 
:     ExtNum = CInt(strNum)
: End Function
: 
: 

:
:

:
: //MicroDot
:
:

Sorry for being so veag, I know what I want to do but it's hard to explain.

MicroDot, I think you may have give'in me a way to pull off my task. The "IsNumeric" function may allow me to put to geather some logic to find the number with in my string. Learn somthing new everyday.

THANKS GUYS! I'll keep you posted.

DrKajun



 

Recent Jobs