Results 1 to 10 of 15

Thread: Re: Defining multiple variables in VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,316
    Rep Power
    10
    Hi snb
    Quote Originally Posted by snb View Post
    -----The result of an Inputox ....
    What's the ... Inputox then








    EDIT a long time later...
    Just some Inputox Notes I wanted to dump here, as a quick place to dump them ..

    Rick said here: _..
    http://www.excelfox.com/forum/showth...tion)-InputBox
    _... about the...How To React To The Cancel Button in a VB (not Application) InputBox _.. that_..
    _...I think the below code snippet is self-explanatory (even though the StrPtr function may be new to you)...
    Code:
    Sub TesthIe()
      Dim Answer As String
      '....
      '....
      Answer = InputBox("Tell me something")
      If StrPtr(Answer) = 0 Then
        MsgBox "The user clicked Cancel, so we will exit the subroutine now."
        Exit Sub
      ElseIf Len(Answer) = 0 Then
        MsgBox "The user clicked OK without entering anything in the InputBox!"
      Else
        MsgBox "The user entered the following..." & vbLf & vbLf & Answer
      End If
      '....
      '....
    End Sub
    I don't think it is easy
    _...
    This my take on it:
    String variable:
    "Pointer" to a "Blue Print" (or Form, Questionnaire not yet filled in, a template etc.)"Pigeon Hole" in Memory, sufficient in construction to house a piece of Paper with code text giving the relevant information for the particular Variable Type. VBA is sent to it when it passes it. In a Routine it may be given a particular “Value”, or (“Values” for Objects). There instructions say then how to do that and handle(store) that(those). At Dim the created Paper is like a Blue Print that has some empty spaces not yet filled in. A String is a bit tricky. The Blue Print code line Paper in the Pigeon Hole will allow to note the string Length and an Initial start memory Location. This Location well have to change frequently as strings of different length are assigned. Instructions will tell how to do this.
    So at the address of the variable itself there is only a pointer to a memory area.
    StrPtr
    The StrPtr function “returns the address of start of that actual memory area once used in which the Unicode string is stored”. This address is not identical to the address of the variable that you use this string in Visual Basic: - at the address of the variable itself there is only a pointer to a memory area..
    The actual memory address ( for the start of the string ) may change, but it will not have been set the first time if the variable has not yet been used.
    API ddl stuff
    I expect the Functions like the StrPtr function are “WRapper functions for some API Function”. In English I think that means that that StrPtr function gives the necessary and appropriate arguments for an API Function that can return addresses of variable by running a code hidden somewhere in a File usually with a .dll extension which is usually supplied as standard with windows. The idea being that these files are a sort of directly runtime executable things that many other applications, such as Excel VBA can use in a code run. It is some sort of efficient way to allow the linking to be done to the file and the various functions loaded and used as the code such as the VBA code runs. Hence a name direct link library – The file is some special sort of runnable thing rather than just a collection of function codes. It is somehow directly Integratable into a code, as apposed to an earlier way of doing things known as static linking which had to copy a lot of stuff into a code to be used when the code ran. The word API is just a word used to intimidate. It stands for Application Program Interface. It very loosely means the things available to an Application programmer from these libraries or some similarly available coding stuff. The word Interface is often used in computing to mean the bit someone can interact with which has all the other clever stuff behind it. It is intend to give some unity / consistency / standardisation of the bit people use to do more complicated stuff that might not be directly available or might be require a lot more in depth computer knowledge to get to and use directly. If you like API is the control panel.
    These things are often a bit vague as I doubt anyone knows in the meantime what is actually going on. You may actually be using the “Excel API” when you play around with Data Base things which use stuff that takes Objects, Linking and Embedding them ( OLE ) into a VBA code. ( you use OLEDB library stuff )
    Anyway the end result of all this is that the actual address, ( as a Long number I expect ) is retuned by the API function and that passed to the wrapper function StrPtr
    Very likely the API function or the wrapper function is wired to return 0 if the things somehow does not work, or doesn’t find anything or whatever similar.
    Hence the end result of all this is I will have
    ____________StrPtr(MyVaraibleNotYetUsed)=0





    https://msdn.microsoft.com/de-de/library/bb978983.aspx
    http://www.excelfox.com/forum/showth...0192#post10192
    http://www.excelfox.com/forum/showth...-VBA#post10153
    https://www.excelforum.com/developme...ml#post4630570
    Last edited by DocAElstein; 02-16-2018 at 07:35 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Replies: 2
    Last Post: 02-27-2019, 05:35 PM
  2. VBA To Compare Multiple Cells
    By x010 in forum Excel Help
    Replies: 4
    Last Post: 08-31-2013, 01:53 AM
  3. Populate Ribbon Controls On Load Dynamically Through VBA Variables
    By phxpoolplayer in forum Excel Ribbon and Add-Ins
    Replies: 1
    Last Post: 04-20-2013, 01:51 AM
  4. Replies: 2
    Last Post: 12-19-2012, 08:28 AM
  5. Split Range into Multiple Columns VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 3
    Last Post: 03-07-2012, 10:53 PM

Posting Permissions

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