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!
Has anyone ever tried connecting to a filemaker database via odbc and have any advice to impart (other than run far far away)?

Adbot
ADBOT LOVES YOU

wwqd1123
Mar 3, 2003
Why does C# allow you to implicitly create variables with the var keyword? It seems like this serves no purpose other than to eventually screw yourself over in the long run when you're debugging your code and can't figure out why all your vars are creating problems.

csammis
Aug 26, 2003

Mental Institution

wwqd1123 posted:

Why does C# allow you to implicitly create variables with the var keyword? It seems like this serves no purpose other than to eventually screw yourself over in the long run when you're debugging your code and can't figure out why all your vars are creating problems.

I have no idea what you're talking about unless you mean explicitly creating implicitly typed variables...in which case the language reference should be a good explanation of the intended use cases.

And if that's not what you meant, can you give an example of what the hell you're talking about? :psyduck:

bgreman
Oct 8, 2005

ASK ME ABOUT STICKING WITH A YEARS-LONG LETS PLAY OF THE MOST COMPLICATED SPACE SIMULATION GAME INVENTED, PLAYING BOTH SIDES, AND SPENDING HOURS GOING ABOVE AND BEYOND TO ENSURE INTERNET STRANGERS ENJOY THEMSELVES

wwqd1123 posted:

Why does C# allow you to implicitly create variables with the var keyword? It seems like this serves no purpose other than to eventually screw yourself over in the long run when you're debugging your code and can't figure out why all your vars are creating problems.

If I write a something like:
code:
var myThing = new MyThing();
It's pretty obvious what type 'var' is and saves me having to type "MyThing" a scrillion times.

In the case of something like
code:
var someThing = GetSomeThing();
or
code:
foreach (var iterator in someObject.GetSomeCollection())
it's less clear, but frankly, with modern IDEs, if I'm looking at the code, I can figure out what's going on with a minimum of effort.

The only time I'd ever think it made things too opaque was if I was reading printed-out code. And who would do that? :psyduck:

Edit: It is purely syntactic sugar used to make my life as a programmer easier, so I don't wind up typing out type names a bunch of times.

Edit edit: Also what csammis said, if you have an anonymous type, you basically have to use it since you don't have access to the typename.

bgreman fucked around with this message at 16:40 on Apr 30, 2010

BliShem
Dec 21, 2008

bgreman posted:

If I write a something like:
code:
var myThing = new MyThing();
It's pretty obvious what type 'var' is and saves me having to type "MyThing" a scrillion times.

In the case of something like
code:
var someThing = GetSomeThing();
or
code:
foreach (var iterator in someObject.GetSomeCollection())
it's less clear, but frankly, with modern IDEs, if I'm looking at the code, I can figure out what's going on with a minimum of effort.

The only time I'd ever think it made things too opaque was if I was reading printed-out code. And who would do that? :psyduck:

Edit: It is purely syntactic sugar used to make my life as a programmer easier, so I don't wind up typing out type names a bunch of times.

Edit edit: Also what csammis said, if you have an anonymous type, you basically have to use it since you don't have access to the typename.

But you get auto completion for the type as you're typing it anyway, and it saves the next guy the hassle of mousing over the variable every drat time to figure out what type it is.
And I say this after spending the past week being that next guy, debugging stuff after a guy who usually writes nothing but html and JavaScript.

I wish Visual Studio had an option to automatically replace all 'var' in the code with the actual types so the code would be fast to both read AND write...

csammis
Aug 26, 2003

Mental Institution

BliShem posted:

But you get auto completion for the type as you're typing it anyway, and it saves the next guy the hassle of mousing over the variable every drat time to figure out what type it is.
And I say this after spending the past week being that next guy, debugging stuff after a guy who usually writes nothing but html and JavaScript.

I wish Visual Studio had an option to automatically replace all 'var' in the code with the actual types so the code would be fast to both read AND write...

Like every other piece of syntactic sugar it can be overdone by someone who doesn't know why they're doing it, but it's dumb to just say gently caress YOU VAR without any caveat. If you read the documentation and what's been written here sometimes var is necessary because the type isn't accessible.

BliShem
Dec 21, 2008

csammis posted:

Like every other piece of syntactic sugar it can be overdone by someone who doesn't know why they're doing it, but it's dumb to just say gently caress YOU VAR without any caveat. If you read the documentation and what's been written here sometimes var is necessary because the type isn't accessible.

I never said var is bad thing no matter what. I use it all the time, but always for anonymous types in the middle of linq queries.

You can disagree if you like, but in my opinion, if you know the type of your variable you should declare it as such, if only to make the lives of future maintainers a little easier.

MrBishop
Sep 30, 2006

I see what you did there...

Soiled Meat
Just started using VS 2010 the last couple days, and something is bugging the crap out of me. In VS 2008, I could double-click some whitespace, and select just that white space. In VS 2010, when I double-click whitespace, it selects that whitespace but also some other characters next to it. For example, in a variable declaration line, if I have two or more spaces between the type and the variable name, double-clicking the space will select the space + the variable name. If I have spaces at the end of a line, double-clicking selects the spaces + the last token (semi-colon, bracket, etc).

Is there any way to change this behavior? I looked in the text editor section of the options, but didn't see anything related.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

BliShem posted:

You can disagree if you like, but in my opinion, if you know the type of your variable you should declare it as such, if only to make the lives of future maintainers a little easier.

Is it really that bad? Based on context, comments, the name of the variable and the method/constructor call, you should have a pretty good idea of what type it is and even if you don't it only costs a second to hover over the variable.

If you have to do maintenance on a piece of code you've never seen (or it's been months/years), then figuring out what's going on is going to cost some time anyway. I just don't see how figuring out which types are being used is going to impact that in any significant way.

That said, if you're working with lots of calculations, var does tend to muddle things up.

And maybe my perspective is skewed because I work with a very small team on a codebase that I'm familiar with on pretty much every level, so I rarely have to wonder about what types are being used.

ljw1004
Jan 18, 2005

rum

BliShem posted:

You can disagree if you like, but in my opinion, if you know the type of your variable you should declare it as such, if only to make the lives of future maintainers a little easier.

I think it's a reasonable concern. But have you used the new "dynamic" keyword yet? :)

Kekekela
Oct 28, 2004
One of the Resharper defaults at one point (not sure if its been changed) was to always use var, which lead to a lot of over-usage. I was initially against it in places where it didn't have to be used but I've since come around to pretty much always using it if the right-hand side of the declaration makes the type clear. I find its a marginal time-saver when I have to do a refactoring that involves changing the type, but mainly because somewhere along the way "MyType m = new MyType();" starting looking too verbose.

BliShem
Dec 21, 2008

dwazegek posted:

Is it really that bad? Based on context, comments, the name of the variable and the method/constructor call, you should have a pretty good idea of what type it is and even if you don't it only costs a second to hover over the variable.

If you have to do maintenance on a piece of code you've never seen (or it's been months/years), then figuring out what's going on is going to cost some time anyway. I just don't see how figuring out which types are being used is going to impact that in any significant way.

That said, if you're working with lots of calculations, var does tend to muddle things up.

And maybe my perspective is skewed because I work with a very small team on a codebase that I'm familiar with on pretty much every level, so I rarely have to wonder about what types are being used.

It only takes a second to mouse over the variable to see the type, sure, but its a second I have to spend almost each and every time var appears without a handy = new MyType() after. After a while this sort of thing can really get on your nerves.
An unfortunately common occurrence of var is something like
code:
var gridDetails = GetData();
, which immediately gets shoved into the DataContext of a WPF control and I have to make sure the variable is an ObservableCollection instead of a List or Dictionary or whatever.

It doesn't help that in my demented mind, every time I see this, I get a picture of the guy who wrote the code, going "hehe, the compiler figured this one out, see if you can! :smug:"

I'm basically pissed that I have to solve scope and context riddles just because someone else was too lazy to write the first 4 letters of the proper type and hit tab. And don't even get me started on dynamic. I dread the day we move to .NET 4 because of that single keyword.

Dietrich
Sep 11, 2001

Var is awesome. When I change the return type of something from, say, list<t> to ienumerable<t>, IT KEEPS WORKING.

wwb
Aug 17, 2004

Var can be awesome. Especially when doing aspx template stuff with strongly typed variables and you don't have either <%@ Import %>s all over the place, or SomeCompany.Core.Entites.Something.SomethingElse.SomeClass all over the place.

Definitely agree it can make things less readable in some cases.

Intel Penguin
Sep 14, 2007
hooray

wwqd1123 posted:

Why does C# allow you to implicitly create variables with the var keyword? It seems like this serves no purpose other than to eventually screw yourself over in the long run when you're debugging your code and can't figure out why all your vars are creating problems.

It's for anonymous types, mostly. Like when you do a LINQ query with a custom returned object.

Too Poetic
Nov 28, 2008

Is there any easy way to make a transparent label in Visual Studio 2010? I've tried setting the background color to transparent but for whatever stupid reason it's not really transparent. Googling isnt being too helpful. I'm trying to put it on top of a picture box.

Sab669
Sep 24, 2009

I'm having a bit of a problem with a combo box for this project I'm working on. Basically, the program is just a simple application that let's the owner of a restaurant manage employee data, items on their menu, and reservations.

I'm handling the menu portion, and my two group mates are doing the other two functions. Each one of these three functions will obviously have the basic Create / Read / Update / Delete abilities, and I have 3 out of 4 of these functions working. I'm stuck on the Update portion.

So, say you launch the program, this is what it'd look like:


Then when you select Menu, you're presented with the various CRUD options:


As said, I'm stuck on Edit. I have the user prompted with a combo box that lets them select the piece of food they want to edit, then click the button:


That will open up a new form, which is populated with info from the database HOWEVER the combo box is what I'm stuck on. I've tried changing all sorts of properties, but I have no idea which one I want to change, and it keeps throwing errors that I don't quite understand, or it doesn't throw an error and then defaults to the first thing, which is Appetizer:



What it should be:


So yea, I've tried tooling around with drat near every property of the combo box, and I can't seem to figure out what I'm doing wrong.

Here's the code for the entire page. Initially, instead of a for loop, I just had while(drSelect.Read()) but that was returning -1 for menuType, I think? So I tried a for instead, but that didn't solve the problem.
http://pastebin.com/CZVWBYn8

The database I'm using has 2 tables.
Menus, which stores the menuID, menuPrice, menuName, menuDesc, and menuType (foriegn key to the following table)

Types, which stores typeID, typeName

So this would be the Appetizer, Entree, Dessert, Beverage table. But again, I can't seem to get the Edit Menu form to properly display which course the designated food falls under. Any ideas what I'm doing wrong, goons?

Sab669 fucked around with this message at 00:13 on May 5, 2010

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

Sab669 posted:

So this would be the Appetizer, Entree, Dessert, Beverage table. But again, I can't seem to get the Edit Menu form to properly display which course the designated food falls under. Any ideas what I'm doing wrong, goons?
I'm couldn't really follow your post, but you want it to have Entree selected?

So.. comboBox1.SelectedIndex = 1;
Index starts at 0, so entree is 1? I would also recommend you put your items in alphabetical order, it makes more sense.

And if you have your combo box indices linked to your database ids you can just select the correct id based on the one you get from the database.

Sab669
Sep 24, 2009

Sweeper posted:

I'm couldn't really follow your post, but you want it to have Entree selected?

So.. comboBox1.SelectedIndex = 1;
Index starts at 0, so entree is 1? I would also recommend you put your items in alphabetical order, it makes more sense.

And if you have your combo box indices linked to your database ids you can just select the correct id based on the one you get from the database.


Well, for the condition shown in the screen shot, yes, Entree is supposed to be selected. But if they chose Bud Lite in the previous prompt, then it should display Beverage.

I've tried cmbCourse.SelectedIndex = Convert.ToInt16(drSelect["menuType"]); and it didn't work. As I've said, I've tried drat near every property for the combo box. From SelectedMember, Index, Value, to DisplayMember or Value, I've fidgetted with almost everything.

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

Sab669 posted:

So this would be the Appetizer, Entree, Dessert, Beverage table. But again, I can't seem to get the Edit Menu form to properly display which course the designated food falls under. Any ideas what I'm doing wrong, goons?

Well you are setting the index an int value with a 0 index to well i'm not sure how that even works.

code:
int index = cmbCourse.FindString(drSelect["menuType"]);
cmbCourse.SelectedIndex = index;
This is assuming your "menutype" is the string your looking for if its say the ID in your table then you'll have to pull out the string.

Also this is an app for school right? just proof of concept?

efb;

Sab669
Sep 24, 2009

Sprawl posted:

Well you are setting the index an int value with a 0 index to well i'm not sure how that even works.

code:
int index = cmbCourse.FindString(drSelect["menuType"]);
cmbCourse.SelectedIndex = index;
This is assuming your "menutype" is the string your looking for if its say the ID in your table then you'll have to pull out the string.

Also this is an app for school right? just proof of concept?

efb;

I've made the mistake of going to a Tech school, rather than a traditional college, so this is actually my "senior" project. Will have my associates degree in a few weeks.

e; so yes, I know it's terrible and I'm not a good programmer.

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

Sab669 posted:

I've made the mistake of going to a Tech school, rather than a traditional college, so this is actually my "senior" project. Will have my associates degree in a few weeks.

e; so yes, I know it's terrible and I'm not a good programmer.
If you have this:
code:
cmbCourse.SelectedIndex = Convert.ToInt16(drSelect["menuType"]);
and menuType is a string shouldn't it be:
code:
cmbCourse.SelectedIndex = Convert.ToInt16(drSelect[menuType]);
What I see in the first one is you are getting drSelect at index menuType instead of whatever menuType contains?
If you are in visual studio set a break point at this line
code:
cmbCourse.SelectedIndex = Convert.ToInt16(drSelect["menuType"]);
and see what
code:
Convert.ToInt16(drSelect["menuType"]);
returns and if it is correct

Sab669
Sep 24, 2009

I've tried printing out menuType to a text field, like just concatenating it onto txtDesc.Text and it does return the value expected (in this case, a 2).

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

Sab669 posted:

I've tried printing out menuType to a text field, like just concatenating it onto txtDesc.Text and it does return the value expected (in this case, a 2).

Okay well iirc a combo box index is a 0 index so you would need to -1 to that value anyways.

I think i finally understand what you need to do

code:
cmbCourse.SelectedIndex = drSelect["menuType"];
should be

code:
cmbCourse.SelectedIndex = ID - 1;

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

Sprawl posted:

Okay well iirc a combo box index is a 0 index so you would need to -1 to that value anyways.

I think i finally understand what you need to do

code:
cmbCourse.SelectedIndex = drSelect["menuType"];
should be

code:
cmbCourse.SelectedIndex = ID - 1;
Yes combo boxes are 0 indexed, I looked at your pastebin code and I see that you are using the SQL datareader stuff, it makes more sense now.

If you could paste some of your errors here it would be helpful.

Sab669
Sep 24, 2009

Sprawl posted:

Okay well iirc a combo box index is a 0 index so you would need to -1 to that value anyways.

I think i finally understand what you need to do

code:
cmbCourse.SelectedIndex = drSelect["menuType"];
should be

code:
cmbCourse.SelectedIndex = ID - 1;

Well, the thing with ID - 1 is that ID is actually the ID of the meal they edited, so that can range from 1 through 40 based off whatever meal they selected from that first drop down box. But I get what you're saying.

I could just parse out menuType to any variable, subtract one, and then do SelectedIndex = that.

Thing is though, I know I tried setting SelectedIndex = menuType, and it threw some error. I don't recall what, exactly though. And I'm honestly not sure if I can work on it now (I'm out of class finally) and my laptop was having some problems connecting to the DB last I knew.

BizarroAzrael
Apr 6, 2006

"That must weigh heavily on your soul. Let me purge it for you."
What information can I get about devices through C#? I have come across an interesting problem here; part of my app runs a defrag, but I don't want that to happen on SSDs, since that will shorten it's working lifespan, so I would like to be able to specify a drive by letter and establish if it is an SSD or not. I know all our SSDs are Intel, so perhaps they have serial numbers or something starting with "INTEL-" or something that I could use?

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

Sab669 posted:

Well, the thing with ID - 1 is that ID is actually the ID of the meal they edited, so that can range from 1 through 40 based off whatever meal they selected from that first drop down box. But I get what you're saying.

I could just parse out menuType to any variable, subtract one, and then do SelectedIndex = that.

Thing is though, I know I tried setting SelectedIndex = menuType, and it threw some error. I don't recall what, exactly though. And I'm honestly not sure if I can work on it now (I'm out of class finally) and my laptop was having some problems connecting to the DB last I knew.
You should have a meal type id and a meal id, otherwise you can't tell what kind of meal it is without hardcoding it in. The meal type id will tell you if it is an entree or whatever and the meal id is the unique id you identify the meal as.

Sab669
Sep 24, 2009

Sweeper posted:

You should have a meal type id and a meal id, otherwise you can't tell what kind of meal it is without hardcoding it in. The meal type id will tell you if it is an entree or whatever and the meal id is the unique id you identify the meal as.

In the menu table, menuType is just an int from 1-4, which is a foriegn key for the actual Types table, which is typesID (this being the other key), and then actual typesName field.

Thanks for the help guys. I'll try it out when I get a chance. I guess one last big question; how bad IS my code?

csammis
Aug 26, 2003

Mental Institution

BizarroAzrael posted:

What information can I get about devices through C#? I have come across an interesting problem here; part of my app runs a defrag, but I don't want that to happen on SSDs, since that will shorten it's working lifespan, so I would like to be able to specify a drive by letter and establish if it is an SSD or not. I know all our SSDs are Intel, so perhaps they have serial numbers or something starting with "INTEL-" or something that I could use?

Look into WMI, it's an interface that will allow you to query hardware information.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Having an issue in WPF. My application has two windows. One is for controlling a set of data and the other is for hosting a control to display the data. The problem is if the display form that contains the control isn't the Applications StartupUri, then the control doesn't render.

I can place basic WPF controls (ex: textblock) on the form and they will appear just fine. Is there some kind of initialization I'm failing to run on the form that is implicitly run when the form is set as the application StartupUri?

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
I'm hoping someone with CAS experience can help me out a bit. I've been trying to set up dotnetpad on a new VPS and it's been real painful.
Right now I've got F# compiling correctly (I think) but the resulting assemblies aren't running properly. I'm getting System.Security.SecurityException: That assembly does not allow partially trusted callers. When I run the exact same paste on my home machine or on the first VPS it runs fine.
I'm super confused and I've never seen this issue before. I don't understand how the exact same code can have different security rules. Both are calling on the same assemblies.
Anybody have any good ideas? :sigh:

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

Free Bees posted:

I'm hoping someone with CAS experience can help me out a bit. I've been trying to set up dotnetpad on a new VPS and it's been real painful.
Right now I've got F# compiling correctly (I think) but the resulting assemblies aren't running properly. I'm getting System.Security.SecurityException: That assembly does not allow partially trusted callers. When I run the exact same paste on my home machine or on the first VPS it runs fine.
I'm super confused and I've never seen this issue before. I don't understand how the exact same code can have different security rules. Both are calling on the same assemblies.
Anybody have any good ideas? :sigh:

What kind of server do you have at home? The IIS built into windows xp/vista/7? because that is not the same as the one on a windows server.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
Home is a Win7 machine, the new VPS is Server 2008 and the old VPS is Server 2003.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
I'm trying to integrate a native DLL for some performance-sensitive code into my C# app, and on my development machine everything works. However, when I copy a build to another machine for testing, calling the native code throws an exception:

System.IO.FileNotFoundException: Could not load file or assembly 'Native.dll' or one of its dependencies. The specified module could not be found.

However, in both cases, Native.dll is in the same directory as everything else. The only difference is that Visual Studio isn't on the remote box.

I've tried adding the dll to the GAC by dragging it into %windir%\assemblies, but it didn't seem to accept it. The assembly is strong-named, so that should work too?

My next step is probably to create a clean image and see if it has the same issue, but that'll take an hour or so to bake...

BizarroAzrael
Apr 6, 2006

"That must weigh heavily on your soul. Let me purge it for you."
I need my C# program to wait for a process that it did not start to finish before it proceeds, is this the best way to do it:

code:
while (Process.GetProcessesByName("process").Length != 0)
            {
                System.Threading.Thread.Sleep(60000);
            }
I've been having trouble testing overnight. Seems okay when I manually kill the process in question but when I test it under the real world situation it doesn't seem to work, and loops forever.

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

Free Bees posted:

Home is a Win7 machine, the new VPS is Server 2008 and the old VPS is Server 2003.

Yea i doubt you will be able to run it on anything other then a Windows Server version of IIS.

Mongolian Queef
May 6, 2004

Ryouga Inverse posted:

I'm trying to integrate a native DLL for some performance-sensitive code into my C# app, and on my development machine everything works. However, when I copy a build to another machine for testing, calling the native code throws an exception:

System.IO.FileNotFoundException: Could not load file or assembly 'Native.dll' or one of its dependencies. The specified module could not be found.

However, in both cases, Native.dll is in the same directory as everything else. The only difference is that Visual Studio isn't on the remote box.

I've tried adding the dll to the GAC by dragging it into %windir%\assemblies, but it didn't seem to accept it. The assembly is strong-named, so that should work too?

My next step is probably to create a clean image and see if it has the same issue, but that'll take an hour or so to bake...

I have a hunch it's because of this: http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en

This is one of those rare (I never ever have to use it otherwise) opportunities where the event log will help you out. Right click My Computer, select Manage then look under System Tools -> Event Viewer. The Application log will probably tell you why it failed.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Or you're referencing debug libraries that come with VS, but aren't on the other machine.

Adbot
ADBOT LOVES YOU

Mongolian Queef
May 6, 2004

dwazegek posted:

Or you're referencing debug libraries that come with VS, but aren't on the other machine.

Yes. This is quite handy: http://www.dependencywalker.com/

  • Locked thread