Results 1 to 4 of 4
  1. #1
    sgerber
    Guest

    Proud of myself -- and grateful to you guys

    I hope this won't be considered a waste of bandwidth.

    I just wanted to say that the reason I haven't been participating more in the past week or so is that I've been making terrific progress on my VBA project -- even, wonder of wonders, figuring out a few things on my own here and there. And I owe it in very large measure to the help of the forum regulars, without whose assistance I'd still be staggering blindly about in the dark forest of VBA bewilderment.

    Thanks, folks -- I'm hugely grateful.

    (Aside to Chris Reaves: In case you're wondering -- no, I haven't forgotten about the duck button and the book. I just haven't had a chance to get to the P.O. yet.)

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proud of myself -- and grateful to you guys

    >figuring out a few things on my own here and there

    So .... TELL US!

    Remember. A short post on a novel (to you) idea sits on the Lounge hadr disk forever (right!) and thus becomes a valuable resource for the future. The REALLY big benefit of the forum is its serachable database of text. That's what alerts us to expertise within a human brain.



    >Chris Reaves

    (sigh!) It's REEVES!!!!!

  3. #3
    sgerber
    Guest

    Re: Proud of myself -- and grateful to you guys

    >> It's REEVES!!!!! <<

    Er, sorry about that. I was going by the spelling in your forum ID.

    >> Remember. A short post on a novel (to you) idea sits on the Lounge hard disk forever (right!) and thus becomes a valuable resource for the future. The REALLY big benefit of the forum is its serachable database of text. That's what alerts us to expertise within a human brain. <<

    FWIW, here goes:

    I was faced with a situation where the contents of a textbox in a userform could be either all numerical or alphanumerical. I had to figure out a way to increment those contents in either case.

    At first, I used your own strGPPP functions to accomplish that within a subroutine -- separating out the alphabetical characters from the numerical, incrementing the numerical, then putting the two strings back together again.

    That worked, of course, but I hadn't taken it far enough. The value has to change every time a user selects a different choice from a dropdown list, and calling a subroutine every time meant passing a dizzyingly long list of parameters back and forth.

    Then I remembered what you'd said about your preference for using functions, because they can return a value. I came up with this...

    ---------------------------------------------------

    Public Function GetNewIshNumber(INIFile As String, LastSeries As String) As String

    Dim LastIshNum As String, DigitsOnly As Boolean, intNewIshNum As Integer, NewIshNum As String
    Dim NonDigits As String, JustDigits As String

    GetNewIssueNumber:
    LastIshNum = System.PrivateProfileString(FileName:=INIFile, Section:=LastSeries, Key:="Issue")
    DigitsOnly = boolDigitsOnly(LastIshNum)
    If DigitsOnly = True Then
    intNewIshNum = Val(System.PrivateProfileString(FileName:=INIFile, _
    Section:=LastSeries, Key:="Issue") + 1)
    GetNewIshNumber = LTrim(Val(str(intNewIshNum)))
    GoTo Bye
    Else: GoTo GetNonDigits
    End If

    GetNonDigits:
    NonDigits = strAlphaOnly(LastIshNum)
    JustDigits = strDigitsOnly(LastIshNum)
    intNewIshNum = Val(JustDigits + 1)
    GetNewIshNumber = NonDigits + LTrim(str(intNewIshNum))

    Bye:
    End Function

    ---------------------------------------------------

    ...which is called initially in a subroutine, and later in a change event in the userform code, with one line:

    strNewIshNum = GetNewIshNumber(INIFile, LastSeries)

    Not exactly revolutionary, and it still needs some refinement (this version only deals with alphabetical characters that come before the numerical value), but the insight into how to use functions that way was something of a revelation for me.

    Now if I could just figure out how to do it with arrays (sigh)...

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proud of myself -- and grateful to you guys

    >the spelling in your forum ID
    Oh THAT! That's GREAVES. I thought you were referring to the OTHER superman ...


    >GoTo GetNonDigits

    Can you figure out a way to get rid of this little piece of code? You're going to meet an AWFUL lot of nice people who avoid using GoTos as much as possible.


    >using functions, because they can return a value.

    Not only that, but functions which decompose two values to one. Which reminds me, there's a posting from James I'm still wanting to reply.


    >NonDigits = strAlphaOnly(LastIshNum)

    As far as I know, this will extract all the ALPHABETIC (but not punctuation characters such as !@#$%^&*()_+=-{}[]":';?><,./ from a string, no matter where they appear in a string. At the end you're going to glue these to the front, or to the back, right? be prepared that this will probably work in THIS application, but down the road you're going to want to use this function in another setting, and it may not work as well.


    If you have mixed numeric and non-numeric and you need to increment just the numeric part, AND you have this mixture in an INI file value, there has to be a reason, right?. OK. So let's accept that it's a good reason. It's going to suggest that there's significance to the mixture.

    Either that mixture has a well-defined format, in which case you can deal with it, or it has NO defined format, in which case you must DEAL with it.

    An example of the former might be a telephone number "416-1234-5678 x123" where we find digit characters, a hyphen, digit characters, a hyphen, digit characters, a hyphen, an extension flag, and an extension number. We always get a string of digits following the "x". We ought to be able to program to find the "x", find the extension digits, increment THOSE and glue everything back together properly.

    An example of the former might be a customer's Purchase Order number, such as "123XY567YT9076" where we have NO control over the layout of characters that come in. If you need to increment a value in THAT string and there is no specified format, what rules do YOU lay down for incrementing what part of that string?

Posting Permissions

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