CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2006
    Posts
    172

    Problem with calling a case statement from a case statement

    i am trying to call a case statement from a case statement..it is throwing an error
    if u can tell me where i am getting wrong

    Select Case strOper

    Case "Search for Product"

    .ClearToQuery
    .SetViewMode 3
    .SetSearchSpec "Name", strProduct
    .ExecuteQuery 1
    strInstep = "Step 5:Checking for Product Name existence"
    If .FirstRecord = strProduct Then
    Goto Case "Search for Cost List"---------------it throws error here

  2. #2
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: Problem with calling a case statement from a case statement

    Hi poshyradha
    It is better to send more complete code snippets and within code tags.
    anyway, using goto is discouraged. It causes what is know as spaghetti code, the code that is hard to follow and trace.

    you better refactor your code and move the actions in Case "Search for Product" block to another function or method and call it.
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Problem with calling a case statement from a case statement

    Using Goto is not a good practice. It seems you want to execute another block of statements from the same case. As suggested refactor your code and also, post the complete code block, not just the line that is giving an error.

  4. #4
    Join Date
    Apr 2006
    Location
    Kolkata, India
    Posts
    278

    Re: Problem with calling a case statement from a case statement

    Poshyradha

    Do you have a CASE called "Search for Cost List"?
    Or just "Cost List"?

  5. #5
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: Problem with calling a case statement from a case statement

    [ cleaned ]

    Folks, it is important to post content relevant to the topic under discussion.

    To discuss issues that donot concern the thread, please use "Private Messaging". If you have problems, approach a Moderator.

    Regards,
    Siddhartha
    Last edited by Siddhartha; April 26th, 2007 at 04:54 AM.

  6. #6
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Problem with calling a case statement from a case statement

    Well first of all your using the Goto Incorectly...

    You need to define a Line Lable for the goto to jump too..

    Code:
    Select Case strOper
    	Case "Search for Product"
    ......
    		.ClearToQuery
    		.SetViewMode 3
    		.SetSearchSpec "Name", strProduct
    		.ExecuteQuery 1
    		strInstep = "Step 5:Checking for Product Name existence"
    		If .FirstRecord = strProduct Then
    			'Goto Case "Search for Cost List"---------------it throws error here
    			Goto Next_Step
    .....
    	Case "Search for Cost List"
    Next_Step:
    .......
    You define lables in code by preceeding (err following) them with a ':' ..

    Gremmy...
    Last edited by GremlinSA; April 27th, 2007 at 06:55 AM. Reason: correct code...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  7. #7
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: Problem with calling a case statement from a case statement

    Quote Originally Posted by GremlinSA
    You define lables in code by preceeding them with a ':' ..

    Gremmy...
    You define labels in code with a ':' after the label text.
    Code:
    '...
        Exit Sub
    
    ErrorOccured:
        MsgBox Err.Description
    '...
    Starting with a ':' makes VB believe it's a blank statement.

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Problem with calling a case statement from a case statement

    Starting with a : is the same as the LINE CONTINUATION symbol. It's treated as nothing other than a new statement. It's not ignored.
    Ending with a ":" makes it a line label, and moves it to the far left.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim a
    : a = 2
    MsgBox a
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Problem with calling a case statement from a case statement

    Ooooppss..
    Quote Originally Posted by dglienna
    Ending with a ":" makes it a line label, and moves it to the far left.
    You are so right...

    I dont usually use line lables... and got a little mixed up... I'm too stupid...

    Gremmy...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured