Results 1 to 7 of 7

Thread: [RESOLVED] help (very simple)

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Resolved [RESOLVED] help (very simple)

    i know i know i should know this


    but how can you do a "with"

    example in vb would be

    with OFD_open
    .something
    .somethingelse
    end with


    i have no idea how to do this in c# and everything i try to seach on doesnt want to search the word "with" becuase its joiner word

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: help (very simple)

    Ah, sorry, I misunderstood the question.

    There is no 'With' in C#.

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: help (very simple)

    well then

    im not crazy after all

    or not becuase of this anyway

    thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: help (very simple)

    Let's not forget to resolve our threads.

    "With" in VB doesn't really do anything that can't be done very easily without it. There are only two valid reasons to use a "With" statement in VB:

    1. You want to get a single reference via a long chain, e.g.
    VB Code:
    1. myDataAdapter.SelectCommand.Parameters.AddWithValue("@Paramater1", myTextBox1.Text)
    2. myDataAdapter.SelectCommand.Parameters.AddWithValue("@Paramater2", myTextBox2.Text)
    becomes:
    VB Code:
    1. With myDataAdapter.SelectCommand.Parameters
    2.     .AddWithValue("@Paramater1", myTextBox1.Text)
    3.     .AddWithValue("@Paramater2", myTextBox2.Text)
    4. End With
    so that myDataAdapter.SelectCommand.Parameters gets evaluated only once. This can be mimicked using a local variable with only slightly more code.

    2. You want to access multiple members of the same variable without typing the variable name multiple times. This is mostly negated by the fact that C# Intellisense kicks in as soon as you start typing, although you can prompt VB Intellisense with Ctrl+Space anyway.

    The "With" statement is intended to make code easier to read but many people misuse it and it actually has the opposite affect. Any dots not at the beginning of a line are actually harder to see, so to use a With block like this:
    VB Code:
    1. With myTextBox
    2.     .Text = "Hello World"
    3.     MessageBox.Show(.Text)
    4. End With
    would be considered bad coding style.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: help (very simple)

    yea i just didnt want to type it in over and over.

    i just put it on the clipboard and did it that way

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: help (very simple)

    So... this thread is resolved, correct?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: help (very simple)

    Correct.

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