Unofficial Programming Thread II

Post » Tue May 17, 2011 11:13 am

Somehow I stumbled through and got my service optimizer working. Now I need to somehow write the XML file for the default values then a new one. When I get the ability to save a configuration working I will need beta testers.
User avatar
Elina
 
Posts: 3411
Joined: Wed Jun 21, 2006 10:09 pm

Post » Tue May 17, 2011 3:38 am

So I'm writing a program in Java that scores and reports the value of a poker hand, and I'm using enums for it, but I'm having a little bit of trouble.

My Card class itself is fine, has enums for Rank and Suit, and when I construct my Card object in my main program, that works too. But what I want to do is iterate through both the Suit and Rank until a user specified value is reached. Right now I'm using a for each loop and a switch statement but it's not very efficient or elegant.

Is there something I'm missing so I can just have the user enter say, an integer "3" and have that iterate through my rank enums until it reaches {THREE}?
User avatar
biiibi
 
Posts: 3384
Joined: Sun Apr 08, 2007 4:39 am

Post » Tue May 17, 2011 12:58 pm

I would do something like this
public enum Suit{HEARTS, SPADES, CLUBS, DIAMONDS}int ordianol = 1Suit foo = Suit.values()[ ordinal ];

User avatar
Loane
 
Posts: 3411
Joined: Wed Apr 04, 2007 6:35 am

Post » Tue May 17, 2011 1:10 am

I would do something like this
public enum Suit{HEARTS, SPADES, CLUBS, DIAMONDS}int ordianol = 1Suit foo = Suit.values()[ ordinal ];


Thanks, I think that'll do the trick.
User avatar
Mariana
 
Posts: 3426
Joined: Mon Jun 12, 2006 9:39 pm

Post » Tue May 17, 2011 5:13 am

VB.net express 2010.

Let's say I have 30 pictureboxes named PictureBoxX where X is the number of it.

Now I'm writing something to pop a picture into every picturebox; is there a way to avoid having to do 30 lines of PictureBoxX.ImageLocation = "location"? Like somehow calling the PictureBox part with a variable for X? I can't figure out how. As it is, I have 30 lines - 1 for each picturebox. Every line is the same except for the picturebox number.
User avatar
Facebook me
 
Posts: 3442
Joined: Wed Nov 08, 2006 8:05 am

Post » Tue May 17, 2011 3:46 am

VB.net express 2010.

Let's say I have 30 pictureboxes named PictureBoxX where X is the number of it.

Now I'm writing something to pop a picture into every picturebox; is there a way to avoid having to do 30 lines of PictureBoxX.ImageLocation = "location"? Like somehow calling the PictureBox part with a variable for X? I can't figure out how. As it is, I have 30 lines - 1 for each picturebox. Every line is the same except for the picturebox number.

If there is a way, I'd like to know it too. Maybe something with the preprocessor?
User avatar
Eoh
 
Posts: 3378
Joined: Sun Mar 18, 2007 6:03 pm

Post » Tue May 17, 2011 12:27 am

VB.net express 2010.

Let's say I have 30 pictureboxes named PictureBoxX where X is the number of it.

Now I'm writing something to pop a picture into every picturebox; is there a way to avoid having to do 30 lines of PictureBoxX.ImageLocation = "location"? Like somehow calling the PictureBox part with a variable for X? I can't figure out how. As it is, I have 30 lines - 1 for each picturebox. Every line is the same except for the picturebox number.

Having thirty lines to instantiate thirty objects seems a bit strange. Generally, when you want to do repetitive stuff, you use a loop:

PictureBox[] boxes = new PictureBox[30];for (i=0; i<30; i++)    boxes[i] = new PictureBox();

And in the same way you can set the images.

If you really want to do it using their names, you might take a look at reflection/introspection, although I have no idea if that's even in VB.NET.
User avatar
aisha jamil
 
Posts: 3436
Joined: Sun Jul 02, 2006 11:54 am

Post » Tue May 17, 2011 7:16 am

Having thirty lines to instantiate thirty objects seems a bit strange. Generally, when you want to do repetitive stuff, you use a loop:

PictureBox[] boxes = new PictureBox[30];for (i=0; i<30; i++)    boxes[i] = new PictureBox();

And in the same way you can set the images.

If you really want to do it using their names, you might take a look at reflection/introspection, although I have no idea if that's even in VB.NET.


Yeah - that's why I want to find a way to not have to do 30 lines. Your method doesn't really seem to work in VB at all - it looks more like C# or C++ code.
User avatar
Tessa Mullins
 
Posts: 3354
Joined: Mon Oct 22, 2007 5:17 am

Post » Tue May 17, 2011 11:12 am

While Valdo''s code isn't VB, the same holds true for VB:

Create an array of Picture Boxes with 30 elements. Maybe something like:
Dim pictures(30) as PictureBox'I have no idea if this is required:for i = 0 to 30    pictures(i) = New PictureBox()next

User avatar
Nicole Kraus
 
Posts: 3432
Joined: Sat Apr 14, 2007 11:34 pm

Post » Tue May 17, 2011 7:32 am

Yeah - that's why I want to find a way to not have to do 30 lines. Your method doesn't really seem to work in VB at all - it looks more like C# or C++ code.

I don't know VB, so I picked Java. I figured you'd be able to understand a for loop regardless the language. ;)

Dim pictures(30) as PictureBox'I have no idea if this is required:for i = 0 to 30    pictures(i) = New PictureBox()next


For the record, in Java, if you don't instantiate all members of the array, they'll all be null. No idea about VB either.
User avatar
Kim Bradley
 
Posts: 3427
Joined: Sat Aug 18, 2007 6:00 am

Post » Mon May 16, 2011 11:56 pm

I don't know VB, so I picked Java. I figured you'd be able to understand a for loop regardless the language. ;)


For the record, in Java, if you don't instantiate all members of the array, they'll all be null. No idea about VB either.

I tried to get into Java but didn't like it. The lure of it being named after one of my favorite hot beverages still makes me want to learn it, though.

Anyway, is there any reason to learn PHP & JavaScript? I'm going to eventually learn them both, but it seems like they do the same stuff. What are the strengths/weaknesses of each?
User avatar
Ashley Tamen
 
Posts: 3477
Joined: Sun Apr 08, 2007 6:17 am

Post » Tue May 17, 2011 12:22 am

Anyway, is there any reason to learn PHP & JavaScript? I'm going to eventually learn them both, but it seems like they do the same stuff. What are the strengths/weaknesses of each?

They're very different. JavaScript is primarily a client-side language - it runs on the user's computer in the user's browser (it can also run elsewhere, but that's not as common or important). What's important is that it is the only well-supported client-side web language. If you ever want to run any code in a browser, you'll have to either learn JavaScript or use a framework that translates another language to Javascript (e.g. http://code.google.com/webtoolkit/). Unless you go with Silverlight. Even Flash is powered by a variant of JS, called ActionScript.

PHP, on the other hand, is a server-side language. It's decent and very common, but far from unique. Any other language can do the same work, and often does.
User avatar
Kate Norris
 
Posts: 3373
Joined: Mon Nov 27, 2006 6:12 pm

Post » Tue May 17, 2011 12:29 pm

Dim pictures() as PictureBox
The above would create a dynamic array, but you can create it as fixed size. The dynamic array would be uninitialized until you call ReDim on it with dimensions. Generally simple variables are always initialized to a default value unlike in for example C. A long is initialized as zero and strings as empty strings "". The complex objects need to be instantiated before use with New. I tried it just now without instantiating PictureBox objects in an array like that and simply got a "System.ArgumentNullException". So, yeah, just instantiate the PictureBoxes first.

This actually works too:
Dim pictures() As PictureBox = {New PictureBox, New PictureBox}
pictures(0).Image = System.Drawing.Bitmap.FromFile("C:\Pictures\IMG_2746.JPG")
pictures(1).Image = System.Drawing.Bitmap.FromFile("C:\Pictures\IMG_2747.JPG")
User avatar
D LOpez
 
Posts: 3434
Joined: Sat Aug 25, 2007 12:30 pm

Post » Tue May 17, 2011 2:57 pm

They're very different. JavaScript is primarily a client-side language - it runs on the user's computer in the user's browser (it can also run elsewhere, but that's not as common or important). What's important is that it is the only well-supported client-side web language. If you ever want to run any code in a browser, you'll have to either learn JavaScript or use a framework that translates another language to Javascript (e.g. http://code.google.com/webtoolkit/). Unless you go with Silverlight. Even Flash is powered by a variant of JS, called ActionScript.

PHP, on the other hand, is a server-side language. It's decent and very common, but far from unique. Any other language can do the same work, and often does.

Thanks, I'm a total noob to web programming. PHP probably won't be worth learning soon then, as I already know a couple languages to be server-side.

Thanks again, Max. :)
User avatar
Josh Dagreat
 
Posts: 3438
Joined: Fri Oct 19, 2007 3:07 am

Post » Tue May 17, 2011 11:23 am

So I am having an issue with removing a registry key in C#. Part of the key is a generated numerical value the other part if a specific string, I am trying to search for the string in the name and then remove that key. I am currently stuck how to even appraoch this, I have the node open already and I got all the subkey names into a string array but after that I am a bit lost.

edit: Actually got it but the code is ugly.
Here is how I did it:
        //method to remove the selected mod key from the registry        public bool RemoveKey(Preset p)        {            try            {                RegistryKey ModKey = Registry.LocalMachine.OpenSubKey(ModKeyLocation, true);                if (ModKey != null)                {                    string[] SubKeys = ModKey.GetSubKeyNames();                    for(int i = 0; i <= SubKeys.Length; i++)                    {                        if(SubKeys[i].Contains(p.FullName))                        {                            ModKey.DeleteSubKey(SubKeys[i]);                        }                    }                }                return true;            }            catch            {                return false;            }        }

User avatar
Barbequtie
 
Posts: 3410
Joined: Mon Jun 19, 2006 11:34 pm

Post » Tue May 17, 2011 1:46 pm

So I was thinking of setting up a local Subversion repository for when I do personal programming to eliminate or at least reduce the amount o fmanual backups I need to do of my code. Has anyone done something like this before? When I get home I plan to do it on my external hard drive, but otherwise I will use (or attempt to) use a flash drive or a folder on my local drive. I already use Google code for one project but the others I want to keep somewhat local if I can.
User avatar
Nymph
 
Posts: 3487
Joined: Thu Sep 21, 2006 1:17 pm

Post » Tue May 17, 2011 9:06 am

So I was thinking of setting up a local Subversion repository for when I do personal programming to eliminate or at least reduce the amount o fmanual backups I need to do of my code. Has anyone done something like this before? When I get home I plan to do it on my external hard drive, but otherwise I will use (or attempt to) use a flash drive or a folder on my local drive. I already use Google code for one project but the others I want to keep somewhat local if I can.

I would recommend git, actually. Installing it is really simple, creating a repo is as simple as executing git init, and it's fast. Branching and merging is also really easy.

Unless you're on Windows, in which case installing it is tedious and using it is slow.

[edit] Just realised, you're most likely on Windows given all your C# code... :(
User avatar
Kahli St Dennis
 
Posts: 3517
Joined: Tue Jun 13, 2006 1:57 am

Post » Tue May 17, 2011 9:20 am

I would recommend git, actually. Installing it is really simple, creating a repo is as simple as executing git init, and it's fast. Branching and merging is also really easy.

Unless you're on Windows, in which case installing it is tedious and using it is slow.

[edit] Just realised, you're most likely on Windows given all your C# code... :(

Yeah I am on Windows though I do have MonoDevelop installed in my Ubuntu development virtual machine.
I already have TortoiseSVN installed so I am sticking with that for Windows.

I do however need to figure out how to branch a project on Google Code since I am doing some major changes to the current project and I want to preserve the current source. It will be based on this application but be expanded quite a bit and will change the way it works as a whole, so I want to keep the name but give it its own version andsource control without a new Google Code project.
User avatar
Lovingly
 
Posts: 3414
Joined: Fri Sep 15, 2006 6:36 am

Post » Tue May 17, 2011 1:28 am

I would recommend git, actually. Installing it is really simple, creating a repo is as simple as executing git init, and it's fast. Branching and merging is also really easy.

Unless you're on Windows, in which case installing it is tedious and using it is slow.

[edit] Just realised, you're most likely on Windows given all your C# code... :(

Git may be painful on Windows, but (my personal favorite) Mercurial works fine there -- and Mercurial has an equivalent feature set to git. There's a TortoiseHG for it.

I'd recommend just using that instead of attempting anything related to a branch in Subversion. With any reasonably large project, that's just painful.
User avatar
Nauty
 
Posts: 3410
Joined: Wed Jan 24, 2007 6:58 pm

Post » Tue May 17, 2011 2:09 pm

Git may be painful on Windows, but (my personal favorite) Mercurial works fine there -- and Mercurial has an equivalent feature set to git. There's a TortoiseHG for it.

I'd recommend just using that instead of attempting anything related to a branch in Subversion. With any reasonably large project, that's just painful.

All of my projects are relatively small and my Google Code project is set up as Subversion. I had looked into Mercurial at the start and couldn't decide which to go with so I went with what I have known more about which was Subversion. Would it be hard to make the switch?
User avatar
Nathan Hunter
 
Posts: 3464
Joined: Sun Apr 29, 2007 9:58 am

Post » Tue May 17, 2011 1:01 am

I finally got around to moving my old Python projects onto this computer, so I can compile them and add them to my portfolio. Well, long story short, there are some serious issues with compiling ( primarily with py2exe ) since py 2.6.

It balances out, I suppose. The convenience of interpretation and the hassle of compilation. Downloading 2.5 now and will try to adjust my code accordingly as to work around this dilemma.
User avatar
marie breen
 
Posts: 3388
Joined: Thu Aug 03, 2006 4:50 am

Post » Tue May 17, 2011 7:23 am

Anyone have some good sites to learn about LUA and XML? Trying to program my own plugin/addon for WoW and need to get some references.
User avatar
Kelsey Anna Farley
 
Posts: 3433
Joined: Fri Jun 30, 2006 10:33 pm

Post » Tue May 17, 2011 3:33 am

Anyone have some good sites to learn about LUA and XML? Trying to program my own plugin/addon for WoW and need to get some references.

http://www.w3schools.com/xml/default.asp has a bunch of stuff on XML, not sure how in depth or if it will help you but it is there. I linked to the XML stuff directly but there was other sections for it on the front page, though its possible they are just links to sections inside the section.
User avatar
Matt Bigelow
 
Posts: 3350
Joined: Sun Sep 30, 2007 6:36 pm

Post » Tue May 17, 2011 1:31 am

I need some help reading XML files in C#. Here's what's in the XML file.
	An example assignment XML file	3	2/7/2011	3/1/2011

Wow. You can't even read that.
User avatar
Doniesha World
 
Posts: 3437
Joined: Sun Jan 07, 2007 5:12 pm

Post » Tue May 17, 2011 4:55 am

I need some help reading XML files in C#. Here's what's in the XML file.
	An example assignment XML file	3	2/7/2011	3/1/2011

Wow. You can't even read that.

What are you trying to do with it? I use XML files with almost all of my programs.
User avatar
Kim Kay
 
Posts: 3427
Joined: Fri Oct 13, 2006 10:45 am

PreviousNext

Return to Othor Games