Solved

Is it possible to run subs within Select Case statements?

Posted on 2006-10-20
11
193 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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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:theGhost_k8
Comment Utility
obviously, u can use subs
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
>>                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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 9

Expert Comment

by:DjDezmond
Comment Utility
and its location... as AngelIII says...
0
 
LVL 1

Author Comment

by:nickmarshall
Comment Utility
   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 50 total points
Comment Utility
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
Comment Utility
Urrgh!!!!!!!!!!!!!!!!!!!!!!!

Spelling error, working now DUH!!!!!

 :-/
0
 
LVL 9

Expert Comment

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

Author Comment

by:nickmarshall
Comment Utility
Ah, thats good to know! :-)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now