Solved

Is it possible to run subs within Select Case statements?

Posted on 2006-10-20
11
196 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]
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:theGhost_k8
ID: 17772592
obviously, u can use subs
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 142

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 50 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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