Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2007, 12:35 PM
Registered User
 
Join Date: Jun 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default IsValidData combo list box function

Hi,

I'm jumping into .NET (Visual Studio 2005) from 6.0 and wow. I need help with writing an IsValidData function for a combo list box. On Click, it will verify and/or demand the user select an item in the combo box. They took away my IsNull and there's just enough of a change in code that it's frustrating.

Thanks!

Is it Friday yet?
 
Old June 8th, 2007, 04:54 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

It is Friday.

Could you lay out what you need a little more fully?
 
Old June 11th, 2007, 08:36 AM
Registered User
 
Join Date: Jun 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sure... I'm trying to use this Private Function:

Private Function IsValidData() As Boolean
        IsValidData = True

        If cboRptType.SelectedItem <> True Then
            MessageBox.Show("You must choose a Report Type!", "Input Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            IsValidData = False
        ElseIf cboCountry.SelectedItem <> True Then
            MessageBox.Show("You must choose a Country!", "Input Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            IsValidData = False
        ElseIf cboProduct.SelectedItem <> True Then
            MessageBox.Show("You must choose a Product!", "Input Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            IsValidData = False
        End If
    End Function

I call the function within the "Get Report" control like this:

Private Sub btnGetReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetReport.Click
        If IsValidData() = True Then
            Me.Hide()
            frmSales.Show()
        End If
    End Sub

I tested the IsValidData Function as a simple IF statement with the one test and it worked great. Then I made it an IF ... Then ... Else If statement and I'm getting an "IsValid Cast Exception unhandled" and a box pointing to my first If statement and saying that "<>" is not a Boolean operator. Why would it work once as a stand alone statement, but throw an error when it checks all three combo boxes?

Thanks again!

Is it Friday yet?
 
Old June 11th, 2007, 10:00 PM
Registered User
 
Join Date: Jun 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Figured it out, wasn't as bad as I thought. Thanks anyway.

Is it Friday yet?
 
Old June 20th, 2007, 11:13 AM
Registered User
 
Join Date: Jun 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, this is how I fixed it. I actually put it back into the getreport click sub.

        Dim Type As Integer
        Dim Country As Integer
        Dim Product As Integer
        Dim Report As String

        Dim IsValidData As Boolean = True
        If cboRptType.SelectedItem Is Nothing Then
            MessageBox.Show("You must select a Report Type!", "Input Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            IsValidData = False
            Exit Sub
        ElseIf cboCountry.SelectedItem Is Nothing Then
            MessageBox.Show("You must select a Country!", "Input Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            IsValidData = False
            Exit Sub
        ElseIf cboProduct.SelectedItem Is Nothing Then
            MessageBox.Show("You must select a Product!", "Input Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            IsValidData = False
            Exit Sub
        Else
            'Names and stores selected values in combo boxes.
            Type = cboRptType.SelectedValue
            Country = cboCountry.SelectedValue
            Product = cboProduct.SelectedValue
            Report = Type & Country & Product
        End If
        'Tests Report’s string return value. Rem it once form load is set properly.
        MessageBox.Show(Report)
        If IsValidData Then
            Me.Hide()
        End If

Is it Friday yet?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Msg Box with Combo List Coby Access VBA 4 July 28th, 2007 10:29 AM
Limiting a combo box to default list hamffjs Excel VBA 1 July 17th, 2006 03:19 PM
Combo List Box dragondayz Pro VB.NET 2002/2003 1 May 30th, 2006 06:05 AM
Binding a combo box to update a list view Amethyst1984 General .NET 0 February 28th, 2006 03:04 PM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.