Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Direct Formula | Excel Discussion (Misc queries) | |||
Calculate Textbox value based on another textbox value.doc | Excel Discussion (Misc queries) | |||
Calculate Textbox value based on another textbox value | Excel Discussion (Misc queries) | |||
Can you direct me. | Excel Discussion (Misc queries) | |||
Direct reference | Excel Worksheet Functions |