how to pass data from textbox to a variable

yves_michel

New Member
Joined
Jun 13, 2011
Messages
3
Hello,
I have created a array of 10 and 11 textbox in each text box I am trying to pass the value of the textbox into a segment of my array. But it does not seem to work the values in the array remain 0 even though I entered a decimal value in the textbox, Here a fragment of the program:
Declaration:
Dim parameters(10) As Long

In one of the textbox:
Public Sub TextBox4_Change()
parameters(3) = Val(TextBox4.Text)
End Sub

Many thanks
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Perhaps:-
Code:
Private Sub TextBox1_LostFocus()
Dim parameters(10) As String
parameters(3) = TextBox1.Text
MsgBox parameters(3)
End Sub
 
Upvote 0
To tag on, you mention entering a decimal value in the text box, but you dimensioned your array as a Long, which only holds integers.
 
Upvote 0
Hi Chrism,
Excuse my ignorance, but I thought when I use "parameters(3) = Val(TextBox4.Text)" the val will transform the value in the textbox into a decimal value and place the value into parameters(3) automatically ?
I most admit that I don't really need to have the parameters dimed as long I could use Integer instead.If I do the following:

Dim parameters(10) As integer

Private Sub TextBox4_change()
parameters(3) = Cint(TextBox4.Text)
End Sub

It still doesn't work when I want to retrieve the value of parameters(3) in the frame of the program.Please can you point to me where I go wrong?
Regards,
Yves
 
Upvote 0
What Chris is saying is that Long data types - and Integers - only hold the integer part of a number: no decimals.

CInt specifically removes the decimal part.

If you want to preserve the decimal part, declare the array as Single or Double and use CSng or CDbl.
 
Last edited:
Upvote 0
Thank you, I changed the parameters declaration to integer but I still not being able to retrieve the parameters even though they are entered into the textbox. Anything to do with Private sub that hide the data to be seen anywhere in the program?
 
Upvote 0
Declare parameters as Public in a general code module.
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top