Solved

Is it possible to run subs within Select Case statements?

Posted on 2006-10-20
11
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:theGhost_k8
ID: 17772592
obviously, u can use subs
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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

Technology Partners: 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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