Topics Topics Edit Profile Profile Help/Instructions Help Member List Member List  
Search Last 1|3|7 Days Search Search Tree View Tree View  

VBA rewrite textbox with former value.

:: EPE Chat Zone ­:: ­Radio Bygones Message Board :: » EPE Forum Archives 2010 - » Archive through 21 November, 2013 » VBA rewrite textbox with former value. « Previous Next »

  Thread Last Poster Posts Pages Last Post
  ClosedClosed: New threads not accepted on this page        

Author Message
Top of pagePrevious messageNext messageBottom of page Link to this message

atferrari
Frequent Contributor
Username: atferrari

Post Number: 1447
Registered: 05-2005


Rating: N/A
Votes: 0 (Vote!)

Posted on Tuesday, 05 November, 2013 - 10:53 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

VBA Excel

In a user form, the spin button brings a value up and down between 1 and 32. Value is shown in the textbox.

The user is given the possibility of typing the value directly in the textbox.

The code rejects it, if out of range, but fails to rewrite the old (good) one in the textbox to make evident that the last typed was not accepted.


[CODE

Option Explicit
Const TTR_val_max As Byte = 32
Const TTR_val_min As Byte = 1

.Private Sub TTR_control_enter()
. Dim TTR_val As Byte
. Dim TTR_val_old As Byte

. TTR_val_old = TTR_control.Value '???
. TTR_val = CByte(Val(TextBox_TTR.Text))

. If TTR_val > TTR_val_max Or TTR_val < .TTR_val_min Then
. TextBox_TTR = TTR_val_old '???
. Exit Sub
. Else
. 'Range("GC4").Value = TTR_val - for debugging only
. TextBox_TTR = TTR_val
. TTR_control.Value = TTR_val
. End If
.End Sub

.Private Sub TTR_control_SpinDown()
. TextBox_TTR = TTR_control.Value
.End Sub

.Private Sub TTR_control_SpinUp()
. TextBox_TTR = TTR_control.Value
.End Sub
[/CODE]

I found that the typed value is processed whether I hit Enter or not. More to my confusion.

Any suggestion on how to put this straight?

I am sure I have something mixed up (properties and...?)

Gracias.



Agustín Tomás - Buenos Aires - Argentina
Top of pagePrevious messageNext messageBottom of page Link to this message

poplar10
Frequent Contributor
Username: poplar10

Post Number: 113
Registered: 10-2005

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, 07 November, 2013 - 03:24 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Holas. Correct me if I misunderstand, but what you are doing is to force the user to select a number from 1 to 32, and then use this number in some calculation?

If that is the case then have you considered using a Listbox ? This will show a list of values from 1 to 32 which the user can scroll up and down. When a value is clicked this can then be used elsewhere in your calculations.

Draw a list box, call it Listbox1, on your form with height 110 and width 40

In the Userform Activate event put this code to fill the box with the numbers 1 to 32:

Dim I As Integer
For I = 1 To 32
ListBox1.AddItem I
Next
ListBox1.ColumnWidths = "10pt"


When the user clicks on a value in the list box this will be given as Listbox1.value To check this put this line of code in the Listbox1 Click event:

debug.print Listbox1.Value

Run the code and you should see the selected value appear in the immediate window.
Nothing's impossible, I have found ...
Top of pagePrevious messageNext messageBottom of page Link to this message

atferrari
Frequent Contributor
Username: atferrari

Post Number: 1450
Registered: 05-2005


Rating: N/A
Votes: 0 (Vote!)

Posted on Saturday, 09 November, 2013 - 11:18 am:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Gracias poplar for replying

After testing the software in actual use (by myself) found that extra feature an unnecesary addition. I gave up on that but I know that I am not using the TextBox correctly.

Your Listbox solution works but it is overkill for this.

Gracias again.
Agustín Tomás - Buenos Aires - Argentina

Administration Administration Log Out Log Out   Previous Page Previous Page Next Page Next Page