PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
extracting numbers greater than zero-VBForums
Results 1 to 10 of 10

Thread: extracting numbers greater than zero

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    41

    extracting numbers greater than zero

    i have some set of numbers gotten from a card reader. the set of numbers contain zeroes and
    some other digits.e.g "0000023203". and i want to extract all the digits that are greater than zero and send it to a
    textbox. for example, after looping through the set of numbers 0000023203, i will then have
    2323 that i will send to a textbox field.
    please someone should assist as soon as possible.
    thanks

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,698

    Re: extracting numbers greater than zero

    Sounds like you may be storing the numbers in a variable thats defines as String instead of Integer or Long. Switch to Long and it should automatically trinm the preceeding zeros.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Re: extracting numbers greater than zero

    rob, he wants to remove all zeros, including the right one after number 3.

    ken, you should try this
    vb Code:
    1. Dim a As String = "0000023203"
    2.         a = a.Replace("0", "")
    3.         MessageBox.Show(a)
    Check my Blog at VB Corner,Component Crafts

  4. #4
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,698

    Re: extracting numbers greater than zero

    Oh crap, lol, I didnt see that zero difference in the middle.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Re: extracting numbers greater than zero

    O my, I don't look that this is VB Classic category. I saw this thread from RSS.

    Just ignore my thread if you work with VB6. I don't think VB6 have replace method on string variable.

    Ok, try this one. Sorry, my vb6 is a bit rusty...
    vb Code:
    1. dim a as string="0000023203"
    2. dim rstl as string=""
    3. dim i as integer
    4. for i=0 to len(a) -1
    5. if mid(a,i,1)<>"0" then rslt=rslt & a
    6. next
    Check my Blog at VB Corner,Component Crafts

  6. #6
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,698

    Re: extracting numbers greater than zero

    Nope, but it does have the Replace function.

    Code:
    Dim a As String
    a = "0000023203"
    a = Replace(a, "0", vbNullString)
    Edit: cant assign values to variables in the declaration in vb 6
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    41

    Re: extracting numbers greater than zero

    Thank u Michael. your code worked. but i replace
    a = a.Replace("0", "") with a = Replace(a, "0", "").
    cos i am coding on vb6. and as sugested .
    Thanks

  8. #8
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,698

    Re: extracting numbers greater than zero

    Are you using VB 6 or VB.NET?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,355

    Re: extracting numbers greater than zero

    This also works. Build a form with a text box on it.
    Code:
    Dim MyString As String, MyNewString As String
    
    Private Sub Form_Load()
    MyString = "0000023203"
    For I = 1 To Len(MyString)
        If Val(Mid$(MyString, I, 1)) Then MyNewString = MyNewString & Mid$(MyString, I, 1)
    Next
    Text1.Text = MyNewString
    End Sub
    This will also work whenever any non-numeric character is included in the original MyString.
    Doctor Ed

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: extracting numbers greater than zero

    Replace(a, "0", "") allocates string space for the "", Replace(a, "0", vbNullString) doesn't. (Faster and uses less memory.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width