![]() |
<font color="lightblue">How do you force a newline in a rich text box ??</font>
|
When I saw this thread the one and only thought to come to my head was has comeone else discovered the wonders of VB beer :D
|
Quote:
lennon cook please explain *p.hanson voice* :D |
Run time or design time. At run time the RTbox traps all standard ASCII keys but tab. So to add a new line at run time, just type the 'enter' key.
You must make sure the custom property "Mulit-line" is true (checked). |
Not sure if this is what you mean or not but..
& vbCrLf or & vbNewLine and their are a couple of others as well. if your rich text box is named txtRTB you would say txtRTB = txtRTB & vbCrLf or if you were using a string variable strString = "A line of text" & vbCrLf & "Another Line of text" txtRTB = strString would look like this: A line of text Another line of text [ 03-10-2003, 12:43 PM: Message edited by: Djinn Raffo ] |
I too thought the question was regarding the emerald coloured beverage of choice for many Australians but then I read Sookmas post and figured it actually stood for Very Boring Question ;)
|
<font color="lightblue">Thanks, Djinni [img]smile.gif[/img]
Downunder - just wait until you see what 'boring' things this does :D One other question... my program doesn`t like Object.SetFocus in one case, but does it properly when I use the same code elsewhere in the code... The only two differences I can find between the one that does work and the one that doesn`t: - The one that doesn`t is in a subprogram that fires on Form_Load - The one that doesn`t work is at the End of that subprogram, ie. last thing before the End Sub. Could either of those have anything to do with it ?? The error it returns is "Invalid Function". </font> |
At form load, the object might not exist yet. Assuming thats the one that isnt working, your not exactly very clear on that point.
|
If you can avoid it, don't use an untyped object or variant. While flexible, you don't know the type until runtime.
Now for your ? .... It seems there is an invalid object reference in your sub. Are you passing the proper object? Does your object have the proper scope? e.i Is it a module global or a local to the _Load event? If it's local to _Load, then it is out of scope in the sub. Also, use a typed object variable. If the object is a textbox, declare it as a textbox ... this will help you at design time. MAKE SURE YOU HAVE THIS STATEMENT IN EACH CODE MODULE AS THE FIRST LINE . </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">OPTION EXPLICIT</pre>[/QUOTE]This forces variables to be specifically declared. Otherwise, if not declared in a particular scope, VB will create a new variable as variant. Goto to Tools '--> Options and make sure the "Require variable declaration" option is checked. This makes VB put the statement in. Always declare variables like this </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">dim var as type</pre>[/QUOTE]If you leave out the type, it is declared as a variant. |
No, all controls have been created by the time the _Load event fires. For more info check the topic "Life Cycle of Visual Basic Forms" in the Help section.
|
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. |
<font color="lightblue">Ok, I think I see a mod() command being used alot... but converting back to decimal could pose a problem...
Maybe I should work on Binary - Octal - Decimal and back first; atleast that won`t have me dealing with letters... </font> |
Actually going from hex to dec is really easy -> treat it as a string and process each char separately in a loop. Handle A-F in a case statement. This by any chance wouldn't be homework? Anyway the prototype would be:
function HexToDec(strHexNum as string) as long |
[img]graemlins/wow.gif[/img] Whoa! All this stuff looks so complicated!
There I was thinking this would a topic about VB's (as in the beer) :D |
*tsk tsk tsk* All this visual basic stuff is just .. hard... it's like another language... err it is.... but honestly... I'm a sever hater of VB myself, and I don't mind voicing my opinoin on being Pro-Java... So its more complicated, yeah well at least I can freaking understand what i'm puttin in [img]tongue.gif[/img] I think my favorite code to go with, though, it HTML... [img]tongue.gif[/img]
oh right back to my opinion: C will live forver! yarr! Even if it goes under the name Java and C#... there... [img]tongue.gif[/img] Now with that visual basic question... Night stalker just gave you the answer so theres no pont in my working on it [img]tongue.gif[/img] aaaand im so tired i'm just gonna go to sleep now... |
Regarding the VB stuff we were talking about last night (OK, it was morning for you, who cares), theres a minor bug in the code I gave you.
This is why I use 2d arrays for crap like this, but I guess were stuck with a 1d now. Anyway, 8 MOD 8 is 0. So "if index mod 8 < 6" will return true when dealing with column 8, which screws up the whole function. Ill leave the corrections up to you. And LEARN C. Its faster, more efficient, more powerful, and looks better on your CV. |
Quote:
I,ve learnt C but I'm having trouble with the V for my CV. Can you help....can you? Please, I was doing so well up till then. ;) |
Quote:
|
Quote:
I`m not quite sure I understand how to process each character separately... hints, maybe ?? [img]smile.gif[/img] And is a Function the same thing as a Sub ?? Is one considered more correct over the other ?? And while i`m in a question mood, what is the difference between telling it to "End" and telling it to "Unload Me" ??</font> [ 03-15-2003, 09:00 AM: Message edited by: LennonCook ] |
1) Think why If index >3 didnt work earlier.
2) Learn C. You can handle a string as an array, and FOR through it. Sub and Function are similar, functions return a value, Subs dont. So you could set a = function(b) but not a = sub(b) I have no idea on the end thing. I guess that end is equivalent to a C++ destructor, which cleans up the object then deletes it so you dont have any dead ends, whereas unload me would be equivalent to the free() function. End sounds safer. But Im guessing here. |
End is a forceful shutdown to the whole program, ungracefully.
Unload object is the class destructor. A function returns a value, a sub does not. Useing x=sub() will cause an error. Yes strings are just null terminated charactor (byte) arrays. I forget if VB will let you index a string directly or not. If not you can use the mid funtcion in the for loop. </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">function HexToDec( HexNum as string) as long dim strDigit as string dim lngTempRslt as long dim i as integer for i = 1 to len(HexNum) strDigit = Mid(i, HexNum, 1) '<:-- check the prototype for mid select case strDigit case "a" lngTempRslt = (10 * 10^(i - 1)) + lngTempRslt . . . case else lngTempRslt = CLong(strDigit) * 10^(i - 1) + lngTempRslt end select next end function</pre>[/QUOTE]There's a really big hint ... good luck. |
All times are GMT -4. The time now is 02:43 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