Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have created a form with 'x' of textboxes on it, that have mulitple validation rules. So i Thought that i will create a module to do the checking & validation.

 

But how do i link the textbox of the form to the module.

 

PS this is my first time at coding

Posted (edited)

Hi mulliganmark

 

in your Module you build a Function and return a string

see my Code sample

Public Function myTextBox()
       Dim _string As String
       _string = " Here comes a text"
       Return _string
   End Function

'------------------------------------------
This write in your Form1 Class
TextBox1.Text = Module1.myTextBox

 

[edit]changed < > for [ ] [/edit]

Edited by Robby
Posted

I think that explained it wrong.

 

What i want to do is pass the textbox1 (form1) value to the module1.

It will then validated it by saying ie "Please note you have to enter a value"

 

I think another way is. That you have 3 textboxes on form1, these boxes perform a calculation ie box1 + box2 = box3. Therefore in the module it check to see if there is a value in box1 & box2 if not returnd and error message?

 

I hope this is better

  • *Experts*
Posted

You can create a function that returns a Boolean value to do

your validation. Return False if it isn't validated, and True if it's okay.

 

Public Function ValidateBox(txt As TextBox) As Boolean

' in here, check the value of txt.Text and if it is okay, then:
' Return True
'
' Otherwise, you want to:
' Return False

End Function

 

Then, in your form code, just pass the textbox to the sub, check

the Boolean value that is returned, and show a message if it's

false. You can create functions that accept more than one textbox

in the arguments, if you want.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • *Experts*
Posted

Just a suggestion; If you want to have user-friendly error validation,

look in Tutor's Corner (or was it Code Library?) for divil's tutorial

about using the ErrorProvider component. It allows for non-intrusive,

yet effective error notification.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...