View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Direct manipulation of TextBox

That is only true if the function is used in a spreadsheet

=myfunction(a1)

Mike is using it to work with a textbox in a userform.

Regards,
Tom Ogilvy


Lynn Schauer wrote in message
...
actually the problem is in the way Excel handles functions versus
subroutines - excel functions (and also subroutines called by functions)

can
only return values and are not allowed to modify worksheets or the Excel
environment.

Just the way Excel works.

Lynn S
"Mike NG" wrote in message
...
This is a simplified version of my code. Basically, I have a function
which takes a source string, does some manipulation, passes back a
target (result) string, and sets the function return to true or false
bases on certain conditions

Function a_test(sSource As String, sTarget As String) As Boolean

sTarget = Left(sSource, 1)
a_test = True

End Function



The workings of the function are not important. What I am doing is
calling this on the exit of one textbox to populate another textbox on a
UserForm


Now doing this will not work

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim x As Boolean
x = a_test(TextBox1, TextBox2)
End Sub


I have to use an intermediate variable instead

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim x As Boolean
Dim y as String
x = a_test(TextBox1, y)
TextBox2 = y
End Sub


I tried the first method with .Value and .Text and these didn't work.
Surely if textboxes are read/write I can manipulate them directly...or
can I?
--
Mike