Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Direct manipulation of TextBox

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Direct manipulation of TextBox

Mike,

You should and you can. But I think you are misunderstanding how to use
functions. The function should return the result of the manipulation, to try
and manipulate an argument and return a result is a bit obtuse. This works
fine

Function a_test(sSource As String) As String
a_test = Left(sSource, 1)
End Function


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Value = a_test(TextBox1)
End Sub


very simple, no intermediates.

--
HTH

-------

Bob Phillips
... looking out across Poole Harbour to the Purbecks


"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



  #3   Report Post  
Posted to microsoft.public.excel.programming
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Direct manipulation of TextBox

On Sat, 12 Jul 2003 at 13:40:34, Bob Phillips (Bob Phillips
) wrote:
Mike,

You should and you can. But I think you are misunderstanding how to use
functions. The function should return the result of the manipulation, to try
and manipulate an argument and return a result is a bit obtuse. This works
fine

Function a_test(sSource As String) As String
a_test = Left(sSource, 1)
End Function


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Value = a_test(TextBox1)
End Sub

Cheers Bob

While this is going to work, what I was trying to achieve by passing
parameters back and a function return code, was so that I could do
something like

If Not a_test(TextBo1, TextBox2) Then Goto ....

I guess I will end up with the same result, a function call and an If
statement, but at least I've avoided having to declare an intermediate
variable
--
Mike
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Direct manipulation of TextBox

Mike,

If you really want to do that, try this
Function a_test(sSource As String, ByRef sTarget As MSForms.TextBox) As
Boolean
sTarget.Value = Left(sSource, 1)
a_test = True
End Function


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If a_test(TextBox1.Value, TextBox2) Then
'do your other stuff
End If
End Sub


--
HTH

-------

Bob Phillips
... looking out across Poole Harbour to the Purbecks


"Mike NG" wrote in message
...
On Sat, 12 Jul 2003 at 13:40:34, Bob Phillips (Bob Phillips
) wrote:
Mike,

You should and you can. But I think you are misunderstanding how to use
functions. The function should return the result of the manipulation, to

try
and manipulate an argument and return a result is a bit obtuse. This

works
fine

Function a_test(sSource As String) As String
a_test = Left(sSource, 1)
End Function


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Value = a_test(TextBox1)
End Sub

Cheers Bob

While this is going to work, what I was trying to achieve by passing
parameters back and a function return code, was so that I could do
something like

If Not a_test(TextBo1, TextBox2) Then Goto ....

I guess I will end up with the same result, a function call and an If
statement, but at least I've avoided having to declare an intermediate
variable
--
Mike



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Direct Formula Rechie Excel Discussion (Misc queries) 7 October 20th 09 10:48 AM
Calculate Textbox value based on another textbox value.doc Tdungate Excel Discussion (Misc queries) 1 February 12th 09 07:11 PM
Calculate Textbox value based on another textbox value Tdungate Excel Discussion (Misc queries) 0 February 12th 09 07:03 PM
Can you direct me. Baha Excel Discussion (Misc queries) 3 June 22nd 07 08:56 AM
Direct reference Archana Excel Worksheet Functions 1 August 31st 06 07:44 AM


All times are GMT +1. The time now is 11:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"