![]() |
Quote:
|
<font color="lightblue">Ok, i`ve been fiddling round with it a fair bit, and all that seems to be wrong is it being fired at form load.
For the record, the *exact* error is -</font> Quote:
[ 03-13-2003, 12:37 AM: Message edited by: LennonCook ] |
Well if you want a control to have focus as soon as the form loads you could just set the TabIndex of that control to 0.
edit> you can zip and email me the files if you want. [ 03-13-2003, 01:36 AM: Message edited by: Djinn Raffo ] |
OK i did some searching and the problem you are having is that the control is not visible yet.
Put these events in a new form (i copy this from a thread at deja.com) and run it. Check your immediate pane for the debug.prints to see what is happening.. '============ Option Explicit Private Sub Form_Activate() On Error Resume Next Text2.SetFocus If Err.Number = 0 Then Debug.Print "Form_Activate:Success" Else Debug.Print "Form_Activate:Failed" End If Err.Clear End Sub Private Sub Form_GotFocus() On Error Resume Next Text2.SetFocus If Err.Number = 0 Then Debug.Print "Form_GotFocus:Success" Else Debug.Print "Form_GotFocus:Failed" End If Err.Clear End Sub Private Sub Form_Initialize() On Error Resume Next Text2.SetFocus If Err.Number = 0 Then Debug.Print "Form_Initialize:Success" Else Debug.Print "Form_Initialize:Failed" End If Err.Clear End Sub Private Sub Form_Load() On Error Resume Next Text2.SetFocus If Err.Number = 0 Then Debug.Print "Form_Load:Success" Else Debug.Print "Form_Load:Failed" End If Err.Clear End Sub ''''''''''' [ 03-13-2003, 01:50 AM: Message edited by: Djinn Raffo ] |
<font color="lightblue">*slaps forehead* All I needed was to make it ignore that error, because realy it should have done it. There`s a reason, after all, that they included as part of the language "On Error Resume Next"... </font>
|
Oh, duh! You are trying to set focus to the control from _Load. Again check out the help files. VBs help is pretty good usually. But, anyway, to sum up. Your form at the _Load event is loaded, but not visible. This means that the form object has been created, and all child objects have been created, but they are not displayed. You can access any object's properties or methods, but you can only set focus to visible objects. The place to set focus when first loading a form is the _Activate event (another place is the _GotFocus event). This is the event that fires when the form is made visible, but before it has focus. Be warned though that code here gets called EVERY time the form is made visible (switching to another application and back to this one causes this for example). If all you want to do is have a default control have focus on form load, give it a .tabindex=0. you can do this from the properties page, or in code (even in _Load).
Hope this makes some sense to you. If you want me to look at your code, pm me. |
<font color="lightblue">Two more questions...
1) Is it possible to automatically select the text in the textbox after you press something ?? 2) I`ve been challenged and need a bit of help... anyone have ideas on how to write a program that converts between decimal and hex ?? </font> |
1. Yes, there is a selected property of the textbox. Check help for implementation, cuz I don't have access at the moment.
2. Is this for a mental exersize? I think there may be some built in functions to help with this .... If not, remember: A decimal number is cn x 10^n + ...... + c2 x 10^2 + c1 x 10^1 + c0 (technically x 10^0 which is just 1) where c has a range of 0-9. A hex number is yn x 16^n + ...... + y1 x 16^1 + y0 where y has a range of 0-F Try a recurisve function that takes a long parm and returns a string. Do you see an algorithm appearing yet? [ 03-13-2003, 03:42 AM: Message edited by: Night Stalker ] |
<font color="lightblue">Ok, what`s a recursive function ?:|?</font>
|
A function that calls itself.
ex. </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">function Factorial(by val x as integer) as long If x != 0 Then Factorial = x * Factorial(x-1) Else Factorial = 1 End If end function</pre>[/QUOTE]this function will call itself until x=0 then start returning values. If x=4, you would have Factorial=4 * Factorial(3) so Factorial(3) needs to be resolved before Factorial(4) ... and so on till x =0 The final result returned is 24. Not all recursive functions are structured like this, but all need a way to break the recursion, else an infinate call happens. |
All times are GMT -4. The time now is 02:46 PM. |
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved