Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Is it possible to run subs within Select Case statements?

Posted on 2006-10-20
11
Medium Priority
?
203 Views
Last Modified: 2010-04-23
Experts,

I have a select case statement as follows;

        For Each currentNode In currentNodes
            Select Case currentNode.ToString
                Case "Hardware"
                    QueryHardware(SourceFileName)
                Case "Software"
                    QuerySoftware(SourceFileName)
                Case "SoftwareUnchecked"
                    QueryUnchecked(SourceFileName)
            End Select

I am getting QueryHardware(SourceFileName) not declared within the debugger, however I have created a private sub called QueryHardware elsewhere.

Is it not possible to run subs within case statements?
0
Comment
Question by:nickmarshall
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17772573
yes, that should be possible.

>however I have created a private sub called QueryHardware elsewhere.
well, I guess changing from private to protected, friend, protected friend or public, depending on the scope, this will solve the problem
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17772581
I have tried altering the sub to public, which I also thought would solve the problem however it remains the same.
0
 
LVL 21

Expert Comment

by:K V
ID: 17772592
obviously, u can use subs
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17772594
well, where is the 'elsewhere' ?
is the function part of a class? if yes, you have to have an object of that class and use it's method ...
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17772602
>>                Case "Hardware"
                      QueryHardware(SourceFileName)

If this QueryHardware sub is in the same class as your select statement, then make sure its set to private and use
Me.QueryHardware.

If its still not working, will you post the QueryHardware sub?
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17772609
and its location... as AngelIII says...
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17772617
   Private Sub OpenXML(ByVal SourceFileName As String) ' Open XML document and run query based on XML node <Type></Type>

        Dim XmlDoc As New XmlDocument
        XmlDoc.Load(SourceFileName)
        Dim currentNode As XmlNode
        Dim currentNodes As XmlNodeList = XmlDoc.SelectNodes("//Type/Type")
        Dim currentArray As ArrayList = NodesToArrayList(currentNodes)

        For Each currentNode In currentNodes
            Select Case currentNode.ToString
                Case "Hardware"
                    QueryHardware(SourceFileName)
                Case "Software"
                    QuerySoftware(SourceFileName)
                Case "SoftwareUnchecked"
                    QueryUnchecked(SourceFileName)
            End Select
        Next

    End Sub

    Private Sub QuerySofware(ByVal SourceFileName As String) 'Insert XML software to database

        Dim Server As String = "localhost", DataBaseName As String = "DB", User As String = "root", Password As String = "letmein"
        Dim ODBCConnectString As String = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & Server & ";DATABASE=" & DataBaseName & ";UID=" & User & ";PASSWORD=" & Password & ";OPTION=3;"

        Dim currentXML As New XmlDocument
        currentXML.Load(SourceFileName)
        MessageBox.Show(SourceFileName)

        Dim currentNodes As XmlNodeList = currentXML.SelectNodes("//Program/Program")
        Dim currentArray As ArrayList = NodesToArrayList(currentNodes)

        '------------ Loop to add array to database --------------'

        'Open command prompt to execute the query
        Dim ConnectionObject As New System.Data.Odbc.OdbcConnection(ODBCConnectString)

        ConnectionObject.Open()

        'Dim QueryDelete As String = "Delete From Programs"
        'Dim CommandObject2 As New System.Data.Odbc.OdbcCommand(QueryDelete.ToString.Trim, ConnectionObject)
        'CommandObject2.ExecuteNonQuery()

        'Loop to add each array member to database
        For Each program As String In currentArray

            Dim SQLQuery As String = "Insert Into DB (programs) VALUES ('"
            SQLQuery &= program ' concenate the program (val from array) to the sql statement
            SQLQuery &= "')" ' close the sql statement
            Dim CommandObject As New System.Data.Odbc.OdbcCommand(SQLQuery.ToString.Trim, ConnectionObject)
            CommandObject.ExecuteNonQuery()

        Next

        'Close the database
        ConnectionObject.Close()
        ConnectionObject = Nothing

        MessageBox.Show("Database query complete")
        GsStatus = "Waiting for next file"
        Timer1.Start()

    End Sub
0
 
LVL 9

Accepted Solution

by:
DjDezmond earned 200 total points
ID: 17772635
Private Sub QuerySofware(ByVal SourceFileName As String) 'Insert XML software to database

Did you mean to miss-spell QuerySoftware? Could that be the problem?
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17772648
Urrgh!!!!!!!!!!!!!!!!!!!!!!!

Spelling error, working now DUH!!!!!

 :-/
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17772657
lol, happens to the best of us mate ;)
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17772706
Ah, thats good to know! :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

879 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