CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: syntax

  1. #1
    Join Date
    Sep 2001
    Location
    South Dakota
    Posts
    20

    syntax

    Can anyone tell me whay this does not work, and how to make it work. I have SiteNumbers that are 5 digits long and those that are 7. So, those below 00090, I need to pull in those 5 digits. Numbers over 00090, I need to pull in 7 digits. Here's the code I tried, and it will not work. If I just use the 00090, it takes off the 0s, and leaves me with a < 90.
    Thanks
    Pat

    If Mid$(Trim(cmbSite.Text), 6) < 90 Then
    strOnlySiteNumber = Mid$(Trim(cmbSite.Text), 3)
    Else
    strOnlySiteNumber = Left$(Trim(cmbSite.Text), 7)
    End If


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: syntax

    do not follow all but saw this
    Mid$(Trim(cmbSite.Text), 6)
    now,
    mid$(string,start,len)
    that is:
    Mid$(Trim(cmbSite.Text), 6,2) takes 2 bytes starting from 6° char (char 6 and 7)

    Mid$(Trim(cmbSite.Text), 1,6) takes 6 bytes starting from first (chars 1 to 6)

    You've to be sure the string is long enough so:
    if len(trim(text1.text)> 7 then 'you can get chars with mid till 8 position
    ie: mid$(trim(text1.text),5,4) 'which takes from char 5 to char 8
    ...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Sep 2001
    Location
    South Dakota
    Posts
    20

    Re: syntax

    I probably didn't make this to clear. My application wouldn't accept both 5 and 7 digit SiteNumbers. So what we did was add 00 to the beginning of the 5 digit sites so now the length of all sites is 7 digits. But...when I download the data, I need a way for my app to distinguish between the 5 and 7 digit numbers. If I use the Mid$(trim(cmbSite.text), 3), it works fine for the 5 digit SiteNumbers, but it doesn't read the 7 digit ones, because I need all of the digits.
    Thanks


  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: syntax


    'was this?
    if isnumeric(text1.text) then
    if cdbl(text1.text)> 90 then
    'put it in 7 digits
    else
    'put it in 5 digits
    end if
    end if




    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: syntax

    Could you use a ComboBox instead of a textbox and allow them to choose the number rather than enter it?


  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: syntax

    >so now the length of all sites is 7 digits. But...
    >when I download the data, I need a way for my app to distinguish
    >between the 5 and 7 digit numbers

    So, what can distinguish after you added "00"? Last two digits over or under 90?
    then:
    if len(trim(text1.text)> 1 then
    if cint(right(text1.text,2))<90 then
    '... short, so take it with mid$(text,3)
    else
    '... long so take last 7 (right(text, 7)

    end if
    else
    'too short
    end if
    but question is
    0000100 'this was a short one
    and
    0000093 'this was a long one
    is the above true?


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured