+ Reply to Thread
Results 1 to 7 of 7

Textbox value won't assign to variable

  1. #1
    Registered User
    Join Date
    02-22-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Question Textbox value won't assign to variable

    I was running tests on my software and found that some of the values it was producing weren't correct.

    I decided to step through the code and noticed that the variables I had assigned to textbox values when hovered over said empty, even though when hovering over the textbox assigned to it, the value inputted by the user showed.

    For Example,

    Please Login or Register  to view this content.
    when hovered over said
    Please Login or Register  to view this content.
    even though
    Please Login or Register  to view this content.
    when hovered over.

    So say I have a formula shortly after, that says
    Please Login or Register  to view this content.
    n when hovered over says empty and d is made 0 when it shouldn't be.

    Someone told me if I switch it around to
    Please Login or Register  to view this content.
    it should be recognised but it is still not.


    What could possibly be causing this?

    Copy of my actual coding (I'm trying to price options using the binomial tree pricing method):

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Textbox value won't assign to variable

    Where you hovering over before or after the code to assign the textbox value to the variable was executed?

    Could you attach a sample workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-22-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Textbox value won't assign to variable

    Book3.xlsm

    I hovered over the variables once i'd ran the software to see if my programming was processing properly.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Textbox value won't assign to variable

    When code is finished all the variables are destroyed.

    What are you trying to do here?
    Please Login or Register  to view this content.
    That's putting the values of S, X, r, T, sigma and n into textboxes on the form.

    Some of those variables aren't even declared, and all of them are empty.

    If you are trying to put the values from the textboxes in the variables then it should be the other way round.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-22-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Textbox value won't assign to variable

    I originally had it that way round and I tried to get a friend to help me and he advised me to flip and see if that helps.

    I've tried declaring all the variables originally I had it as

    dim S,X,r,T,sigma,n As Double

    Then i changed it to declaring them individually and then scrapped it because the variables were still empty. What you can see are the remaining ones I didn't delete due to my indecisiveness as to what to do next.

    And you have said exactly my point. All the variables are empty. They are assigned to textbox values, but when values are entered into the textboxes the variables still remain empty.

    What could I do to possibly solve this?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Textbox value won't assign to variable

    This code is assigning the values of the variables to the textboxes, not the other way round.
    Please Login or Register  to view this content.
    I changed the code to have the variable on the left and the textbox on the right, and declare all the variables, like this:
    Please Login or Register  to view this content.
    I then opened the form, entered values in the textboxes, clicked the Calculation Option button and stepped through the code line by line with F8.

    When I reached the above section of code all the variables were assigned values from the various textboxes.

    Those variables were then used in the subsequent calculations.

  7. #7
    Registered User
    Join Date
    02-22-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Textbox value won't assign to variable

    Thank you so much. I've been worrying about this for hours!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1