?
Solved

Simple Question *WinForms VB.NET TABCONTROL Saving values from 2 textboxes and print

Posted on 2004-11-24
12
Medium Priority
?
355 Views
Last Modified: 2010-04-24
Hi,

I have added a tab control to the windows form application.......... I have  2 Tabs Added lets say tab1 and tab2 and control name is tabcontrol
I added One Textbox in tab1 and another textbox in tab2 .........I have a common SAVE Button at the bottom........
In One shot I want to print the values entered in textbox1 and textbox2 when SAVE Button is clicked .......


For this I declared 2 variables    dim x as string, y as string at the top of the general declarations
I used SelectedIndex change of TabControl
Select case  Tabcontrol_selectedIndexchanged
case  0                             ie tab1 control clicked
if textbox1.text.trim <> "" then
 x = textbox1.text.trim
end if
case 1                               'Tab1 control clicked
if textbox2.text.trim <> "" then
y = textbox2.text.trim
end if
end select

Private Sub BtnSave_Click()
msgbox(x)
msgbox(y)
end sub


I am not able to achieve the desired results properly


 
0
Comment
Question by:sainavya1215
  • 6
  • 3
  • 3
12 Comments
 
LVL 9

Expert Comment

by:caball88
ID: 12670047
both text boxes are accessible when you hit the save button. if the event for the save button click you can get the values from the textboxes. what is the purpose of the tab click even? why set values for x and y?

Private Sub BtnSave_Click()
msgbox(me.textbox1.text)
msgbox(me.textbox2.text)
end sub
0
 
LVL 1

Expert Comment

by:bastawhiz
ID: 12670224
Did you declare X and Y to be local to that Sub/Function, or did you declare them to be Private/Public?
0
 
LVL 9

Expert Comment

by:caball88
ID: 12670378
if you declare x and y as a private in the from containing the tab control you will get the same result. i don't quite understand where you are declaring your variable when you say general declarations at the top. i am assuming this is the top of the form class.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:bastawhiz
ID: 12670447
Try instead of:

Dim x as string
Dim y as string

Try this:

Private x as string
Private y as string
0
 

Author Comment

by:sainavya1215
ID: 12672585
But the problem is :

Lets say in the first tab there exists 3 textboxes and in second tab there are two textboxes

Each Tab has some validation logic .....Like for eg in the first tab if the user Enters data in first textbox and leaves to second tab and enters data in first textbox and if he clicks SAVE it should tell him that Data has not been filled entirely for both tab1 and tab2
Thats the condition. So i thought i should validate it both in SAVE click as well as tab clicks

0
 
LVL 1

Expert Comment

by:bastawhiz
ID: 12675825
Could you post your current code somewhere? Maybe then, I can better diagnose the source of the problem.
0
 

Author Comment

by:sainavya1215
ID: 12676463
ok got you.........If i can get answer to this question I am done

Lets say when the user presses tab1 i have 10 Textboxes.

The validation is :
All the textboxes have to be entered ...User cant enter one text box or two and leave others empty
empty.  
 Or
he can leave all the textboxes empty which isfine.(IS THERE ANY EASY WAY TO CHECK THIS VALIDATION LOOPING THRU THE CONTROLS ON FORM)
All the texboxes are placed inside a groupBox
0
 

Author Comment

by:sainavya1215
ID: 12676529
For clear Understanding this is what I am looking for

I'm looking for a way do validation on 3 text boxes.

If all 3 text boxes are blank, then that is okay.

If one or two of the text boxes is filled in and the others are empty, then this is an error condition.

0
 
LVL 1

Accepted Solution

by:
bastawhiz earned 800 total points
ID: 12683141
Ok, I think I know where you're going.

Code to place on the TabControl's change:


If Textbox1.Text = "" and Textbox2.Text = "" and Textbox3.Text = "" Then

     Exit Sub

Else

     If Textbox1.Text = "" or Textbox2.Text = "" or Textbox3.Text = "" Then

MsgBox "You must complete all fields before continuing!"

     End If

End If


This will validate the three fields, making sure that all of them are filled (or all of them are blank).


0
 
LVL 1

Expert Comment

by:bastawhiz
ID: 12683149
PS - You can replace the MsgBox line with the code that is to be run when validation has failed.
0
 
LVL 1

Expert Comment

by:bastawhiz
ID: 12683155
PS #2 - You can also place that code in your button's click event.
0
 
LVL 9

Assisted Solution

by:caball88
caball88 earned 400 total points
ID: 12696235
yes you can create a sub to validate the textbox on the form. for example:

Public Class YourForm

Private Function Validate_Form() as Boolean

'perform your validation here
if len(textbox1.text) = 0 orelse len(textbox2.text) = 0 orelse len(textbox3.text) then
     return false
else
     return true
end if

End Function

End Class

the textboxes is within the scope of the form and can be accessed in a sub or function within the form. there is no need to assign it to x or y. doing that just uses more memory allocation which is not necessary(not that its that big a performance hit). also i used len to check if empty string because string comparisons are another performance degradation.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question