Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

Code Jockey posted:


This is a dumb, dumb question I'm sure, but VS2005 can do 3.5 perfectly well, can't it? There's no way in hell I'm going to convince my boss to shell out for VS2008 right now, so I'm rather stuck.


No, it can't. You'd have to use VS 2008 express.

Adbot
ADBOT LOVES YOU

Code Jockey
Jan 24, 2006

69420 basic bytes free

Nurbs posted:

No, it can't. You'd have to use VS 2008 express.

Crap, I looked it up and the site I was reading said it'd work, but it was just talking about referencing the new assemblies, not taking advantage of the new syntax and compilers what not.

Fffffuck. Well, I'll grab Express and work on convincing him to get me the full thing.

wwb
Aug 17, 2004

It's worth it. LINQ is like sex without the bodily fluids.

Actually, at this point, I would really look to jump to 4.0 rather than 3.5. And the full-blown VS 2010 is in public beta and reputedly pretty solid.

No real seat-time with NH, but does it specify the string or a connection string name? I think you can also provide the connection string when you initiate the session, which is probably what your code should be doing anyhow.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.
Ok, I have narrowed down my imaging thing quite a bit (with IsaacNewtons very helpful hints), now here is my only stumbling block...

I am creating 1's and 0's, and need to put these into an array of bytes, I think you can do this with some sort of <<< operator or something...

So I will loop through the pixels and start adding ones and zeros to a byte, every eight bit I will add the current byte to an array, then create a new byte, something like this

Create a new byte (0000 0000)

Read in the pixel
Add a 0 or 1 depending on the brightness(
(byte now contains 1000 0000)

Read next pixel
Add another bit, in this case a 0
(byte now contains 1000 0000)

Read next pixel
Add another bit
(byte now contains 1010 0000)

... etc.
(byte now contains 1010 1101)

Add that byte to my byte[] array and start with a new one

When we reach the end of the row just add the last byte we are working with to the array (that will take care of the padding) and start with the next row


Thats the last missing piece is how to create these bytes, I have everything else solved including determining the bytes per row and converting it to a hexidecimal string.

Code Jockey
Jan 24, 2006

69420 basic bytes free
Welp teach me to follow a tutorial without actually reading about what the gently caress I'm doing

Thank god the table I accidentally wiped out with my NHibernate tutorial was on the development server. :sweatdrop:

Fiend
Dec 2, 2001
Anyone know of a method that will strip BR tags from the beginning of a string? I have a series of records where some of the columns have preceding break tags in XHTML format and appear as "<BR>", "<BR />", "<BR/>". I need to have the mechanism strip only from the beginning of the string and nowhere else.

Anyone know if there is a regex option or something simple that is not a perf hit?

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

Fiend posted:

Anyone know of a method that will strip BR tags from the beginning of a string? I have a series of records where some of the columns have preceding break tags in XHTML format and appear as "<BR>", "<BR />", "<BR/>". I need to have the mechanism strip only from the beginning of the string and nowhere else.

Anyone know if there is a regex option or something simple that is not a perf hit?

I suppose you could take the first x characters in each string and regex those.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.
Ok, I figured it out

code:
byte bits = 0x0;

// Set the bit in the first position to 1
bits |= 1 << 7;

// set the bit in the 5th position to 1
bits |= 1 << 3;
Hot.

tk
Dec 10, 2003

Nap Ghost

Fiend posted:

Anyone know of a method that will strip BR tags from the beginning of a string? I have a series of records where some of the columns have preceding break tags in XHTML format and appear as "<BR>", "<BR />", "<BR/>". I need to have the mechanism strip only from the beginning of the string and nowhere else.

Anyone know if there is a regex option or something simple that is not a perf hit?

I would probably use Regex.Replace(input, @"^<[Bb][Rr]\s?/?>", "");

SixPabst
Oct 24, 2006

^^ On that same note, I'd like to pull out the "action" attribute of a form tag. I'm terrible with regular expressions and even after a bit of googling couldn't get this to work.

The form tag looks like this:

code:
<form id="form"
  action=
    "some url"
  method="post"
    >
I'm at a loss. I tried the following clusterfuck:

code:
Regex reg = new Regex("(<form.*?action=\")([^\"]*)(\"[^>]*>)", RegexOptions.IgnoreCase | RegexOptions.Multiline); 
Any help?

IsaacNewton
Jun 18, 2005

mintskoal posted:

Any help?

code:
action = Regex.Match(SubjectString, "<form[^i]+id=\"[^\"]+\"[^a]+action=[^\"]+\"([^\"]*)\"[^>]*>",
		RegexOptions.IgnoreCase | RegexOptions.Multiline).Groups[1].Value;
Edit: Modified it so that it doesn't poo poo a brick if an 'a' is included in the form ID.

SixPabst
Oct 24, 2006

IsaacNewton posted:

code:
action = Regex.Match(SubjectString, "<form[^i]+id=\"[^\"]+\"[^a]+action=[^\"]+\"([^\"]*)\"[^>]*>",
		RegexOptions.IgnoreCase | RegexOptions.Multiline).Groups[1].Value;
Edit: Modified it so that it doesn't poo poo a brick if an 'a' is included in the form ID.

gently caress me it works! Thank you!!!!

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
If you're trying to do HTML parsing, use HtmlAgilityPack and not a regex. It's A) a lot easier to write XPath to find what you want and B) not going to gently caress up if the HTML changes slightly.

wwb
Aug 17, 2004

^^^This. Or, if you can guarantee it is XML, just use XElment or XmlDocument or whatever you want to pull xpath from.

SixPabst
Oct 24, 2006

Free Bees posted:

If you're trying to do HTML parsing, use HtmlAgilityPack and not a regex. It's A) a lot easier to write XPath to find what you want and B) not going to gently caress up if the HTML changes slightly.

I can't believe I haven't seen this before. Thanks!

Fiend
Dec 2, 2001

tk posted:

I would probably use Regex.Replace(input, @"^<[Bb][Rr]\s?/?>", "");

hrm....

code:
string tehString = "<br><br><br /><br/> <br/><br /><br>Lorem ipsum dolor sit amet<br/>";
Console.WriteLine(tehString);
Console.WriteLine(Regex.Replace(tehString, @"^<[Bb][Rr]\s?/?>", string.Empty));

Output posted:

<br><br><br /><br/> <br/><br /><br>Lorem ipsum dolor sit amet<br/>
<br><br /><br/> <br/><br /><br>Lorem ipsum dolor sit amet<br/>

I'm not sure what is going on here, but pretty sure I know dick about regular expressions :(

gibbed
Apr 10, 2006

It's replacing the first <br> as indicated by the regular expression.

tk
Dec 10, 2003

Nap Ghost

Fiend posted:

hrm....

code:
string tehString = "<br><br><br /><br/> <br/><br /><br>Lorem ipsum dolor sit amet<br/>";
Console.WriteLine(tehString);
Console.WriteLine(Regex.Replace(tehString, @"^<[Bb][Rr]\s?/?>", string.Empty));
I'm not sure what is going on here, but pretty sure I know dick about regular expressions :(

Oh, you probably want something more like @"^(\s*<[Bb][Rr]\s?/?>)+".

Also, http://www.regular-expressions.info/tutorial.html

Code Jockey
Jan 24, 2006

69420 basic bytes free

This website is second only to google in # of hits per month. I write a lot of regexes and it's invaluable.

Also EditPad. It makes developing the little bastards really simple, just type in a bunch of text, fire up the search, turn on highlight and you get a realtime display of how your regex will match the string(s).

Dietrich
Sep 11, 2001

Check out Expresso for all your RegEx creation/checking needs. It provides a nice little logic tree that really illustrates what your regex is being interpreted to mean.

tk
Dec 10, 2003

Nap Ghost
I like to use http://www.nregex.com/. I've never tried out EditPad/Expresso/RegexBuddy, but I'm on different computers all day long so a website is easy for me.

Fiend
Dec 2, 2001

gibbed posted:

It's replacing the first <br> as indicated by the regular expression.
It's good that you are able to explain the problem and meet me halfway with my problem and all. Thank you for bumping the thread I guess.


tk posted:

Oh, you probably want something more like @"^(\s*<[Bb][Rr]\s?/?>)+".

Also, http://www.regular-expressions.info/tutorial.html
This is perfect, thank you so much tk :)

...

NOM NOM NOM NOM NOM
  /
:v: • • • • • •

gibbed
Apr 10, 2006

Fiend posted:

It's good that you are able to explain the problem and meet me halfway with my problem and all. Thank you for bumping the thread I guess.
I should have probably linked a tutorial as tk did, I apologize.

gibbed fucked around with this message at 23:23 on Jul 10, 2009

Fiend
Dec 2, 2001
I just did some testing, the old method that used a while loop took 23 seconds to perform the replacement 1,000,000 times while the regex method took about 5. Regex is definitely something I need to become more familiar with. Thanks again tk.

Yeah, I overreacted and should not have responded.

Fiend fucked around with this message at 23:02 on Jul 10, 2009

MrHyde
Dec 17, 2002

Hello, Ladies

Fiend posted:

Or maybe an answer instead of a statement that addresses the problem instead of a pompous statement to stroke your ego?

Alternately, you quit being a dickhead and google "regular expressions" and try to learn something for yourself instead of waiting for someone to do it for you. At the very least accept the apology with a little bit of class.

No Safe Word
Feb 26, 2005

Fiend posted:

Or maybe an answer instead of a statement that addresses the problem instead of a pompous statement to stroke your ego?

His statement wasn't pompous, even if it wasn't all that specific. You're just being a dick.

Fiend
Dec 2, 2001

MrHyde posted:

Alternately, you quit being a dickhead and google "regular expressions" and try to learn something for yourself instead of waiting for someone to do it for you. At the very least accept the apology with a little bit of class.
It was snarky and it should have been ignored, and I had exhausted all avenues for this specific issue before bringing it to this thread.


No Safe Word posted:

His statement wasn't pompous, even if it wasn't all that specific. You're just being a dick.
You're right, it was snarky and I felt that saying "apology accepted" would have seemed equally snarky and inflame him further. Unfortunately I overreacted and responded to him instead of ignoring, and I apologize again for the derail.

Kekekela
Oct 28, 2004

Fiend posted:

Regex is definitely something I need to become more familiar with.

Man if I had a nickel for every time I or someone else uttered those words. One of the situations I often find myself in when I decide to replace some string functions with regex is that I'll come up with something based on my cheatsheets and references that "works", but then I see someone doing something similar with a regex that's five times as long and I realize they're probably catching all sorts of edge cases I'm not accounting for. :smith:

derelict515
Sep 10, 2003
WinForms TreeView help:

I have very little WinForms experience so this may be dumb but I couldn't find anything in searching (it seems like the WPF TreeView is much nicer). I have a TreeView that I want to be able to filter the contents of as you type in a TextBox on the form. Besides the fact that generally iterating through it is not as easy as I'd like, what do I need to do to accomplish this so that updating the tree is done quickly? In particular, the methods on the TreeView I'm using now cause it to be redrawn/collapsed each time you type, forcing you to then expand out the nodes you want which obviously makes this functionality not nearly as nice (almost to the point of not being worth implementing). Is there a way to keep the tree expanded in whatever state it's in and just hide elements? Or do I have iterate over the whole tree, adding the elements I want to a new TreeNodeCollection, tracking their expanded state, and then use that new tree as the root of my TreeView?

Whompy
Apr 21, 2002

derelict515 posted:

WinForms TreeView help:

I have very little WinForms experience so this may be dumb but I couldn't find anything in searching (it seems like the WPF TreeView is much nicer). I have a TreeView that I want to be able to filter the contents of as you type in a TextBox on the form. Besides the fact that generally iterating through it is not as easy as I'd like, what do I need to do to accomplish this so that updating the tree is done quickly? In particular, the methods on the TreeView I'm using now cause it to be redrawn/collapsed each time you type, forcing you to then expand out the nodes you want which obviously makes this functionality not nearly as nice (almost to the point of not being worth implementing). Is there a way to keep the tree expanded in whatever state it's in and just hide elements? Or do I have iterate over the whole tree, adding the elements I want to a new TreeNodeCollection, tracking their expanded state, and then use that new tree as the root of my TreeView?

Try something like this:

code:
//onAfterExitEditModeEventHandler{
//var foo = new TreeView();
            if (foo.Nodes != null)
            {
                var bar = foo.Nodes as IEnumerable<TreeNode>;
                if (bar != null)
                {
                    foreach (var node in bar.ToList())
                    {
                        //DoStuff
                        if (node.Parent != null)
                        {
                            node.Visible =   node.Text.ToLower().Contains(this.TextEditorFilter.Text.ToLower());
                        }
                    }
                    this.TreeView.ExpandAll();
                }
            }
//}

Whompy fucked around with this message at 06:35 on Jul 12, 2009

Code Jockey
Jan 24, 2006

69420 basic bytes free

Kekekela posted:

they're probably catching all sorts of edge cases I'm not accounting for. :smith:

This is one of the big reasons I love regex. Properly written, they can handle all sorts of things traditional string search methods might miss.

seregrail7
Nov 3, 2006
I'm having trouble with WinForms again, and the solution is probably simple.

I'm creating a level editor and I have a main form where the level is displayed, along with the properties for the selected item and the level components. I want it to work so that when you want to add a new sprite to the level, a box pops up and you select the sprite to add. I've gotten this far, but my problem is telling the other form to add in the sprite, how do I get the sprite form to tell the level editor form what to do?

uXs
May 3, 2005

Mark it zero!

seregrail7 posted:

I'm having trouble with WinForms again, and the solution is probably simple.

I'm creating a level editor and I have a main form where the level is displayed, along with the properties for the selected item and the level components. I want it to work so that when you want to add a new sprite to the level, a box pops up and you select the sprite to add. I've gotten this far, but my problem is telling the other form to add in the sprite, how do I get the sprite form to tell the level editor form what to do?

Your sprite dialog probably has an Ok and a Cancel button. Set their DialogResult properties to "OK" and "Cancel".

Also add a public function "GetSprite()" that returns the selected sprite, if any.

In your level editor, test the DialogResult you're getting from the sprite dialog. If it's "Ok", then call the GetSprite() function to get the sprite.


So you don't let the sprite form tell the level form what to do. Instead, you have the level form ask the sprite form what the result was.

seregrail7
Nov 3, 2006
Thanks, that works perfectly.

derelict515
Sep 10, 2003

Whompy posted:

Try something like this:

code:
//onAfterExitEditModeEventHandler{
//var foo = new TreeView();
            if (foo.Nodes != null)
            {
                var bar = foo.Nodes as IEnumerable<TreeNode>;
                if (bar != null)
                {
                    foreach (var node in bar.ToList())
                    {
                        //DoStuff
                        if (node.Parent != null)
                        {
                            node.Visible =   node.Text.ToLower().Contains(this.TextEditorFilter.Text.ToLower());
                        }
                    }
                    this.TreeView.ExpandAll();
                }
            }
//}

But there's no Visible property on TreeNodes :( That's what threw me off before. There's only a settable Visible property on a TreeView but the nodes themselves just have an IsVisible that's only a getter, there doesn't seem to be a way to hide nodes short of removing them entirely. But then I have to save any removed node's structure (with all it's children) somewhere and restore it to how it was every time another character changes in the textbox which seems like it's going to be doing a lot of allocating on every character entered and just generally a pain to implement.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
Can someone tell me if such a thing as I describe is possible?

I'd like to run an application that tells me the url of every incoming request on port 80, but does not block the request from being processed by IIS. I don't want to handle the request itself; just keep a log of all requests coming in, and what's being requested. The web application I'm interested in using this with in particular is not written in asp.net, so an http module won't work.

Island Nation
Jun 20, 2006
Trust No One
This is probably a newbie questions but I couldn't get good info online on this.

I want to have a button on my VB 2008 form take a person online to a specific website but I'm not sure what code I have to put in to open the browser much less open it with the site itself. What code am I missing here?

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

NYIslander posted:

This is probably a newbie questions but I couldn't get good info online on this.

I want to have a button on my VB 2008 form take a person online to a specific website but I'm not sure what code I have to put in to open the browser much less open it with the site itself. What code am I missing here?

string url = "http://cnn.com";

System.Diagnostics.Process.Start(url); // May be System.Diagnostics.Process.Run - I can't remember

Island Nation
Jun 20, 2006
Trust No One

Nurbs posted:

string url = "http://cnn.com";

System.Diagnostics.Process.Start(url); // May be System.Diagnostics.Process.Run - I can't remember

Got 3 errors with Process.Start

Error 1 'String' is a class type and cannot be used as an expression. (under string)
Error 2 '.' expected. (under url)
Error 3 Name 'url' is not declared. (under url on the second line)

Adbot
ADBOT LOVES YOU

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

NYIslander posted:

Got 3 errors with Process.Start

Error 1 'String' is a class type and cannot be used as an expression. (under string)
Error 2 '.' expected. (under url)
Error 3 Name 'url' is not declared. (under url on the second line)

I wrote it in C# out of habit. For VB I believe it goes like this

Dim url as string

url = "http://cnn.com"

System.Diagnostics.Process.Start(url)

  • Locked thread