working with TextBoxen

'1. counting values
'2. 

make

all textboxen

on

a form empty '3.

make

use of the property index '4. passing a textfield as a parameter to a sub '5. disable changes to a enabled textbox '6.

set

textselected by focus '7. Linefeed to textbox '8. Use Format to

set

date

input

'9. jump from one textbox to an other '10. Convert TextBox.Text to a value '11. expanding the size of a textbox with the related form '12. limit

input

of textbox '13. PasswordChar ------------------------------------------------------------------ '1. counting values 'make a new form with 2 textboxen, 1 label and 1 commandbutton 'put the next line benath the Command1_Click event Lable1.Caption = Cstr(Val(Text1.Text) + Val(Text2.Text)) '2.

make

all textboxen

on

a form empty 'make a new form; put some textboxen

on

it with some text in it 'make a commandbutton 'put the next code under the Command_Click event Dim Control For Each Control In Form1.Controls If TypeOf Control Is TextBox Then Control.Text = "" Next Control '3.

make

use of the property index 'make a new form; put a textbox

on

it 'set the

focus

to the textbox and type CTRL-C (copy) 'type CTRL-V (paste); say you want to

make

an indexed control.. 'put some textboxen

on

your form with CTRL-V 'notice that the property of the textbox control Index has a number 'each textbox has a different number! '4. passing a textfield as a parameter to a sub 'make a new form, 'put a 3 command buttons

on

it; index them 0 to 2, 'put 3 textboxen

on

the form; index them also 0 to 2 'put the next code

on

the appropiate places 'and press F5 Private

sub

ChangeColor(X As Control) X.Enabled = True X.BackColor = &HC0& X.SetFocus End Sub Private

sub

Command1_Click(Index As Integer) Call ChangeColor(Text1(Index)) End Sub Private

sub

Form_Load() Dim t% For t% = 0 To 2 Text1(t%).Text = "" Text1(t%).BackColor = &HFFFFFF Text1(t%).Enabled = False Next t% End Sub '5. disable changes to a enabled textbox >Hi all. I want to prevent users from being able to change the contents of >a text box. Hold on, using the .enabled=false way will not work for me. >I need the control to be enabled. Also, using a label will not work for >me. I need a control that VB can see the handle of. make a global varibale vTextDummy$ on the Text1_Getfocus do vTextDummy$ = Text1.Text on the Text1_Lostfocus do Text1.Text = vTextDummy$ or 'on a module form Global Const WM_USER = &H400 Global Const EM_SETREADONLY = (WM_USER + 31) Declare Function SendMessage Lib "User" (ByVal hWnd As

integer

ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long 'to disable the textbox do SendMessage(Text1.hWnd, EM_SETREADONLY, 1, 0) '6.

set

textselected by focus Public

sub

SetSelected() Screen.ActiveControl.SelStart = 0 Screen.ActiveControl.SelLength = Len(Screen.ActiveControl.Text) 'put in every text1.gotfocus => SetSelected End Sub '7. Linefeed to textbox 'do in vb3 Text1.Text = vText & chr(13) & chr(10) & xText 'do in vb4 Text1.Text =vText & vbCRLF & xText and don't forget to

set

the property MultiLine to TRUE!! '8. Use Format to

set

date

input

Text1.Text = Format(Text1.Text,"mm/dd/yy") or you

do

some coding (on the fly): Sub Text1_Lostfocus Select Case Len(Text1.Text) Case 6 Text1.Text = Left$(Text1.Text,2) & "/" & _ Mid$(Text1.Text,3,2) & "/" & _ Right$(Text1.Text,2) Case 5 'this is difficult because it could be februari the 11th but also december the first Case 4 Text1.Text = Left$(Text1.Text,1) & "/" & _ Mid$(Text1.Text,2,1) & "/" & _ Right$(Text1.Text,2) End Select End Sub Input can be like 020497 (02/04/97) or 2397 (2/3/97) 11297 (1/12/97 or 11/2/97) You see it's not simple. The best way to use dates is to learn your users to put in dates like it just to be. You can

do

this by showing a dummy-date in the textbox and afterwards checking if the date is correct: Const dummyDate As Date = "1/1/97" Sub Text1_Lostfocus on error goto errDate Text1.Text = CDate(Text1.Text) Exit Sub errDate: MsgBox "no valid date" Text1.Text = dummyDate Resume End Sub '9. jump from one textbox to an other cz3040@ark.ship.edu (C Zello) wrote: >Let's say I

have

the following text boxes

on

a form > > A > B > C > D > E > F > >How

do

I "jump" (cause the cursor to go) from A to E? > set the property TabIndex of textbox A to 0 (zero); B to 1; C to 2; D to 3; E to 4 and F to 5. When you load your form the

focus

will be at the first textbox (because this is TabIndex 0). Pushing de TAB will cycle you throught the other textboxes in the given order. n.b. you can always give the

focus

to another textbox by using the command SetFocus (E.Setfocus) '10. Convert TextBox.Text to a value "Darren Mar-Elia" wrote: >- Is there any reason to

have

the return value of an

input

box be a string, >even if the value is an

integer

and will be used as such? (The book I'm >learning from has done this several times and doesn't explain why.Its the Yes,

make

use of the convert methodes in VB: Dim vValue% vValue% = CInt(Text1.Text) see the help

on

Conversion Functions Asc Function CBool Function CByte Function CCur Function CDate Function CDbl Function Chr Function CInt Function CLng Function CSng Function CStr Function CVar Function CVErr Function Format Function Hex Function Oct Function Str Function Val Function '11. expanding the size of a textbox with the related form On Fri, 02 May 1997 22:33:17 +0200, Eric Persson wrote: >Hi ! > >When I expand or rezising my form i want for instance the text box i >putted in there to expand just as mush so it dont get stucked up in the >corner. >Someone knows how to

do

this??? In the form_resize event you

have

to put the code whixh will expand (or shrink) your textbox. (I'ts a lot of work espacialy with a lot of controls

on

you form. There are 3th party vbx/ocx which can

do

the job for you..) Sub Form1_Resize() 'you cannot

do

this when you minimize the form! If Form1.WindowState=1 then Exit Sub 'Move left, top, width, height Text1.Move 50,50,form1.width -50,form1.height-250 End Sub Perhaps you

have

to change the values for your needs.. But this is the way to go '12. limit

input

of textbox On Fri, 09 May 1997 03:02:24 GMT, rmasters@inlink.com (Rick) wrote: >Does anyone

have

a

sub

that allows only digits, backspaces and one >decimal point to be entered into a text box. Private

sub

Text1_KeyPress(KeyAscii As Integer) Const Numbers$ = "0123456789." If KeyAscii <> 8 Then If InStr(Numbers, Chr(KeyAscii)) = 0 Then MsgBox "error" KeyAscii = 0 Exit Sub

end

If

end

If End Sub '13. PasswordChar On 5 May 1997 04:46:21 GMT, cz3040@ark.ship.edu (C Zello) wrote: >How

do

I get passowrd text to show **** when letters are typed? > set the property PasswordChar of the Textbox to *
Return